kubeadm init 时启动 apiserver失败

执行

 sudo kubeadm init \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.32.1 \
  --pod-network-cidr=10.244.0.0/16 \
  --apiserver-advertise-address=192.168.1.10

遇到报错

[api-check] Waiting for a healthy API server. This can take up to 4m0s
[api-check] The API server is not healthy after 4m0.000168093s

Unfortunately, an error has occurred:
        context deadline exceeded

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 running Kubernetes containers by using crictl:
        - 'crictl --runtime-endpoint unix:///var/run/containerd/containerd.sock ps -a | grep kube | grep -v pause'
        Once you have found the failing container, you can inspect its logs with:
        - 'crictl --runtime-endpoint unix:///var/run/containerd/containerd.sock logs CONTAINERID'
error execution phase wait-control-plane: could not initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

contained默认镜像有问题
解决方法是

containerd config default > /etc/containerd/config.toml
sed -i 's/registry.k8s.io/registry.aliyuncs.com\/google_containers/' /etc/containerd/config.toml
systemctl daemon-reload
systemctl restart containerd
### 解决 Kubeadm 初始化遇到的错误 当面对 `kubeadm init` 命令失败的情况,通常会涉及多个方面的问题。以下是详细的解决方案: #### 准备好镜像 确保所需的基础镜像已经预先下载并加载到本地环境中。特别是对于国内网络环境而言,官方仓库可能访问困难,因此提前准备这些资源至关重要[^1]。 ```bash docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6 ``` #### 修改 Docker 服务文件 有默认配置下的Docker设置可能会阻碍Kubernetes组件之间的正常通信。调整相关参数可以有效改善这一情况。具体操作包括但不限于更改cgroup驱动程序以匹配kubelet的要求。 编辑 `/etc/docker/daemon.json` 文件: ```json { "exec-opts": ["native.cgroupdriver=systemd"] } ``` 重启Docker使改动生效: ```bash systemctl daemon-reload && systemctl restart docker ``` #### 执行初始化命令 使用带有适当选项的 `kubeadm init` 来启动集群创建过程。这里特别注意要指定正确的 Kubernetes 版本号以及必要的CIDR范围等参数。 ```bash kubeadm init \ --kubernetes-version=v1.14.2 \ --pod-network-cidr=10.244.0.0/16 \ --service-cidr=10.96.0.0/12 \ --ignore-preflight-errors=Swap ``` 如果仍然遭遇连接拒绝等问题,则需进一步检查节点健康状态和服务端口监听状况。例如确认API Server是否正在运行于预期地址和端口号上;验证防火墙规则允许内部流量通过等等[^2][^3]。 另外值得注意的是保持软件包的一致性和兼容性也很重要。比如确保所使用的 `kubeadm`, `kubelet` 和其他核心组件来自同一发行版系列,并且其版本之间相互支持[^4]。 最后提醒一点关于间同步的重要性——不同步的间可能导致证书验证失败从而引发各种异常行为。可以通过部署NTP客户端来维持各主机间精确的间戳交换[^5]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值