Kind is a project I love and have been working on, and I plan to write a series of articles about Kind. Flag++. This is the first one.

Kind introduction

Kind is short for Kubernetes In Docker. As the name implies, Kind is a tool that uses a Docker container as a Node and deploys Kubernetes to it. The official documentation also recommends Kind as a local cluster setup tool.

The installation

Binary installation

Kind uses Golang for development, and on the Release page of the repository, the built binary, which supports a variety of operating systems, has been uploaded and can be downloaded directly for use on demand.

e.g.

Download the latest version 0.2.0
wget -O /usr/localhttps://github.com/kubernetes-sigs/kind/releases/download/0.2.0/kind-linux-amd64 / bin/kind && chmod + x/usr /local/bin/kind
Copy the code

Install from source

If you already have the Golang development environment configured locally, you can install it directly from the source code.

e.g.

go get -u sigs.k8s.io/kind
Copy the code

After running the above command, you will put the kind executable in the $(go env GOPATH)/bin folder, which you may want to add to your $PATH.

Alternatively, you can clone the source code first and then build through go Build.

Rely on

  • At present, the main functions of Kind need to be supported by the Docker environment. Please refer to the official Docker documents for installation.

  • If you need to work with the cluster, you need to install the Kubectl command line. For the installation method, see the official document

Set up a single-node cluster

The following demonstrations use the latest code (that is, installed from source).

Basic usage

Setting up a single-node cluster is the most basic function of Kind.

e.g.

master $ kind create cluster --name moelove
Creating cluster "moelove". ✓ conquering nodes image (kindest/node:v1.13.4) đŸ–ŧ 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="moelove")"
kubectl cluster-info
Copy the code

In the preceding command, –name is optional. If you do not specify this parameter, the cluster name is kind by default.

We operate on the finished output of the command:

master $ export KUBECONFIG="$(kind get kubeconfig-path --name="moelove")"
master $ 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'Master $kubectl Get Nodes NAME STATUS ROLES AGE VERSION Moelove-control-plane Ready Master 2m v1.13.4Copy the code

In the preceding command, kind get kubeconfig-path –name=”moelove” returns the path of the specified cluster configuration file.

You can see that the single node Kubernetes has been set up successfully.

Pay attention to

  • By default, Kind downloads firstThe kindest/node: v1.13.4Image, which is currently hosted on Docker Hub. Download time depends on network conditions.
  • Kind practical usekubeadmCreate a cluster. YeskubeadmThose who know about it know that the image it uses by default can not be downloaded in China, so you need to solve the network problem. Or consider the following:

When creating a cluster, Kind can pass the configuration file to Kind by using the –config parameter. In China, we can use the domestic mirroring source to speed up cluster creation. (This method also applies to building Kubernetes clusters directly from Kubeadm.)

To delete the cluster, run the following command:

master $ kind delete  cluster --name moelove
Deleting cluster "moelove".$KUBECONFIG is still set to use /root/.kube/kind-config-moelove even though that file has been deleted, remember to unset it
Copy the code

Next, save the following configuration to a YAML file, such as kind-config.yaml

kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
kubeadmConfigPatches:
- |
  apiVersion: kubeadm.k8s.io/v1beta1
  kind: ClusterConfiguration
  metadata:
    name: config
  networking:
    serviceSubnet: 10.0. 0. 0/ 16
  imageRepository: registry.aliyuncs.com/google_containers
  nodeRegistration:
    kubeletExtraArgs:
      pod-infra-container-image: registry.aliyuncs.com/google_containers/pause:3.1
- |
  apiVersion: kubeadm.k8s.io/v1beta1
  kind: InitConfiguration
  metadata:
    name: config
  networking:
    serviceSubnet: 10.0. 0. 0/ 16
  imageRepository: registry.aliyuncs.com/google_containers
nodes:
- role: control-plane
Copy the code

We use this configuration file to set up the cluster.

master $ kind create cluster --name moelove --config kind.yaml
Creating cluster "moelove". ✓ conquering nodes image (kindest/node:v1.13.4) đŸ–ŧ 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="moelove")"
kubectl cluster-info
Copy the code

Above, we pass our configuration file to Kind for setting up the cluster through –config, which is recommended for domestic users.

Set up a high availability cluster

Kind also supports setting up highly available K8S clusters, but only through configuration files. You can directly save the following contents to a file and pass the configuration file to Kind.

e.g.

kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
kubeadmConfigPatches:
- |
  apiVersion: kubeadm.k8s.io/v1beta1
  kind: ClusterConfiguration
  metadata:
    name: config
  networking:
    serviceSubnet: 10.0. 0. 0/ 16
  imageRepository: registry.aliyuncs.com/google_containers
  nodeRegistration:
    kubeletExtraArgs:
      pod-infra-container-image: registry.aliyuncs.com/google_containers/pause:3.1
- |
  apiVersion: kubeadm.k8s.io/v1beta1
  kind: InitConfiguration
  metadata:
    name: config
  networking:
    serviceSubnet: 10.0. 0. 0/ 16
  imageRepository: registry.aliyuncs.com/google_containers
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
Copy the code

To set up a highly available Kubernetes cluster, use the following command:

master $ kind create cluster --name moelove-ha --config kind-ha-config.yaml
Creating cluster "moelove-ha". ✓ Ensuring node image (kindest/node:v1.13.4) đŸ–ŧ Preparing nodes đŸ“ĻđŸ“ĻđŸ“ĻđŸ“ĻđŸ“Ļ VPN VPN VPN, Starting the external load balancer ⚖ī¸ ✓ Creating kubeadm config 📜 ✓ Starting control-plane 🕹ī¸ Joining more control-plane nodes 🎮 ✓ Joining worker Nodes 🚜 Cluster creation complete. You can now use the Cluster with:export KUBECONFIG="$(kind get kubeconfig-path --name="moelove-ha")"
kubectl cluster-info
master $ export KUBECONFIG="$(kind get kubeconfig-path --name="moelove-ha")"
master $ kubectl cluster-info
Kubernetes master is running at https://localhost:44019
KubeDNS is running at https://localhost:44019/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Copy the code

A simple verification can be done:

Master $kubectl Get Nodes NAME STATUS ROLES AGE VERSION Moelove-ha-control-plane Ready Master 3m42s v1.13.4 Moelove-ha-control-plane2 Ready Master 3M24s v1.13.4 Moelove-ha-control-Plane3 Ready Master 2M13s v1.13.4 Moelove-ha-worker Ready <none> 96s v1.13.4 moelove-ha-worker2 Ready <none> 98s v1.13.4 moelove-ha-worker3 Ready <none> 95 s v1.13.4Copy the code

You can see that you have successfully created a Multi-master Kubernetes cluster.

conclusion

This is the first article on building a local Kubernetes cluster using Kind, and it complements section 4 of Kubernetes from start to practice, even better with food 🙂


You can subscribe to my official account [MoeLove] through the following TWO-DIMENSIONAL code.