我试图使用 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-reload
和systemctl 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] 这可能需要一两分钟,具体取决于您的 Internet 连接速度
[preflight] 您也可以使用“kubeadm config images pull”预先执行此操作
[ certs] 使用 certificateDir 文件夹 "/etc/kubernetes/pki"
[certs] 生成 "ca" 证书和密钥
[certs] 生成 "apiserver" 证书和密钥
[certs] 为 DNS 名称 [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] 签名的 apiserver 服务证书
[certs] 生成“apiserver-kubelet-client”证书和密钥
[certs] 生成“front-proxy-ca”证书和密钥
[certs] 生成“front-proxy-client”证书和密钥
[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] etcd/peer 服务证书为 DNS 名称 [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 标志。环境"
[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] 创建静态 Pod 清单对于“/etc/kubernetes/manifests”中的本地 etcd
[wait-control-plane] 等待 kubelet 作为静态 Pod 从目录“/etc/kubernetes/manifests”启动控制平面。这最多可能需要 4m0s
[kubelet-check] 40s 的初始超时已通过。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 之间的连接问题。
有谁知道如何解决这一问题?