# 错误：无法升级连接：Pod 不存在

- **ID:** `kubernetes/exec-in-terminating-pod`
- **领域:** kubernetes
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

尝试对处于 Terminating 状态或已被删除的 Pod 执行 exec 操作，导致 kubelet 拒绝连接升级。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.24 | active | — | — |
| 1.25 | active | — | — |
| 1.26 | active | — | — |
| 1.27 | active | — | — |
| 1.28 | active | — | — |

## 解决方案

1. ```
   Wait for pod to fully terminate, then re-create: kubectl wait --for=delete pod/<pod-name> --timeout=60s && kubectl apply -f pod.yaml
   ```
2. ```
   Force delete the pod if stuck: kubectl delete pod <pod-name> --grace-period=0 --force, then exec into a new pod
   ```

## 无效尝试

- **Re-running kubectl exec immediately with same pod name** — Pod 仍在终止中或已完全删除，重试不会改变状态 (95% 失败率)
- **Checking pod logs instead of exec** — 日志可能已被清理或 Pod 已不存在，日志命令同样会失败 (80% 失败率)
- **Restarting kubelet on the node** — Pod 状态由 API Server 管理，kubelet 重启不影响已删除的 Pod (90% 失败率)
