Linux

Kubernetes API 伺服器無法註冊主節點

  • May 13, 2022

我試圖使用 kubeadm 創建一個 Kubernetes 集群。我啟動了一個 Ubuntu 18.04 伺服器,安裝了 docker(確保 docker.service 正在執行),安裝了 kubeadm kubelet 和 kubectl。

以下是我執行的步驟:

sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` test"
sudo apt update
sudo apt install docker-ce
sudo systemctl enable docker
sudo systemctl start docker

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt-get install kubeadm kubelet kubectl -y
sudo apt-mark hold kubeadm kubelet kubectl 
kubeadm version
swapoff –a

此外,為了配置 Docker cgroup 驅動程序,我編輯了**/etc/systemd/system/kubelet.service.d/10-kubeadm.conf**。在文件中,我添加Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"並註釋掉了Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml".

/etc/systemd/system/kubelet.service.d/10-kubeadm.conf供參考:

# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
#Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

在此之後我跑了:systemctl daemon-reloadsystemctl restart kubelet。kubelet.service 執行良好。

接下來,我執行sudo kubeadm init --pod-network-cidr=10.244.0.0/16並收到以下錯誤:

root@ip-172-31-1-238:/home/ubuntu# kubeadm init –pod-network-cidr=10.244.0.0/16

$$ init $$使用 Kubernetes 版本:v1.23.1

$$ preflight $$進行飛行前檢查

$$ preflight $$拉取設置 Kubernetes 集群所需的鏡像

$$ preflight $$這可能需要一兩分鐘,具體取決於您的網際網路連接速度

$$ preflight $$您還可以使用“kubeadm config images pull”預先執行此操作

$$ certs $$使用 certificateDir 文件夾“/etc/kubernetes/pki”

$$ certs $$生成“ca”證書和密鑰

$$ certs $$生成“apiserver”證書和密鑰

$$ certs $$為 DNS 名稱簽名的 apiserver 服務證書$$ ip-172-31-1-238 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local $$和 IP$$ 10.96.0.1 172.31.1.238 $$

$$ certs $$生成“apiserver-kubelet-client”證書和密鑰

$$ certs $$生成“front-proxy-ca”證書和密鑰

$$ certs $$生成“前端代理客戶端”證書和密鑰

$$ certs $$生成“etcd/ca”證書和密鑰

$$ certs $$生成“etcd/server”證書和密鑰

$$ certs $$etcd/server 服務證書為 DNS 名稱簽名$$ ip-172-31-1-238 localhost $$和 IP$$ 172.31.1.238 127.0.0.1 ::1 $$

$$ certs $$生成“etcd/peer”證書和密鑰

$$ certs $$為 DNS 名稱簽署 etcd/peer 服務證書$$ ip-172-31-1-238 localhost $$和 IP$$ 172.31.1.238 127.0.0.1 ::1 $$

$$ certs $$生成“etcd/healthcheck-client”證書和密鑰

$$ certs $$生成“apiserver-etcd-client”證書和密鑰

$$ certs $$生成“sa”密鑰和公鑰

$$ kubeconfig $$使用 kubeconfig 文件夾“/etc/kubernetes”

$$ kubeconfig $$編寫“admin.conf”kubeconfig 文件

$$ kubeconfig $$編寫“kubelet.conf”kubeconfig 文件

$$ kubeconfig $$編寫“controller-manager.conf”kubeconfig 文件

$$ kubeconfig $$編寫“scheduler.conf”kubeconfig 文件

$$ kubelet-start $$將帶有標誌的 kubelet 環境文件寫入文件“/var/lib/kubelet/kubeadm-flags.env”

$$ kubelet-start $$將 kubelet 配置寫入文件“/var/lib/kubelet/config.yaml”

$$ kubelet-start $$啟動 kubelet

$$ control-plane $$使用清單文件夾“/etc/kubernetes/manifests”

$$ control-plane $$為“kube-apiserver”創建靜態 Pod 清單

$$ control-plane $$為“kube-controller-manager”創建靜態 Pod 清單

$$ control-plane $$為“kube-scheduler”創建靜態 Pod 清單

$$ etcd $$在“/etc/kubernetes/manifests”中為本地 etcd 創建靜態 Pod 清單

$$ wait-control-plane $$等待 kubelet 作為靜態 Pod 從目錄“/etc/kubernetes/manifests”啟動控制平面。這可能需要長達 4m0s

$$ kubelet-check $$40 秒的初始超時已過。

    Unfortunately, an error has occurred:  
            timed out waiting for the condition  

    This error is likely caused by:  
            - The kubelet is not running  
            - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)  

    If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:  
            - 'systemctl status kubelet'  
            - 'journalctl -xeu kubelet'  

    Additionally, a control plane component may have crashed or exited when started by the container runtime.  
    To troubleshoot, list all containers using your preferred container runtimes CLI.  

    Here is one example how you may list all Kubernetes containers running in docker:  
            - 'docker ps -a | grep kube | grep -v pause'  
             Once you have found the failing container, you can inspect its logs with:  
            - 'docker logs CONTAINERID'  

執行後systemctl status kubelet.service,似乎 kubelet 執行良好。

但是,執行後journalctl -xeu kubelet,我得到以下日誌:

kubelet.go:2347]“容器執行時網路未準備好”networkReady=“NetworkReady=false 原因:NetworkPluginNotReady 消息:docker:網路外掛未準備好:cni 配置未初始化”

kubelet.go:2422]“獲取節點時出錯"err=“節點“ip-172-31-1-238”未找到”

kubelet.go:2422]“獲取節點時出錯”err=“節點“ip-172-31-1-238”未找到”

controller.go:144]無法確保租約存在,將在 7 秒後重試,錯誤:Get “https://172.31.1.238:6443/apis/coordination.k8s.io/v1/namespaces/kube-node-lease/leases/ip-172-31 -1-238?timeout=10s”: dial tcp 172.31.1.238:6443: connect: connection

denied kubelet.go:2422] “Error getting node” err=“node “ip-172-31-1-238” not found "

kubelet.go:2422]“獲取節點時出錯”err=“未找到節點“ip-172-31-1-238””

kubelet_node_status.go:70] “正在嘗試註冊節點” node=“ip-172-31-1-238”

kubelet_node_status.go:92] “無法向 API 伺服器註冊節點” err=“Post “https://172.31 .1.238:6443/api/v1/nodes”: 撥打 tcp 172.31.1.238:6443: 連接: 連接被拒絕” node=“ip-172-31-1-238”

kubelet.go:2422] “獲取節點時出錯” 錯誤=“節點 “ip-172-31-1-238” 未找到”

版本:

Docker: Docker 版本 20.10.12,建構 e91ed57

Kubeadm: {Major:“1”,Minor:“23”,GitVersion:“v1.23.1”,GitCommit:“86ec240af8cbd1b60bcc4c03c20da9b98005b92e”,GitTreeState:“clean”,BuildDate:” 2021-12-16T11:39:51Z”,GoVersion:“go1.17.5”,編譯器:“gc”,平台:“linux/amd64”}

不確定這是否是 Kube Api Server 和 Kubelet 之間的連接問題。

有誰知道如何解決這一問題?

這裡使用的 kubeadm 版本是 1.23.1。Kubernetes 不再直接支持 docker。在這裡閱讀。據我了解,您都已安裝但未連接。另外,我沒有看到您在 docker 安裝命令中指定了 containerd.io。參考這裡。

選項 1:安裝 contianerd。請按照此步驟操作。 如果問題仍然存在,請通過在 kubelet 服務中添加以下選項來配置 kubelet 服務以使用 containerd。

--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock

選項 2:正確安裝 docker 並按照此處所述進行配置。

引用自:https://serverfault.com/questions/1088776