单机环境:Ubuntu 20.04 安装 kind
Kind 是 Kubernetes In Docker 的缩写,顾名思义是使用 Docker 容器作为 Node 并将 Kubernetes 部署至其中的一个工具。官方文档中也把 Kind 作为一种本地集群搭建的工具进行推荐。
- 安装kubectl,这个不介绍了,之前的文件写的很详细了,不知道的可以查看之前的文章或者自行的百度
2.安装kind
export GO111MODULE=”on”
go get sigs.k8s.io/kind@v0.8.1
kind create cluster
kind create cluster --image kindest/node:v1.19.1
kind create cluster --config mykind.yaml --name mykind
kind get clusters
kubectl config get-contexts
kubectl config set-context kind-clusterName
kubectl get nodes
kind get kubeconfig --name="mykind"
删除集群
kind delete cluster --name mykind
kind delete clusters --all
kubectl get nodes
NAME STATUS ROLES AGE VERSION
mykind-control-plane Ready master 3m11s v1.19.1
mykind-worker Ready <none> 2m39s v1.19.1
mykind-worker2 Ready <none> 2m39s v1.19.1
build:用来从 Kubernetes 源代码构建一个新的镜像。
create:创建一个 Kubernetes 集群。
delete:删除一个 Kubernetes 集群。
get:可用来查看当前集群、节点信息以及 Kubectl 配置文件的地址。
load:从宿主机向 Kubernetes 节点内导入镜像。
- 多节点配置
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30100
hostPort: 30100
listenAddress: "0.0.0.0"
- containerPort: 30101
hostPort: 30101
listenAddress: "0.0.0.0"
- containerPort: 30102
hostPort: 30102
listenAddress: "0.0.0.0"
- containerPort: 30103
hostPort: 30103
listenAddress: "0.0.0.0"
- containerPort: 30104
hostPort: 30104
listenAddress: "0.0.0.0"
- containerPort: 30105
hostPort: 30105
listenAddress: "0.0.0.0"
- containerPort: 30106
hostPort: 30106
listenAddress: "0.0.0.0"
- containerPort: 31107
hostPort: 31107
listenAddress: "0.0.0.0"
- containerPort: 30108
hostPort: 30108
listenAddress: "0.0.0.0"
- containerPort: 30109
hostPort: 30109
listenAddress: "0.0.0.0"
- role: worker
extraPortMappings:
- containerPort: 30100
hostPort: 30200
listenAddress: "0.0.0.0"
- containerPort: 30101
hostPort: 30201
listenAddress: "0.0.0.0"
- containerPort: 30102
hostPort: 30202
listenAddress: "0.0.0.0"
- containerPort: 30103
hostPort: 30203
listenAddress: "0.0.0.0"
- containerPort: 30104
hostPort: 30204
listenAddress: "0.0.0.0"
- containerPort: 30105
hostPort: 30205
listenAddress: "0.0.0.0"
- containerPort: 30106
hostPort: 30206
listenAddress: "0.0.0.0"
- containerPort: 30107
hostPort: 30207
listenAddress: "0.0.0.0"
- containerPort: 30108
hostPort: 30208
listenAddress: "0.0.0.0"
- containerPort: 30109
hostPort: 30209
listenAddress: "0.0.0.0"
- role: worker
extraPortMappings:
- containerPort: 30100
hostPort: 30300
listenAddress: "0.0.0.0"
- containerPort: 30101
hostPort: 30301
listenAddress: "0.0.0.0"
- containerPort: 30102
hostPort: 30302
listenAddress: "0.0.0.0"
- containerPort: 30103
hostPort: 30303
listenAddress: "0.0.0.0"
- containerPort: 30104
hostPort: 30304
listenAddress: "0.0.0.0"
- containerPort: 30105
hostPort: 30305
listenAddress: "0.0.0.0"
- containerPort: 30106
hostPort: 30306
listenAddress: "0.0.0.0"
- containerPort: 30107
hostPort: 30307
listenAddress: "0.0.0.0"
- containerPort: 30108
hostPort: 30308
listenAddress: "0.0.0.0"
- containerPort: 30109
hostPort: 30309
listenAddress: "0.0.0.0"
- 查看集群 node
kubectl get nodes
NAME STATUS ROLES AGE VERSION
mykind-control-plane Ready master 3m11s v1.19.1
mykind-worker Ready <none> 2m39s v1.19.1
mykind-worker2 Ready <none> 2m39s v1.19.1
- 集群部署完成