# error: unable to upgrade connection: pod does not exist

- **ID:** `kubernetes/exec-in-terminating-pod`
- **Domain:** kubernetes
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Attempting to exec into a pod that is in Terminating state or has already been deleted, causing the kubelet to reject the connection upgrade.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.24 | active | — | — |
| 1.25 | active | — | — |
| 1.26 | active | — | — |
| 1.27 | active | — | — |
| 1.28 | active | — | — |

## Workarounds

1. **Wait for pod to fully terminate, then re-create: kubectl wait --for=delete pod/<pod-name> --timeout=60s && kubectl apply -f pod.yaml** (85% success)
   ```
   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** (90% success)
   ```
   Force delete the pod if stuck: kubectl delete pod <pod-name> --grace-period=0 --force, then exec into a new pod
   ```

## Dead Ends

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