节点加入集群 - 横向扩展服务器
生成token
# 脚本
#!/bin/bash
if [ $EUID -ne 0 ];then
echo "You must be root (or sudo) to run this script"
exit 1
fi
if [ $# != 1 ] ; then
echo "Usage: $0 [master-hostname | master-ip-address]"
echo " e.g.: $0 api.k8s.hiko.im"
exit 1;
fi
token=`kubeadm token create`
cert_hash=`openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'`
echo "Refer the following command to join kubernetes cluster:"
echo "kubeadm join $1:6443 --token ${token} --discovery-token-ca-cert-hash sha256:${cert_hash}"
Node节点加入集群
1. 生成Token
# 在master节点执行
bash create-join.sh master主机IP地址
2. 执行命令
# 复制最后一条 命令执行 例如
# Refer the following command to join kubernetes cluster:
# kubeadm join k8s-master-ha:6443 --token jk6cy1.ll75w078owzmn4tg --discovery-token-ca-cert-hash sha256:3a6394b4c9b171e1b18b5341b6ac9418b17cd2b2ebe710a28028b79038691bf6
Master节点加入集群
1. 生成密钥Key
kubeadm init phase upload-certs --upload-certs
# 复制最后一条 密钥Key
# 例如
# [upload-certs] Using certificate key:
# 02e40d41f32de227ad82a9e8d452bdf9790fc6f1a881c8dcfaba94a379021420
2. 生成Token
# 在master节点执行
bash create-join.sh master主机IP地址
# 复制最后一条 命令执行 例如
# Refer the following command to join kubernetes cluster:
# kubeadm join k8s-master-ha:6443 --token jk6cy1.ll75w078owzmn4tg --discovery-token-ca-cert-hash sha256:3a6394b4c9b171e1b18b5341b6ac9418b17cd2b2ebe710a28028b79038691bf6
3. 组合命令
# 密钥Key + Token + --control-plane + --certificate-key
kubeadm join k8s-master-ha:6443 --token jk6cy1.ll75w078owzmn4tg --discovery-token-ca-cert-hash sha256:3a6394b4c9b171e1b18b5341b6ac9418b17cd2b2ebe710a28028b79038691bf6 --control-plane --certificate-key 02e40d41f32de227ad82a9e8d452bdf9790fc6f1a881c8dcfaba94a379021420