brief introduction
Kind (Kubernetes in Docker) is a Kubernetes incubation project. Kind is a set of out of the box Kubernetes environment construction scheme. As the name suggests, it is convenient to build Kubernetes clusters by deploying all components required by Kubernetes in a Docker container.
Kind has been widely used in the CI environment of Kubernetes upstream and related projects. The official documents also recommend kind as a tool for local cluster construction.
What can Kind do?
- Quickly create one or more Kubernetes clusters
- Support the deployment of highly available Kubernetes clusters
- Support to build and deploy a Kubernetes cluster from the source code
- You can experience the latest Kubernetes cluster quickly and at low cost, and support most of the functions of Kubernetes
- Support local offline operation of a multi node cluster
What are the advantages of Kind?
- Minimal installation dependency. You only need to install Docker
- It is easy to use. You can quickly create a cluster by using the Kind Cli tool
- Use containers to model Kubernetes nodes
- Internal use of kubedm's official mainstream deployment tools
- Passed the official K8S Conformance test of CNCF
How does Kind work?
Kind uses a container to simulate each Kubernetes node and runs system D in the container. System D in the container hosts Kubelet and container, and then Kubelet in the container runs other Kubernetes components: Kube apiserver, Etcd, CNI and so on.
Kind uses kubedm internally to deploy clusters, including high availability clusters, with the help of the features provided by kubedm. In the high use cluster, an additional Nginx will be deployed to provide load balancing VIP.
prepare
Install docker
https://docs.docker.com/engine/install/
Install kubectl
official: https://kubernetes.io/docs/tasks/tools/#install-kubectl
yum install kubectl
Install Kind
Kind uses Golang for development and supports good cross platform features. It usually only needs to download the built binary files directly.
Linux
$ curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.11.0/kind-linux-amd64 $ chmod +x ./kind $ mv ./kind /usr/local/bin/kind
Windows
$ curl.exe -Lo kind-windows-amd64.exe https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-windows-amd64 $ mv .\kind-windows-amd64.exe c:\kind.exe
For more platform installation methods, please refer to Official documents
Source code
If the development environment of Golang (1.11 +) has been configured in the local environment, you can also install it directly through the source code.
$ go get sigs.k8s.io/kind@v0.5.1
kind command
$ kind kind creates and manages local Kubernetes clusters using Docker container 'nodes' Usage: kind [command] Available Commands: build Build one of [base-image, node-image] create Creates one of [cluster] delete Deletes one of [cluster] export exports one of [logs] get Gets one of [clusters, nodes, kubeconfig-path] help Help about any command load Loads images into nodes version prints the kind CLI version Flags: -h, --help help for kind --loglevel string logrus log level [panic, fatal, error, warning, info, debug] (default "warning") --version version for kind Use "kind [command] --help" for more information about a command.
Briefly describe the meaning of the following common options:
- Build: used to build a new image from Kubernetes source code.
- Create: create a Kubernetes cluster.
- Delete: delete a Kubernetes cluster.
- get: it can be used to view the current cluster, node information and the address of Kubectl configuration file.
- load: import the image from the host to the Kubernetes node.
Build a single node cluster
$ kind create cluster --name my-cluster Creating cluster "my-cluster" ... â Ensuring node image (kindest/node:v1.21.1) đŧ â Preparing nodes đĻ â Creating kubeadm config đ â Starting control-plane đšī¸ Cluster creation complete. You can now use the cluster with: export KUBECONFIG="$(kind get kubeconfig-path --name="my-cluster")" kubectl cluster-info
– name is an optional parameter. If not specified, the default cluster name is kind.
When using the default installation method, we did not specify any configuration files. From the output of the installation process, it is divided into four steps:
- Check whether there is a basic installation image in the local environment. The default is kindest / node: 1.21 1. The image contains all the things that need to be installed, including kubectl, kubeadm and kubelet
And the image required to install the corresponding version of Kubernetes. - Preparing the Kubernetes node is mainly to start the container and decompress the image.
- Establish the corresponding kubedm configuration, and then install it through kubedm. After the installation is completed, some cleaning operations will be performed, such as deleting the stains on the primary node, otherwise the deployment cannot be completed for a Pod that is not tolerated.
- After all the above operations are completed, a Kubernetes cluster is successfully started and some prompt messages for cluster operation are output.
By default, Kind will download kindest / node: v1.0 first 21.1 mirroring. If you want to specify different versions, you can use the -- image parameter, like this: Kind create Cluster -- Image kindest / node: v1 twenty-one point one
The kindest/node image is currently hosted on the Docker Hub and may be slow to download. The same problem also exists when kind creates clusters. Kind actually uses kubedm to create clusters. Students who know something about kubedm know that the image used by default is inaccessible in China, so they also need to solve the network problem by themselves.
If you have the above network problems, you'd better configure a domestic accelerator or image source. If you don't know how to configure the accelerator and image source, you can refer to: Docker / Kubernetes image source is unavailable. I'll teach you some tricks to fix it! "And" Using DaoCloud / alicloud image acceleration under Docker "Two articles.
Next, we will operate according to the prompt information output after the above command is executed to verify whether the cluster is successfully deployed.
# Gets the path where the configuration file of the specified cluster is located $ export KUBECONFIG="$(kind get kubeconfig-path --name="my-cluster")" $ kubectl cluster-info Kubernetes master is running at https://localhost:34458 KubeDNS is running at https://localhost:34458/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. $ kubectl get nodes NAME STATUS ROLES AGE VERSION my-cluster-control-plane Ready master 2m v1.15.3 $ kubectl get po -n kube-system NAME READY STATUS RESTARTS AGE coredns-86c58d9df4-6g66f 1/1 Running 0 21m coredns-86c58d9df4-pqcc4 1/1 Running 0 21m etcd-my-cluster-control-plane 1/1 Running 0 20m kube-apiserver-my-cluster-control-plane 1/1 Running 0 20m kube-controller-manager-my-cluster-control-plane 1/1 Running 0 20m kube-proxy-cjgnt 1/1 Running 0 21m kube-scheduler-my-cluster-control-plane 1/1 Running 0 21m weave-net-ls2v8 2/2 Running 1 21m
From the above output results, we can see that the Kubernetes of a single node has been built successfully. The default node type of a single node cluster is control plane, which contains all components. These components are: 2*Coredns, Etcd, API server, controller manager, Kube proxy, Sheduler and network plug-in Weave. At present, the default network plug-in is also Weave.