I was reviewing Golang recently and wrote a web application. After running it locally, I wanted to test it in a k8s cluster. Due to the machine configuration, it was still a bit difficult to build a complete k8s cluster. I remember that a friend said that k8s can also be run in docker, so I tried it.
Today’s protagonist is kind, so what is kind? What can kind be used for?
1. Introduction to kind
kind is the abbreviation of Kubernetes In Docker, a tool that uses docker container nodes to run local kubernetes clusters. Kind is mainly used to test kubernetes itself,
suitable for local development or CI.
Kind currently supports almost all official versions of kubernetes. For runtime, it currently only supports docker. In the future, it will gradually support the commonly used runtime in CRI.
I believe that in the future, it will slowly support conterned.
In fact, the process of kind managing clusters is using open source components such as kubeadm and kustomize to work.
Without further ado, let’s quickly install and use kind.
2. Kind installation
Since my system is Mac OSX, I will use brew to install it directly:
# brew install kind==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/kind-0.17.0.arm64_monterey.bottle.tar.gz
Already downloaded: /Users/wanzi/Library/Caches/Homebrew/downloads/bcd419997297730492f5cebc36be86fb51f21061a6ddb2e066e1e4d8ad33ddf3--kind-0.17.0.arm64_monterey.bottle.tar.gz
==> Pouring kind-0.17.0.arm64_monterey.bottle.tar.gz
==> Caveats
zsh completions have been installed to: /opt/homebrew/share/zsh/site-functions ==> Summary 🍺 /opt/homebrew/Cellar/kind/0.17.0: 8 files, 8.7MB ==> Running `brew cleanup kind`... Disable this behavior by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)# kind version kind v0.17.0 go1.19.2 darwin/arm64 ``` For linux installation: ```Shell curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind
Of course, if you are using Windows, you can also use Chocolatey to install; or use the binary method, which is officially supported.
3. Create the first cluster
Before the operation, docker and kubectl are what we need to prepare in advance, and I will ignore the specific installation here.
For the kind help command, we know that kind supports operations such as build, create, delete, get, and load.
For subcommands, you can use -h to get more information.
kind creates a cluster.
Before creating a cluster, we need to ensure that the ~/.kube directory exists, because during the creation process, kind will write information such as the cluster API address and certificate into kubeconfig.
# kind create cluster --name ci-clusterCreating cluster "ci-cluster" ...
✓ Ensuring node image (kindest/node :v1.25.3) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-ci-cluster"You can now use your cluster with:
```### 2. Switch cluster:```Shell
# kubectl cluster-info --context kind-ci-clusterKubernetes control plane is running at https://127.0.0.1:56527
CoreDNS is running at https://127.0.0.1:56527/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Have a nice day ! 👋
kind:ClusterapiVersion:kind.x-k8s.io/v1alpha4nodes:#Add multi-node cluster and customize the node cluster version- role:control-planeimages:kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315kubeadmConfigPatches:- |kind:InitConfigurationnodeRegistration:kubeletExtraArgs: node-labels:"ingress-ready=true"extraPortMappings: - containerPort: 80 hostPort: 80 protocol: TCP - containerPort: 443 hostPort: 443 protocol: TCP - role: worker images: kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978 dd2f745aac5eb1fe65c0807eb315 labels: app: front extraMounts: - hostPath: /Users/wanzi/tools/kind/wwwroot containerPath: /wwwroot - role: worker images:kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315labels:app:backendextraMounts:- hostPath:/Users/wanzi/tools/kind/wwwrootcontainerPath:/wwwrootnetworking:#Custom configuration APIServer and networkapiServerAddress:"127.0.0.1"apiServerPort:6443podSubnet:"10.244.0.0/16"serviceSubnet:"10.96.0.0/12"#disableDefaultCNI: true #The default CNI plugin is kindnetd, and you can also disable other plugins such as calicokubeProxyMode:"ipvs"#Set kubeproxy mode to lvs, if you want to disable, you can set it to none
So far, using kind to quickly build a cluster has come to an end. You can use it to run tests and verify functions normally.