export REGISTRY_MIRROR=https://registry.cn-hangzhou.aliyuncs.com
curl -sSL https://kuboard.cn/install-script/v1.20.x/install_kubelet.sh | sh -s 1.20.0
export MASTER_IP=192.168.163.101
export APISERVER_NAME=menqi1
export POD_SUBNET=10.100.0.1/16
echo "${MASTER_IP} ${APISERVER_NAME}" >> /etc/hosts
curl -sSL https://kuboard.cn/install-script/v1.20.x/init_master.sh | sh -s 1.20.0
/coredns
kubectl get nodes -o wide
在 master 节点上执行:
kubeadm token create --print-join-command
得到如下输出:
kubeadm join menqi1:6443 --token v2sdp2.iseaa9a7zxlg2sre --discovery-token-ca-cert-hash sha256:a76ceb168f32c3281a38552c25e4d0c77a94b75d7237b7f60852fc6606d0c610
针对所有的 worker 节点执行:
export MASTER_IP=192.168.163.102
export APISERVER_NAME=menqi2
echo "${MASTER_IP} ${APISERVER_NAME}" >> /etc/hosts
kubeadm join menqi1:6443 --token v2sdp2.iseaa9a7zxlg2sre --discovery-token-ca-cert-hash sha256:a76ceb168f32c3281a38552c25e4d0c77a94b75d7237b7f60852fc6606d0c610
在 master 节点上执行:
kubectl get nodes -o wide
[root@demo-master-a-1 ~]# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
menqi1 Ready control-plane,master 12m v1.20.0 192.168.163.101 <none> CentOS Linux 7 (Core) 3.10.0-1160.6.1.el7.x86_64 docker://17.3.1
menqi2 Ready <none> 11m v1.20.0 192.168.163.102 <none> CentOS Linux 7 (Core) 3.10.0-1160.6.1.el7.x86_64 docker://20.10.7
初始化方式同节点1
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml
kubectl get pod -n kubernetes-dashboard
kubectl get svc -n kubernetes-dashboard
暴露端口:
kubectl patch svc kubernetes-dashboard \
-n kubernetes-dashboard \
-p ‘{"spec":{"type":"NodePort","ports":[{"port":443,"targetPort":8443,"nodePort":30001}]}}‘
cat > dashboard-adminuser.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
EOF
创建登录用户
kubectl apply -f dashboard-adminuser.yaml
获取token:
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk ‘{print $1}‘)
访问:
https://192.168.163.102:30001/
这里192.168.163.102为dashboard服务所在节点ip。
https://kuboard.cn/install/history-k8s/install-k8s-1.20.x.html
原文:https://www.cnblogs.com/processing/p/14865209.html