主机名 master work1 work2
外网ip 39.101.185.52 39.99.250.32 39.99.250.32
内网ip 172.26.124.191 172.26.124.189 172.26.124.189
主机名 kmaster01 kwork01 kwork02
网址 default via 172.26.127.253 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
172.26.112.0/20 dev eth0 proto kernel scope link src 172.26.124.191
default via 172.26.127.253 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
172.26.112.0/20 dev eth0 proto kernel scope link src 172.26.124.189
default via 172.26.127.253 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
172.26.112.0/20 dev eth0 proto kernel scope link src 172.26.124.189

参考地址:
https://www.kuboard.cn/install/install-k8s.html#%E5%AE%89%E8%A3%85docker%E5%8F%8Akubelet

初始化master

  1. export MASTER_IP=172.26.124.191
  2. export APISERVER_NAME=apiserver.demo
  3. export POD_SUBNET=10.100.0.1/16
  4. echo "${MASTER_IP} ${APISERVER_NAME}" >> /etc/hosts
  5. curl -sSL https://kuboard.cn/install-script/v1.19.x/init_master.sh | sh -s 1.19.0

检查master是否初始化成功

# 只在 master 节点执行

# 执行如下命令,等待 3-10 分钟,直到所有的容器组处于 Running 状态
watch kubectl get pod -n kube-system -o wide

# 查看 master 节点初始化结果
kubectl get nodes -o wide

使用以下命令将其它机器添加为master节点(在其它节点上运行)

kubeadm join k8s.tgeem.cn:6443 --token prk141.9o40trf0j2ezmy78 \
    --discovery-token-ca-cert-hash sha256:3ede6e97e946508b71772048a5b0cb7d755216a84ea27685706017ff2a710689 \
    --control-plane --certificate-key 01a3a4a388b61b23bfab5acfd60e2f84e5b63d1bcefe214497af5ff843f5cd9c

使用以下命令将其它机器添加为work节点(在其它节点上运行)

kubeadm join k8s.tgeem.cn:6443 --token e3r944.dgjj9cestpxhg5ud     --discovery-token-ca-cert-hash sha256:3ede6e97e946508b71772048a5b0cb7d755216a84ea27685706017ff2a710689

初始化 worker节点

在 master 节点上执行生成加入master的参数(token时效两小时)

kubeadm token create --print-join-command
kubeadm join k8s.tgeem.cn:6443 --token e3r944.dgjj9cestpxhg5ud     --discovery-token-ca-cert-hash sha256:3ede6e97e946508b71772048a5b0cb7d755216a84ea27685706017ff2a710689

加入集群

export MASTER_IP=172.26.124.191
export APISERVER_NAME=apiserver.demo
echo "${MASTER_IP}    ${APISERVER_NAME}" >> /etc/hosts

kubeadm join k8s.tgeem.cn:6443 --token e3r944.dgjj9cestpxhg5ud     --discovery-token-ca-cert-hash sha256:3ede6e97e946508b71772048a5b0cb7d755216a84ea27685706017ff2a710689

检查初始化结果

# 只在 master 节点执行
kubectl get nodes -o wide

安装 Ingress Controller

在master节点上执行以下命令

# 只在 master 节点执行
kubectl apply -f https://kuboard.cn/install-script/v1.19.x/nginx-ingress.yaml

本地docker-desktop
登录token

eyJhbGciOiJSUzI1NiIsImtpZCI6IjNtbXpBSThjZTJDUHZfWEc0bWd4a1JvOHVGZ2hpcEpkc0ZpRHdvd0haaDgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJvYXJkLXVzZXItdG9rZW4tcmQyeDIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoia3Vib2FyZC11c2VyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiY2QwNjgzM2YtODk2My00ZGFkLThkYTgtOTk3OGRhYmQ0ODFlIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmt1Ym9hcmQtdXNlciJ9.RmxsPmRjLd5hR81MqAT5osljIR6oV1JC_ALa_6DWdsS6bHjxZ1o1JQ1XIqKL3cnXWic1rLipzDjDp_LINEz6UhpU2VTYM1YHITnuICd5ST_jFYE6tXFGWRrvsIsya8IFMaw4dz3rkhuiQfFHiwkoEU4unmUua268lOYNT9zF2SoXdEnfvdtN9h-o7U6PlHPytyV0muOrANZN8YhwP7EDeF12j4ZWwJxxR_u82g-PZ2dsVimvVRI5MtflB2E3a4qBC7Tyoq1Oh6p8bWCkAQFLVt2EbwawmKhkehg0aN4StVtLJP_qAsAJonMwgwxaO6mhfq_t8ZEkJ1zorLyYyvfx9A