kind 搭建 k8s

kubectl 安装

由于 API 版本兼容的问题,尽量保持 kubectl 版本与 K8S 集群版本保持一致,或版本相差在在一个小版本内

https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl

1
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl

或者在 k8s github 地址 changelog 中下载

1
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.14.md

kind 安装

kind 官方下载地址:
https://github.com/kubernetes-sigs/kind/releases

或者使用 go get 安装:

1
go get sigs.k8s.io/kind

启动示例:

1
2
kind create cluster --image kindest/node:v1.13.4 --config kind-config.yaml --name kind
kind create cluster --image kindest/node:v1.13.4 --config kind-ha-config.yaml --name kind // 搭建高可用集群

修改环境变量:

1
2
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
kubectl cluster-info

kind-config.yaml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
metadata:
name: config
networking:
serviceSubnet: 10.0.0.0/16
imageRepository: registry.aliyuncs.com/google_containers
- |
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
metadata:
name: config
networking:
serviceSubnet: 10.0.0.0/16
imageRepository: registry.aliyuncs.com/google_containers
nodeRegistration:
kubeletExtraArgs:
pod-infra-container-image: registry.aliyuncs.com/google_containers/pause:3.1
nodes:
- role: control-plane

kind-ha-config.yaml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
metadata:
name: config
networking:
serviceSubnet: 10.0.0.0/16
imageRepository: registry.aliyuncs.com/google_containers
- |
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
metadata:
name: config
networking:
serviceSubnet: 10.0.0.0/16
imageRepository: registry.aliyuncs.com/google_containers
nodeRegistration:
kubeletExtraArgs:
pod-infra-container-image: registry.aliyuncs.com/google_containers/pause:3.1

nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker

参考资料:

kind 文档:

https://kind.sigs.k8s.io/