前言
Kind(Kubernetes in Docker)用于在本地或CI环节,快速搭建1个可用的Kubernetes集群,进行本地开发/测试。
它通过在1个VM内启动多个Docker容器来运行Kubernetes节点,每1个容器相当于1个集群节点,从而组成一个完整的Kubernetes集群。
限制:
-
Kind适合本地开发、测试和CI场景,不适合生产环境或真正的分布式Kubernetes架构。
-
支持单机容器间的集群交互(跨容器通信),不支持跨不同VM或物理主机的节点通信。
一、使用kind
kind is a tool for running local Kubernetes clusters using Docker container “nodes”.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.
1.安装kubectl
curl -LO "https://dl.k8s.io/release/v1.29.3/bin/linux/amd64/kubectl" chmod +x kubectl mv kubectl /usr/local/bin/
2.配置kind
kind-cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "192.168.10.100"
apiServerPort: 6443
nodes:
- role: control-plane
image: kindest/node:v1.28.0
- role: worker
image: kindest/node:v1.28.0
- role: worker
image: kindest/node:v1.28.0
kubeadmConfigPatches:
- |
apiServer:
certSANs:
- "192.168.10.100"
3.安装kind
root@master01:/home/zhanggen# curl -Lo kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 97 100 97 0 0 196 0 --:--:-- --:--:-- --:--:-- 197 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 6381k 100 6381k 0 0 2864k 0 0:00:02 0:00:02 --:--:-- 7227k root@master01:/home/zhanggen# chmod +x kind root@master01:/home/zhanggen# mv kind /usr/local/bin/ root@master01:/home/zhanggen# kind version kind v0.23.0 go1.21.10 linux/amd64
4.启动kind
root@master01:/home/zhanggen# kind create cluster --name zhanggen-dev --config kind-cluster.yaml Creating cluster "zhanggen-dev" ... ✓ Ensuring node image (kindest/node:v1.28.1) 🖼 ✓ Preparing nodes 📦 📦 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 ✓ Joining worker nodes 🚜 Set kubectl context to "kind-zhanggen-dev" You can now use your cluster with: kubectl cluster-info --context kind-zhanggen-dev Thanks for using kind! 😊
5.验证kind
服务端查看容器
root@master01:/home/zhanggen# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2448a98e3f6 kindest/node:v1.28.0 "/usr/local/bin/entr…" 5 hours ago Up 5 hours zhanggen-dev-worker 781ac4527f88 kindest/node:v1.28.0 "/usr/local/bin/entr…" 5 hours ago Up 5 hours 192.168.10.100:6443->6443/tcp zhanggen-dev-control-plane 9bc376e142ca kindest/node:v1.28.0 "/usr/local/bin/entr…" 5 hours ago Up 5 hours zhanggen-dev-worker2 root@master01:/home/zhanggen# kubectl get nodes NAME STATUS ROLES AGE VERSION zhanggen-dev-control-plane Ready control-plane 4h53m v1.28.0 zhanggen-dev-worker Ready <none> 4h53m v1.28.0 zhanggen-dev-worker2 Ready <none> 4h53m v1.28.0
Windows客户端测试到服务端6443端口连通性
Test-NetConnection -ComputerName 192.168.10.100 -Port 6443
6.删除kind
root@master01:/home/zhanggen# kind delete cluster --name zhanggen-dev root@master01:/home/zhanggen# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
浙公网安备 33010602011771号