参考资料
安装
1
2
3
|
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.9.0/kind-$(uname)-amd64"
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind
|
启动集群
注意启动集群前 请确认 docker 服务是否启动
1
2
3
4
5
6
7
8
9
10
11
12
|
docker info|grep -A 2 Server # 确认 是否启动
Server:
Containers: 1
Running: 1
--
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: extfs
kind create cluster # 启动
|
配置 kubectl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
mkdir -p ~/.kube
kind get kubeconfig >> ~/.kube/kind-config-kind
kubectl cluster-info --context kind-kind # 切换集群
~ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-f9fd979d6-w6mhs 1/1 Running 0 14m
kube-system coredns-f9fd979d6-xrlp8 1/1 Running 0 14m
kube-system etcd-kind-control-plane 1/1 Running 0 14m
kube-system kindnet-l66x7 1/1 Running 0 14m
kube-system kube-apiserver-kind-control-plane 1/1 Running 0 14m
kube-system kube-controller-manager-kind-control-plane 1/1 Running 0 14m
kube-system kube-proxy-r6qk9 1/1 Running 0 14m
kube-system kube-scheduler-kind-control-plane 1/1 Running 0 14m
local-path-storage local-path-provisioner-78776bfc44-hfpvq 1/1 Running 0 14m
|
添加别名方便后期使用
1
|
echo "alias local-k8s=\"kubectl cluster-info --context kind-kind\"" >> ~/.zshrc # 配置完成后重启一下终端 (linux 系统为 "~/.bashrc")
|
集群管理
删除集群
部署原生 k8s dashboard
1
2
3
4
5
6
7
|
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
kubectl get pod -n kubernetes-dashboard # 检查 pod 是否启动完成
kubectl proxy # 启动代理
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ # 访问地址
|
-
生成最高权限的 admin 用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: admin
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: admin
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
|
1
|
kubectl create -f admin-role.yaml
|
获取token
1
|
kubectl -n kube-system get secret admin-token-nwphb -o jsonpath={.data.token}|base64 -d
|