kind (k8s in docker)
在容器里运行Kubernetes
安装kind
- 使用包管理器安装
brew install kind
kind
k8s in docker
brew install kind
kind create cluster
kind delete cluster
kind get clusters
控制平面节点 Control planel
- 创建
-
- 如果不指定名称,默认为kind
kind create cluster --name dev
- 查看全部集群
kind get clusters
- 为了与特定集互,您只需指定 cluster name 作为上下文中的 Context:
kubectl cluster-info --context kind-dev
kubectl cluster-info --context kind-kind
- 删除
-
- 如果不指定名称, 默认删除kind
kind delete cluster --name dev
使用配置文件定义集群
- 运行命令
kind create cluster --config kind-example-config.yaml
- kind-example-config.yaml
# a cluster with 1 control-plane nodes and 2 workers
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- 高可以集群
# a cluster with 3 control-plane nodes and 3 workers
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
加载镜像到集群节点
在mac上要关闭docker desktop 的 Use containerd for pulling and storing images ,这个是构建多平台镜像时要打开的
- 加载 nginx:1.29.0 镜像到 kind 中
- docker pull nginx:1.29.0
kubectl config use-context kind-kind
kind load docker-image nginx:1.29.0 --name kind
部署镜像
- 编写 Deployment
nginx-deployment.yml
- 应用
kubectl apply -f nginx-deployment.yml
- 查看部署结果
kubectl get pods