-
Notifications
You must be signed in to change notification settings - Fork 0
使用kind构建本地k8s测试环境
EZ4BRUCE edited this page Dec 1, 2022
·
2 revisions
kind 可以让你在本机使用docker的容器作为k8s的node节点,并一件部署一个本地k8s测试环境,你可以直接在宿主机使用kubectl操控集群!
搭好之后再在本地机器安装helm和kubectl即可,本地就像mater节点一样
brew install kind
# 如果要使用多集群,就要指定 --name ,不指定就是默认名为kind
kind create cluster --config kind-config.yaml
# 如果你指定了名称,后续对集群操作如果失败,那很有可能就要带上,如果没啥特定需求不建议取名
kind delete cluster --name bruce-cluster
默认的集群只有一个节点,使用配置可以创建多个
vim kind-config.yaml
推荐配置如下
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 8123
hostPort: 8123
listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
protocol: udp # Optional, defaults to tcp
- role: worker
- role: worker
# build自定义镜像
docker build -t my-custom-image:unique-tag ./my-image-dir
# 部署到所有节点
kind load docker-image [image]:unique-tag
kubectl get all [-n namespace]
kubectl cp [-n namespace] [pod-name]:file/path [./local/path]