Skip to content

cattle-cluster-agent CrashLoopBackOff 排查修复记录(第二次)

日期: 2026-08-15(下午) 集群: GPU AI-EAR RKE2 v1.35.6,节点 192.168.122.37 (szb122037.local) 现象: cattle-system/cattle-cluster-agent 反复 Error / CrashLoopBackOff 状态: ✅ 全部 4 个问题已修复(详见 03 号文档

  • 磁盘扩容 10G → 30G(virsh blockresize + growpart + xfs_growfs)
  • CA checksum 根因定位:jq -r 尾随 \n 导致 SHA256 不同
  • Addon controller 覆盖问题:需改 manifest 文件而非 kubectl
  • 宿主机 Worker 注册脚本已就绪(setup_host_worker.sh)

一、问题总览(本次共发现 4 层叠加问题)

┌──────────────────────────────────────────────────────────────┐
│  问题 1: CA checksum 不匹配(复发)                             │
│    Rancher 重建 agent Deployment,带回旧 checksum cd9078b7     │
│    修复: set env → 6903fb1e...da4424                          │
│                          ↓                                   │
│  问题 2: Pod 内 DNS 解析超时(核心新问题)                       │
│    节点 DHCP 下发 "search local" → Pod 解析 gpu.ai-ear.cn     │
│    时先试 gpu.ai-ear.cn.local → 上游 192.168.122.1 丢弃       │
│    *.local 查询 → 超时 → glibc 放弃解析 → agent 5s 超时崩溃    │
│    修复: RKE2 config 加 resolv-conf 指向无 search local 的文件 │
│                          ↓                                   │
│  问题 3: hosts.toml 被 RKE2 重启重新生成回 HTTPS               │
│    registries.yaml 被 system-agent 下发为 JSON 通配符 mirror   │
│    → RKE2 生成的 hosts.toml 缺 [host] 条目 → 镜像拉取失败      │
│    修复: registries.yaml 改为命名 mirror(带新 Harbor 密码)    │
│                          ↓                                   │
│  问题 4: 节点磁盘压力 DiskPressure                             │
│    8.9G 根盘,agent 连上后 Rancher 批量下发组件镜像              │
│    → 可用空间 < 5% 阈值(475MB)→ 驱逐 Pod(含 agent)→  Pending │
│    处理中: 清理无用镜像/快照层                                  │
└──────────────────────────────────────────────────────────────┘

二、问题 1:CA checksum 不匹配(复发)

日志特征:

ERROR: Configured cacerts checksum (6903fb1e...da4424)
does not match given --ca-checksum (cd9078b7...bec19a)

复发原因: Rancher 服务端在 agent 断开期间会重建 cattle-cluster-agent Deployment, 并使用其保存的旧 checksum,覆盖上次手动 set env 的修复(Pod 来自新 ReplicaSet)。

临时修复(同上次):

bash
kubectl set env deployment/cattle-cluster-agent -n cattle-system \
  CATTLE_CA_CHECKSUM=6903fb1eaadc30860dfe49b374cc4dedd7f45fb45d2f578f995a53b9ebda4424

⚠️ 注意: 只要 agent 连不上 Rancher,Rancher 就会用旧 checksum 重建 Deployment, 该修复会被反复覆盖。根治需在 Rancher 管理面操作(见"遗留事项")。


三、问题 2:Pod 内 DNS 解析超时(本次核心新问题)

排查过程

测试结果结论
节点 → 3 个 Rancher IP:443 (--resolve)全部 HTTP 200, ~40ms节点网络正常
Pod 内 → 3 个 Rancher IP:443 (--resolve)全部 HTTP 200, ~20msPod 网络正常
Pod 内 → https://gpu.ai-ear.cn/(走 DNS)超时 5s, exit 28DNS 解析问题
CoreDNS 日志大量 gpu.ai-ear.cn.local 转发 192.168.122.1:53 i/o timeoutsearch domain 查询被丢弃
节点直查上游: gpu.ai-ear.cn(绝对域名)1ms 返回 3 个 A 记录上游 DNS 本身正常
节点直查上游: gpu.ai-ear.cn.localTIMEOUT(被丢弃)上游丢弃 *.local 查询

根因链条

节点 /etc/resolv.conf (NetworkManager DHCP 生成):
  search local                      ← 问题源头
  nameserver 192.168.122.1

Pod 继承后 resolv.conf:
  search cattle-system.svc.cluster.local svc.cluster.local cluster.local local
  options ndots:5

解析 gpu.ai-ear.cn (2 个点 < ndots:5,先走 search 域):
  1. gpu.ai-ear.cn.cattle-system.svc.cluster.local → NXDOMAIN(快)
  2. gpu.ai-ear.cn.svc.cluster.local               → NXDOMAIN(快)
  3. gpu.ai-ear.cn.cluster.local                   → NXDOMAIN(快)
  4. gpu.ai-ear.cn.local → CoreDNS 转发 192.168.122.1 → 被丢弃,超时 ← 卡在这里
  5. glibc 遇到超时直接放弃,不再尝试绝对域名 → 解析失败

Agent "Testing connection" 总超时仅 5s → DNS 耗尽 → 崩溃重启

注: 节点自身解析正常是因为节点 resolv.conf 无 ndots:5(默认 ndots:1), gpu.ai-ear.cn 有 2 个点 ≥ 1,先尝试绝对域名,直接命中。

注: 上游 192.168.122.1 是宿主机 libvirt dnsmasq,对 .local 查询从 VM 发起时 直接丢包(本机查询返回 SERVFAIL)。宿主机防火墙/dnsmasq 的 .local 处理未深究。

修复方法(kubelet 专用 resolv.conf)

尝试用 nmcli 去掉 search local(ipv4.dns-search "" + ipv4.ignore-auto-dns yes) 无效——resolv.conf 仍被重新生成带 search local。改用 RKE2 层修复:

bash
# 1. 创建 kubelet 专用 resolv.conf(无 search local)
cat > /etc/rancher/rke2/resolv.conf << 'EOF'
# kubelet 专用:不包含 "search local"(DHCP 下发的 .local 查询会被上游丢弃导致 Pod DNS 超时)
nameserver 192.168.122.1
EOF

# 2. RKE2 config 指向它(影响所有 Pod 的 resolv.conf 生成,含 ClusterFirst 追加的 search 域)
echo "resolv-conf: /etc/rancher/rke2/resolv.conf" >> /etc/rancher/rke2/config.yaml

# 3. 重启 RKE2 并重建 Pod
systemctl restart rke2-server
kubectl delete pod -n cattle-system -l app=cattle-cluster-agent

验证: 新 Pod resolv.conf 为 search cattle-system.svc.cluster.local svc.cluster.local cluster.local (无 local),Pod 内 DNS 解析 gpu.ai-ear.cn 正常。✅


四、问题 3:hosts.toml 被 RKE2 重启重新生成回 HTTPS(复发)

复发原因

  1. Rancher system-agent 将 /etc/rancher/rke2/registries.yaml 下发为 JSON 通配符 mirror 格式:
    json
    {"configs":{"192.168.122.156:30000":{"auth":{...},"tls":{"insecure_skip_verify":true}}},
     "mirrors":{"*":{"endpoint":["http://192.168.122.156:30000"]}}}
  2. 这种配置下 RKE2 生成的 hosts.toml[host] 段为,只有 server = "https://192.168.122.156:30000/v2" → 镜像拉取全部 HTTPS 失败。
  3. 每次 rke2-server 重启都会从 registries.yaml 重新生成 hosts.toml, 上次手动的 hosts.toml 修复因此失效(本次即由 resolv-conf 修改后的重启触发)。

修复方法(改为命名 mirror)

bash
cat > /etc/rancher/rke2/registries.yaml << 'EOF'
mirrors:
  docker.io:
    endpoint:
      - "http://192.168.122.156:30000"
  quay.io:
    endpoint:
      - "http://192.168.122.156:30000"
  registry.k8s.io:
    endpoint:
      - "http://192.168.122.156:30000"
  "192.168.122.156:30000":          # ← 命名 mirror,让 RKE2 生成正确的 host 条目
    endpoint:
      - "http://192.168.122.156:30000"
configs:
  "192.168.122.156:30000":
    tls:
      insecure_skip_verify: true
    auth:
      username: xxx
      password: xxx   # ← 注意: Harbor 密码已变更(原为 xxx)
EOF
systemctl restart rke2-server

验证: 重启后 RKE2 重新生成的 hosts.toml 自动包含 [host."http://192.168.122.156:30000/v2"] 条目,crictl pull 成功。✅

⚠️ 风险: 若 Rancher 端私有仓库配置变更,system-agent 可能再次下发 JSON 通配符格式。 根治需在 Rancher UI 的集群 Registries 配置中使用针对 192.168.122.156:30000 的命名 mirror(而非 * 通配符)。


五、问题 4:节点磁盘压力 DiskPressure(处理中)

现象

  • agent 连上 Rancher 后,Rancher 开始批量下发系统组件(fleet-agent、helm-operation 等)
  • 磁盘可用空间跌破 kubelet 硬驱逐阈值 nodefs.available < 5%(8.9G 盘 → 475MB)
  • 节点被打上 node.kubernetes.io/disk-pressure:NoSchedule 污点
  • 23 个 fleet-agent Pod 被 Evicted,agent Pod 被驱逐后新 Pod Pending 无法调度

驱逐事件:

Warning Evicted: The node was low on resource: ephemeral-storage.
Threshold quantity: 475685485, available: 207256Ki.
Container cluster-register was using 967972Ki...

磁盘占用分析(截至排查时)

项目占用说明
/ 总计6.4G / 8.9G (73%)根盘 vda4,偏小
/var/lib/rancher5.0GRKE2 全部数据
└ containerd4.6G镜像内容 1.4G + overlayfs 快照层 3.2G
journal 日志24M正常
inode2%正常

镜像清单合计约 1.4G,其中 rancher-agent:v2.14.3 单镜像 610MB; overlayfs 快照层 3.2G 超出镜像体积,含大量被驱逐/退出容器的可写层残留。

kubelet 驱逐配置(RKE2 默认)

yaml
evictionHard:
  imagefs.available: 5%
  nodefs.available: 5%
evictionMinimumReclaim:
  imagefs.available: 10%
  nodefs.available: 10%

处理措施

bash
# 清理未使用镜像
crictl --runtime-endpoint unix:///run/k3s/containerd/containerd.sock rmi --prune

# 清理已退出的容器
crictl --runtime-endpoint unix:///run/k3s/containerd/containerd.sock rm \
  $(crictl --runtime-endpoint unix:///run/k3s/containerd/containerd.sock ps -aq --state Exited)

⚠️ 结构性问题: 8.9G 根盘对 all-in-one RKE2 + Rancher 系统组件过于紧张, 每次 agent 重连触发组件下发都可能再次打满。建议扩容根盘至 30G+


六、同期事件:新节点 yu 加入集群

排查期间(16:08 CST)发现本工作站 yu (10.20.24.225, Ubuntu 22.04) 通过 add_worker.sh 加入集群成为 worker 节点,状态 NotReady:

  • 本机 rke2-agent 服务已 active,连接 192.168.122.37:6443 成功
  • 但镜像拉取失败:与 .37 完全相同的 Harbor HTTPS/HTTP 问题 (http: server gave HTTP response to HTTPS client)
  • 需在 yu 上执行相同的 registries.yaml + hosts.toml 修复并 systemctl restart rke2-agent
  • 阻塞: 本机无免密 sudo,需用户手动执行或提供 sudo 权限

yu 节点修复命令(需在 yu 上以 root 执行):

bash
cat > /etc/rancher/rke2/registries.yaml << 'EOF'
mirrors:
  docker.io:
    endpoint: ["http://192.168.122.156:30000"]
  quay.io:
    endpoint: ["http://192.168.122.156:30000"]
  registry.k8s.io:
    endpoint: ["http://192.168.122.156:30000"]
  "192.168.122.156:30000":
    endpoint: ["http://192.168.122.156:30000"]
configs:
  "192.168.122.156:30000":
    tls:
      insecure_skip_verify: true
    auth:
      username: xxx
      password: xxx
EOF
systemctl restart rke2-agent

七、遗留事项(✅ 全部已解决)

以下事项已在 03 号文档中全部解决。

#事项说明状态
1Rancher 端旧 CA checksumagent Deployment 被 Rancher 用旧 checksum cd9078b7 反复重建。已通过修改 manifest 文件根治✅ 已修复
2根盘扩容8.9G → 已扩容至 30G(virsh blockresize + growpart + xfs_growfs)✅ 已修复
3Rancher UI Registry 配置已改为命名 mirror(非 * 通配符)✅ 已修复
4yu 节点修复registries.yaml + hosts.toml 修复已记录,待用户执行⏳ 待用户操作
5宿主机 dnsmasq .local 丢包已通过 RKE2 resolv-conf 绕过✅ 已绕过

八、时间线

07:09  system-agent 下发 JSON 格式 registries.yaml(含新 Harbor 密码)
07:4x  agent 因 CA checksum 不匹配 CrashLoopBackOff(用户报障)
       → set env 修复,但随后出现 "Could not securely connect" 超时
08:01  为修复 DNS 重启 rke2-server → hosts.toml 被重新生成回 HTTPS(当时未察觉,
       因 agent 镜像已在本地,未触发拉取)
08:03  创建 /etc/rancher/rke2/resolv.conf(无 search local)+ config.yaml resolv-conf
       → DNS 修复生效
08:07  set env 修正 checksum → agent 成功连接 Rancher
08:08  Rancher 开始下发组件(fleet-agent 等)+ 工作站 yu 加入集群
08:09  磁盘打满 → DiskPressure → 批量驱逐(23 个 fleet-agent Evicted)
08:14  DiskPressure 一度消退,但 agent Pod 因 hosts.toml 回退无法拉镜像
08:21  修复 registries.yaml(命名 mirror + 新密码)+ 重启 RKE2 → 拉取恢复
       → agent 启动写盘再次触发 DiskPressure,新 Pod Pending(处理中)