Kind本地部署kubernetes环境
kind简介:
kind是一种在本地用docker启动kubernetes集群的工具,主要是用来测试kubernetes本身的,但有也用于本地开发和CI。
安装kind请参考文档 https://kind.sigs.k8s.io/docs/user/quick-start/#installation
mac上安装使用如下命令
brew install kind
通常使用配置文件来创建集群,配置文件如下所示:
cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kind-cluster # 指定集群名称
#开启指定featureGates
#featureGates:
# "CSIMigration": true
networking:
# apiserver配置 根据实际需求改,例如需要外部客户端访问,默认是127.0.0.1
# WARNING: It is _strongly_ recommended that you keep this the default
# (127.0.0.1) for security reasons. However it is possible to change this.
apiServerAddress: "192.168.10.3"
# By default the API server listens on a random open port.
# You may choose a specific port but probably don't need to in most cases.
# Using a random port makes it easier to spin up multiple clusters.
apiServerPort: 6443
# 设置pod ip段
podSubnet: "10.233.0.0/16"
# 设置service ip段
serviceSubnet: "10.96.0.0/12"
# 关闭默认的cni插件kindnetd, 使用第三方插件
# the default CNI will not be installed
disableDefaultCNI: false
# kube-proxy mode设置,默认是iptables
kubeProxyMode: "ipvs"
nodes:
- role: control-plane
image: kindest/node:v1.21.14 # 指定版本号
# 端口映射,
extraPortMappings:
- containerPort: 30950 # 容器端口号
hostPort: 10950 # 宿主机端口号
- role: worker
image: kindest/node:v1.21.14
- role: worker
image: kindest/node:v1.21.14
- role: worker
image: kindest/node:v1.21.14
创建集群
kind create cluster --config=./cluster.yaml
注意,如果kind所在机器跟kubectl机器不是同一台,需要将apiServerAddress改为kind所在机器的地址,然后使用kubecm add config文件即可。