|
| 1 | +<h1 align=center>Kubernetes Tutorials | k8s 教程</h1> |
| 2 | + |
| 3 | +[](https://github.com/guangzhengli/k8s-tutorials/network)[](https://github.com/guangzhengli/k8s-tutorials/stargazers)[](https://github.com/guangzhengli/k8s-tutorials/issues)[](https://github.com/guangzhengli/k8s-tutorials/blob/main/LICENSE) |
| 4 | + |
| 5 | +<h4 align=center>🌈 Kubernetes | 📰 Tutorials</h4> |
| 6 | + |
| 7 | +K8s as a cloud-native operating system, the need to learn it speaks for itself, if you encounter any problems, you can comment in [Discussions]((https://github.com/guangzhengli/k8s-tutorials/discussions)) or Issue, if you think this repository is valuable to you, welcome to star or raise PR / Issue to make it better! |
| 8 | + |
| 9 | +Before learning this tutorial, you need to note that this tutorial focuses on practical guidance to modify the code in an incremental way, starting from the most basic container definition, through `pod`, `deployment`, `service`, `ingress`, `configmap`, `secret` and other resources until the `helm` to packaged deployment of a complete set of services. So if you don't know much about the basics of containers and k8s, it is recommended to get the basic theoretical knowledge from the [official documentation]((https://kubernetes.io/docs/home/)) or other tutorials first, and then deepen your mastery of the knowledge through real-life practice! |
| 10 | + |
| 11 | +Here is the index of this document: |
| 12 | +* [Preparation](docs/pre.md) |
| 13 | +* [container](docs/container.md) |
| 14 | +* [pod](docs/pod.md) |
| 15 | +* [deployment](docs/deployment.md) |
| 16 | +* [service](docs/service.md) |
| 17 | +* [ingress](docs/ingress.md) |
| 18 | +* [namespace](docs/namespace.md) |
| 19 | +* [configmap](docs/configmap.md) |
| 20 | +* [secret](docs/secret.md) |
| 21 | +* [job/cronjob](docs/job.md) |
| 22 | +* [helm](docs/helm.md) |
| 23 | +* [dashboard](docs/dashboard.md) |
| 24 | +* Translate English(unfinished) |
| 25 | + |
| 26 | +# kubernetes tutorials |
| 27 | + |
| 28 | +## Preparation |
| 29 | + |
| 30 | +Before starting this tutorial, you need to configure your local environment. Here are the dependencies and packages that need to be installed. |
| 31 | + |
| 32 | +### Install docker |
| 33 | + |
| 34 | +First we need to install `docker` to package the image, if you already have `docker` installed locally, then you can choose to skip this section. |
| 35 | + |
| 36 | +#### Recommended installation method |
| 37 | + |
| 38 | +The easiest way to install docker is to use [Docker Desktop](https://www.docker.com/products/docker-desktop/) currently, just open the official website and download the package that corresponds to your computer's operating system (https://www.docker.com/products/docker-desktop/) |
| 39 | + |
| 40 | +When the installation is complete, you can quickly verify that the installation was successful by using `docker run hello-world`! |
| 41 | + |
| 42 | +#### Other installation methods |
| 43 | + |
| 44 | +Currently, Docker has announced that [Docker Desktop](https://www.docker.com/products/docker-desktop/) is only free for individual developers or small groups (no longer free for large companies from 2021), so if you can't install `docker` via [Docker Desktop](https://www.docker.com/products/docker-desktop/), you can refer to [this article](https://dhwaneetbhatt.com/blog/run-docker-) to download and install `docker`. without-docker-desktop-on-macos) to install only the [Docker CLI](https://github.com/docker/cli). |
| 45 | + |
| 46 | +### Install minikube |
| 47 | + |
| 48 | +We also need to build a local cluster of k8s (either using a cloud vendor or another k8s cluster). The recommended way to build a local k8s cluster is to use [minikube](https://minikube.sigs.k8s.io/docs/). |
| 49 | + |
| 50 | +You can download and install according to [minikube quick install](https://minikube.sigs.k8s.io/docs/start/), here is a brief list of MacOS installation, Linux & Windows OS can refer to [official documentation](https://minikube.sigs.k8s.io/docs/start/) for a quick installation. |
| 51 | + |
| 52 | +```shell |
| 53 | +brew install minikube |
| 54 | +``` |
| 55 | + |
| 56 | +#### Start minikube |
| 57 | + |
| 58 | +Because minikube supports many containers and virtualization technologies ([Docker](https://minikube.sigs.k8s.io/docs/drivers/docker/), [Hyperkit](https://minikube.sigs.k8s.io/docs/drivers/hyperkit/), [Hyper-V](https://minikube.sigs.k8s.io/docs/drivers/hyperv/), [KVM](https://minikube.sigs.k8s.io/docs/drivers/kvm2/), [Parallels](https://minikube.sigs.k8s.io/docs/drivers/parallels/), [Podman](https://minikube.sigs.k8s.io/docs/drivers/podman/), [VirtualBox](https://minikube.sigs.k8s.io/docs/drivers/virtualbox/), or [VMware Fusion/Workstation](https://minikube.sigs.k8s.io/docs/drivers/vmware/)), is also the place where the problem appears more often, so it is better to explain it here a little. |
| 59 | + |
| 60 | +If you are using the `docker` solution recommended above [Docker Desktop](https://www.docker.com/products/docker-desktop/), then you can start minikube with the following command and wait patiently for the dependencies to download. |
| 61 | + |
| 62 | +```shell |
| 63 | +minikube start --vm-driver docker --container-runtime=docker |
| 64 | +``` |
| 65 | + |
| 66 | +When you're done, run `minikube status` to check the current status to make sure it started successfully! |
| 67 | + |
| 68 | +If you only have the Docker CLI locally, and the criterion is that if you execute a command like `docker ps` and it returns the error `Cannot connect to the Docker daemon at unix:///Users/xxxx/.colima/docker.sock. daemon running?` Then you need to run the following command. |
| 69 | + |
| 70 | +```shell |
| 71 | +brew install hyperkit |
| 72 | +minikube start --vm-driver hyperkit --container-runtime=docker |
| 73 | + |
| 74 | +# Tell Docker CLI to talk to minikube's VM |
| 75 | +eval $(minikube docker-env) |
| 76 | + |
| 77 | +# Save IP to a hostname |
| 78 | +echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null |
| 79 | + |
| 80 | +# Test |
| 81 | +docker run hello-world |
| 82 | +``` |
| 83 | + |
| 84 | +**minikube command quick search** |
| 85 | + |
| 86 | +`minikube stop` Does not delete any data, just stops the VM and k8s cluster. |
| 87 | + |
| 88 | +`minikube delete` Delete all minikube data after startup. |
| 89 | + |
| 90 | +`minikube ip` View the IP address where the cluster and docker engine are running. |
| 91 | + |
| 92 | +`minikube pause` Suspend current resources and k8s clusters |
| 93 | + |
| 94 | +`minikube status` View current cluster status |
| 95 | + |
| 96 | +### Install kubectl |
| 97 | + |
| 98 | +This step is optional, if not installed, all subsequent `kubectl` related commands will be replaced by the `minikube kubectl` command. |
| 99 | + |
| 100 | +If you don't want to use `minikube kubectl` or configure the relevant environment variables for the following tutorial, you can consider installing `kubectl` directly. |
| 101 | + |
| 102 | +```shell |
| 103 | +brew install kubectl |
| 104 | +``` |
| 105 | + |
| 106 | +### Register a docker hub account to log in |
| 107 | + |
| 108 | +Since the default image address used by minikube is DockerHub, we also need to register an account in DockerHub (https://hub.docker.com/) and log in to the account using the login command. |
| 109 | + |
| 110 | +```shell |
| 111 | +docker login |
| 112 | +``` |
0 commit comments