在Linux系統安裝Kubernetes,一般可按以下步驟進行:
hostnamectl設置主機名,編輯/etc/hosts文件確保節點間能互通。systemctl stop firewalld等命令關閉防火墻,用sed命令注釋/etc/selinux/config中相關行來禁用SELinux。sudo swapoff -a臨時關閉,編輯/etc/fstab永久關閉。可選擇Docker或Containerd,推薦Containerd。以Ubuntu為例,安裝Containerd的命令為:sudo apt-get update && sudo apt-get install -y containerd,然后生成默認配置并啟用:sudo mkdir -p /etc/containerd,containerd config default | sudo tee /etc/containerd/config.toml,sudo systemctl restart containerd,sudo systemctl enable containerd。
sudo apt-get update && sudo apt-get install -y apt-transport-https curl,再通過curl命令添加GPG密鑰和源;CentOS系統通過創建/etc/yum.repos.d/kubernetes.repo文件添加源。yum或apt-get安裝,安裝后可用apt-mark hold(Ubuntu)或systemctl disable(CentOS)防止自動升級。在主節點上執行sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=MASTER_IP,初始化成功后,按提示將生成的配置文件復制到$HOME/.kube/config并設置權限。
以Flannel為例,執行kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml。
在主節點獲取加入命令kubeadm token create --print-join-command,然后在工作節點上執行該命令,將節點加入集群。