[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz'
时间: 2023-11-22 10:46:41 浏览: 130
该报错是由于kubelet无法连接到本地的10248端口导致的。解决方法是重启docker并重新初始化kubeadm。具体步骤如下:
```
# 添加以下内容
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
# 重启docker
systemctl restart docker
# 重新初始化
kubeadm reset # 先重置
kubeadm init \
--apiserver-advertise-address=192.168.42.122 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.22.2 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all
```
相关问题
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost :10248/healthz": dial tcp [::1]:10248: connect: connection refused.[kubelet-check] It seems like the kubelet isn't running or healthy. [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost :10248/healthz": dial tcp [::1]:10248: connect: connection refused. 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'
根据提供的错误信息,看起来是关于 Kubernetes 中 kubelet 的运行或健康性出现了问题。kubelet 是 Kubernetes 的一个核心组件,负责管理节点上的容器和与控制平面通信。
错误信息中提到了两个 HTTP 请求失败的问题,指向了 localhost 的地址和端口。这可能意味着 kubelet 进程没有运行,或者由于节点的某些配置问题导致 kubelet 无法正常工作。
如果你的系统是基于 systemd 的,可以尝试使用以下命令来排查错误:
- 'systemctl status kubelet':查看 kubelet 服务的状态
- 'journalctl -xeu kubelet':查看 kubelet 的日志
另外,控制平面组件可能在容器运行时启动时崩溃或退出。你可以使用你喜欢的容器运行时 CLI 工具列出所有正在运行的 Kubernetes 容器,例如使用 Docker 运行时可以执行:
- 'docker ps -a | grep kube | grep -v pause':列出所有包含 "kube" 但不包含 "pause" 的容器
一旦找到出错的容器,你可以使用下面的命令检查其日志:
- 'docker logs CONTAINERID':查看容器的日志信息
通过查看 kubelet 服务状态、kubelet 日志以及容器日志,你可以更进一步排查和定位问题所在。
The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
### 解决方案分析
当遇到 `curl` 命令返回 `(7) Failed connect to localhost:10248; 拒绝连接` 的错误时,这通常表明目标服务未运行或监听指定端口。以下是可能的原因及其解决方案:
#### 1. **Kubelet健康检查端口未启用**
Kubernetes 中的 Kubelet 默认会暴露一个本地健康检查接口 `/healthz`,但该功能需要显式配置才能正常工作。如果 Kubelet 配置文件中缺少相关参数,则可能导致此问题[^1]。
#### 修改方法
编辑 Kubelet 启动参数,确保包含以下选项:
```bash
--address=127.0.0.1 --port=10248 --read-only-port=10249 --authentication-anonymous=true
```
如果使用 systemd 管理 Kubelet,可以编辑其服务文件并重启服务:
```bash
sudo systemctl edit kubelet
```
添加环境变量:
```ini
[Service]
Environment="KUBELET_EXTRA_ARGS=--address=127.0.0.1 --port=10248 --read-only-port=10249"
```
接着重启 Kubelet:
```bash
sudo systemctl daemon-reload && sudo systemctl restart kubelet
```
#### 2. **防火墙阻止访问**
如果服务器启用了防火墙规则,可能会阻止单独对特定端口(如 10248)的访问。可以通过临时禁用防火墙来验证这一点:
```bash
sudo ufw disable || sudo iptables -F
```
或者允许特定端口通过防火墙:
```bash
sudo ufw allow 10248/tcp
```
#### 3. **Docker 和 Kubelet cgroup 驱动不一致**
当 Docker 使用的 cgroup 驱动与 Kubelet 不匹配时,可能导致组件间通信异常,从而影响健康检查等功能[^4]。确认两者使用的驱动是否相同:
- 查看 Docker 驱动:
```bash
docker info | grep -i cgroup
```
- 查看 Kubelet 驱动:
```bash
ps aux | grep kubelet | grep cgroup
```
若发现差异,需统一两者的设置。例如,在 Docker 配置文件中修改驱动为 `systemd`:
```bash
vi /lib/systemd/system/docker.service
```
找到 `[Service]` 节点下的 `ExecStart` 行,并追加参数:
```ini
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd
```
更新配置后重新加载并启动 Docker:
```bash
sudo systemctl daemon-reload && sudo systemctl restart docker
```
#### 4. **API Server 连接问题**
错误信息还提到无法连接至 API Server (`localhost:8080`) 或其他节点上的地址(`192.168.0.102:6443`)。这是由于客户端尝试默认连接到旧版无认证的端口所致[^2]。建议始终提供完整的上下文信息给 kubectl 工具:
```bash
export KUBECONFIG=~/.kube/config
kubectl get pods --all-namespaces
```
此外,可通过调试模式进一步排查网络连通性:
```bash
curl -k https://<master-ip>:6443/healthz
```
---
### 总结代码片段
```bash
# 修改 Kubelet 参数
sudo systemctl edit kubelet
cat <<EOF > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[Service]
Environment="KUBELET_EXTRA_ARGS=--address=127.0.0.1 --port=10248 --read-only-port=10249"
EOF
sudo systemctl daemon-reload && sudo systemctl restart kubelet
# 统一 Docker 和 Kubelet cgroup 驱动
vi /lib/systemd/system/docker.service
sed -i 's/--exec-opt native\.cgroupdriver=cgroupfs/--exec-opt native.cgroupdriver=systemd/g' /lib/systemd/system/docker.service
sudo systemctl daemon-reload && sudo systemctl restart docker
# 测试健康状态
curl -sSL http://localhost:10248/healthz
```
---
###
阅读全文
相关推荐















