切换到root用户
运行初始化脚本 init-os.sh
运行安装脚本 install-k8s.sh
运行安装脚本 install-kube-vip
kubeadm config print init-defaults --component-configs KubeletConfiguration > kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
nodeRegistration:
criSocket: unix:///var/run/containerd/containerd.sock # 使用 containerd 的 socket 地址
taints: null
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd # 配置 cgroup driver
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
controlPlaneEndpoint: 192.168.2.10:6443 # 设置控制平面 Endpoint 地址
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs # 配置kube-proxy ipvs模式
kubeadm config images pull --config kubeadm-config.yaml
kubeadm init --upload-certs --config kubeadm-config.yaml
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
注意:
控制节点同样需要安装containerd、kubelet、kubeadm、kubectl、kube-vip
kubeadm join 192.168.2.10:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:4a3134f5f3eeaf00cb05a0555d0f4532b818d0899ba242b4e6ba0ae13da64a77 \
--control-plane --certificate-key 36aa8b9c9e48256546df021d6940cad5655a7fce912b13b093fc9c9d6caa86ca
kubeadm join 192.168.2.10:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:4a3134f5f3eeaf00cb05a0555d0f4532b818d0899ba242b4e6ba0ae13da64a77
kubectl get nodes
如果忘记了上面的 join 命令可以使用命令
kubeadm token create --print-join-command
重新获取。 如果是添加control-plane可以使用命令kubeadm init phase upload-certs --upload-certs
获取加入证书, 在加入命令后添加--control-plane --certificate-key xxxx
参数
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/master/stable.txt)
CLI_ARCH=amd64
if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi
curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
sha256sum --check cilium-linux-${CLI_ARCH}.tar.gz.sha256sum
sudo tar xzvfC cilium-linux-${CLI_ARCH}.tar.gz /usr/local/bin
rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
cilium install
初始化命令