1.下載用於Kubernetes軟體包倉庫的公共簽名秘鑰
#如果 `/etc/apt/keyrings` 目錄不存在,則應在 curl 命令之前建立它。
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
新增Kubernetes apt 倉庫
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
檢視看具體配置
跟新apt 包索引
sudo apt-get update
2.k8s叢集軟體安裝
安裝軟體之前,可以先檢視軟體列表
apt-cache policy kubeadm
也可以檢視軟體列表及其依賴關係
apt-cache showpkg kubeadm
# 檢視軟體列表
apt-cache madison kubeadm
預設安裝
sudo apt-get install -y kubelet kubeadm kubectl
# 也可以安裝指定版本 sudo apt-get install -y kubelet=1.29.0-1.1 kubeadm=1.29.0-1.1 kubectl=1.29.0-1.1
# 鎖定版本,防止後期自動更新
sudo apt-mark hold kubelet kubeadm kubectl
# 解鎖版本,可以執行更新
sudo apt-mark unhold kubelet kubeadm kubectl
3.k8s叢集初始化
3.1.叢集配置檔案
檢視版本
kubeadm version
生成部署配置檔案
kubeadm config print init-defaults > kubeadm-config.yaml
需要編輯kubeadm-config.yaml檔案
vim kubeadm-config.yaml
需要將advertiseAddress: 1.2.3.4 由“1.2.3.4” 改成“192.168.113.131” 將name: node 由 "node" 改成 "k8s-master01" Netwoking 需要 增加 pod
檔案內容最後追加
--- kind: KubeletConfiguration apiVersion: kubelet.config.k8s.io/v1betal cgroupDriver: systemd
最終如下:
apiVersion: kubeadm.k8s.io/v1beta3 kind: InitConfiguration bootstrapTokens: - groups: - system:bootstrappers:kubeadm:default-node-token token: abcdef.0123456789abcdef ttl: 24h0m0s usages: - signing - authentication localAPIEndpoint: advertiseAddress: 192.168.113.131 bindPort: 6443 nodeRegistration: criSocket: unix:///var/run/containerd/containerd.sock imagePullPolicy: IfNotPresent name: k8s-master01 taints: null --- apiVersion: kubeadm.k8s.io/v1beta3 kind: ClusterConfiguration apiServer: timeoutForControlPlane: 4m0s certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controllerManager: {} dns: {} etcd: local: dataDir: /var/lib/etcd imageRepository: registry.k8s.io kubernetesVersion: 1.29.0 networking: dnsDomain: cluster.local serviceSubnet: 10.96.0.0/12 podSubnet: 10.244.0.0/16 scheduler: {} --- apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration cgroupDriver: systemd
檢視映象
sudo kubeadm config images list
# 拉取映象
kubeadm config images pull
如果拉取失敗則,可以使用
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers
# 檢視具體映象
crictl images
3.2使用部署配置檔案初始化K8S叢集
# 初始化
kubeadm init --config kubeadm-config.yaml
結果報錯了如下:
需要檢查配置檔案中的 apiVersion配置的資訊是否正確
正常輸出的內容如下: