Kind 是 Kubernetes In Docker 的缩写,顾名思义是使用 Docker 容器作为 Node 并将 Kubernetes 部署至其中的一个工具。官方文档中也把 Kind 作为一种本地集群搭建的工具进行推荐。
kind的官网:https://kind.sigs.k8s.io/
使用kind必须具备以下条件
GOPROXY=goproxy.cn go install sigs.k8s.io/kind@v0.12.0
sudo cp $(go env GOPATH)/bin/kind /usr/local/bin
kind create cluster --name=kind
使用 kind create cluster 安装,是没有指定任何配置文件的安装方式。从安装打印出的输出来看,分为4步:
kubectl中文文档:http://kubernetes.kansea.com/docs/user-guide/kubectl/kubectl_config_set-context/
kubectl config get-contexts #查看可用集群
kubectl cluster-info --context clusterName #查看集群信息
# 查看完集群列表后,根据需要切换上下文
kubectl config set-context clusterName
# 查看完集群列表后,根据需要切换上下文
kubectl config delete-context clusterName
# 查看完集群列表后,根据需要切换上下文
kubectl config use-context clusterName
kubectl get nodes
kind create cluster
kind create cluster --image kindest/node:latest
kind create cluster --name kind2
kind get clusters
kind get nodes
kind delete cluster
kind delete cluster --name clusterName
kind delete clusters --all
Docker映像可以通过以下方式加载到群集节点中
docker pull nginx
kind load docker-image nginx
如果使用命名群集,则需要指定要将映像加载到的群集的名称
kind load docker-image nginx --name kind-2
kind load image-archive /my-image-archive.tar
docker build -t my-custom-image:unique-tag ./my-image-dir
kind load docker-image my-custom-image:unique-tag
kubectl apply -f my-manifest-using-my-image:unique-tag
由于 Node 是 docker 容器,则可以使用 docker ps 命令查看当前运行的容器:
docker exec -it kind-control-plane bash
可以使用 crictl 命令操作 kind 结点中的镜像: