okteto-debugging
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOkteto Environment Debugger
Okteto环境调试器
This skill triages broken Okteto environments. When a service is misbehaving, run through the triage algorithm below, apply the matching playbook, and emit a structured diagnosis. Do not guess — always let the command output drive the conclusion.
Diagnostics are read-only: , , , and are fine here. Never mutate the cluster with raw / — fixes go through and (see the skill for lifecycle operations, worktree isolation, and teardown rules).
kubectl getkubectl describekubectl logskubectl get eventskubectlhelmokteto buildokteto deployokteto此技能用于诊断故障的Okteto环境。当服务运行异常时,请按照以下诊断流程执行,应用匹配的处理手册,并输出结构化诊断结果。请勿猜测——始终以命令输出作为结论依据。
诊断为只读操作:允许使用、、和命令。禁止使用原生/修改集群——修复操作需通过和完成(生命周期操作、工作树隔离和销毁规则请参考技能)。
kubectl getkubectl describekubectl logskubectl get eventskubectlhelmokteto buildokteto deployoktetoTriage algorithm
诊断流程
Run these steps in order. Stop at the first step that identifies the failure.
按顺序执行以下步骤,在第一个识别出故障的步骤处停止。
Step 1: Verify connectivity and pin the namespace
步骤1:验证连接并锁定命名空间
bash
okteto context showIf this fails, the user is disconnected from the cluster. Stop and help them reconnect () before proceeding.
okteto context use <url>The JSON output includes the active . Capture it — every command below targets it explicitly as :
namespace$nsbash
ns=$(okteto context show | jq -r .namespace)If you are working in an isolated worktree namespace (see the skill), use that namespace instead — the environment you need to debug lives there, not in the context's default.
oktetokubectl must target the same cluster and namespace as Okteto. kubectl reads its own kubeconfig, which can point at a different namespace — or a different cluster entirely — than the Okteto context, especially when multiple agents or worktrees are active on the same machine. Run to download credentials for the cluster selected via , and pass on every kubectl command. If errors or shows pods that don't match the services in , fix the kubeconfig before trusting any diagnostic output.
okteto kubeconfigokteto context-n "$ns"kubectl get pods -n "$ns"okteto.yamlbash
okteto context show如果此命令失败,说明用户已与集群断开连接。停止后续操作,先帮助用户重新连接()。
okteto context use <url>JSON输出包含当前激活的。请记录该值——以下所有命令均需显式指定此命名空间为:
namespace$nsbash
ns=$(okteto context show | jq -r .namespace)如果您正在隔离工作树命名空间中操作(参考技能),请使用该命名空间——需要调试的环境位于此命名空间,而非上下文默认命名空间。
oktetokubectl必须与Okteto指向相同的集群和命名空间。 kubectl读取自身的kubeconfig,其指向的命名空间或集群可能与Okteto上下文不同,尤其是当同一台机器上运行多个agent或工作树时。运行下载Okteto上下文所选集群的凭据,并在每个kubectl命令后添加。如果报错或显示的Pod与中的服务不匹配,请先修复kubeconfig,再信任任何诊断输出。
okteto kubeconfig-n "$ns"kubectl get pods -n "$ns"okteto.yamlStep 2: Discover services
步骤2:发现服务
bash
cat okteto.yamlParse the and sections for canonical service names. Never hardcode service names — always derive them from .
deploydevokteto.yamlbash
cat okteto.yaml解析和部分,获取标准服务名称。请勿硬编码服务名称——始终从中提取。
deploydevokteto.yamlStep 3: Snapshot pod states
步骤3:快照Pod状态
bash
kubectl get pods -n "$ns"This is the master triage signal. Map each pod to one of these states and apply the matching playbook below:
| Pod state | Playbook |
|---|---|
| Crash loop |
| OOM kill |
| Image pull failure |
| Unschedulable |
| Runtime error |
| No pods exist / deploy never completed | Deploy failure |
All pods | Sync / dev mode issue |
If the user named a specific service, filter to that service's pods only. If no service was named, check all pods.
Playbooks
处理手册
Crash loop (CrashLoopBackOff)
崩溃循环(CrashLoopBackOff)
The container starts, crashes, and Kubernetes keeps restarting it.
bash
undefined容器启动后崩溃,Kubernetes持续重启它。
bash
undefinedGet logs from the previous (crashed) container instance
获取上一个(已崩溃)容器实例的日志
kubectl logs <pod-name> --previous -n "$ns"
kubectl logs <pod-name> --previous -n "$ns"
If that fails (first crash, no previous), get current logs
如果该命令失败(首次崩溃,无历史日志),获取当前日志
kubectl logs <pod-name> -n "$ns"
kubectl logs <pod-name> -n "$ns"
Check exit code and liveness/readiness probe config
检查退出码和存活/就绪探针配置
kubectl describe pod <pod-name> -n "$ns"
**Look for:**
- Exit code in `kubectl describe pod` — `Exit Code: 1` is an app error; `Exit Code: 137` is OOM (see OOM playbook); `Exit Code: 126/127` means the entrypoint command wasn't found
- The last lines of `--previous` logs — the final error before crash is usually the root cause
- Liveness probe failures in `kubectl describe pod` events section — misconfigured health check paths or timeouts
**Common root causes:**
- Missing or wrong environment variable (`fatal: required env var FOO not set`)
- Can't connect to a dependency (database, message queue) that isn't ready yet
- Port mismatch between app and probe configuration
- Command/entrypoint not found (wrong base image or typo in okteto.yaml `command`)
---kubectl describe pod <pod-name> -n "$ns"
**需关注:**
- `kubectl describe pod`中的退出码——`Exit Code: 1`为应用错误;`Exit Code: 137`为内存溢出(参考内存溢出处理手册);`Exit Code: 126/127`表示入口命令未找到
- `--previous`日志的最后几行——崩溃前的最终错误通常是根本原因
- `kubectl describe pod`事件部分中的存活探针失败——健康检查路径或超时配置错误
**常见根本原因:**
- 缺失或错误的环境变量(`fatal: required env var FOO not set`)
- 无法连接到尚未就绪的依赖项(数据库、消息队列)
- 应用与探针配置的端口不匹配
- 命令/入口未找到(基础镜像错误或okteto.yaml中`command`存在拼写错误)
---OOM kill (OOMKilled)
内存溢出终止(OOMKilled)
The container exceeded its memory limit and was killed by Kubernetes.
bash
kubectl describe pod <pod-name> -n "$ns"Look for:
- in the
OOMKilledsectionLast State - value under
limits.memory→ContainersLimits - Compare limit to how much memory the service actually needs
Fix pattern:
Increase the memory limit in the service's Helm values or . Show the user the exact current limit and suggest a reasonable increase (typically 2×). Do not suggest removing limits entirely.
okteto.yaml容器超出内存限制,被Kubernetes终止。
bash
kubectl describe pod <pod-name> -n "$ns"需关注:
- 部分中的
Last State标记OOMKilled - →
Containers下的Limits值limits.memory - 将限制值与服务实际所需内存进行对比
修复方案:
在服务的Helm配置或中增加内存限制。向用户显示当前的精确限制值,并建议合理的增量(通常为2倍)。请勿建议完全移除限制。
okteto.yamlImage pull failure
镜像拉取失败
Kubernetes can't pull the container image.
bash
kubectl describe pod <pod-name> -n "$ns"Look for:
- in the Events section
Failed to pull image - The exact image reference Kubernetes tried to pull (registry, repo, tag)
- vs
ImagePullBackOff— both mean the same thing, different retry statesErrImagePull
Common root causes:
- Image doesn't exist (typo in tag, or was never run for this service)
okteto build - Image exists but is in a private registry with no pull credentials
- Tag was deleted or overwritten after a bad push
Fix pattern:
If the image should have been built by Okteto, run . If the image is external, verify the tag exists. If credentials are the issue, help the user create an image pull secret.
okteto build <service>Kubernetes无法拉取容器镜像。
bash
kubectl describe pod <pod-name> -n "$ns"需关注:
- Events部分中的信息
Failed to pull image - Kubernetes尝试拉取的镜像完整引用( registry、仓库、标签)
- 与
ImagePullBackOff——两者含义相同,仅重试状态不同ErrImagePull
常见根本原因:
- 镜像不存在(标签拼写错误,或未针对此服务运行)
okteto build - 镜像存在但位于私有registry且无拉取凭据
- 标签在错误推送后被删除或覆盖
修复方案:
如果镜像应由Okteto构建,运行。如果镜像是外部镜像,验证标签是否存在。如果是凭据问题,帮助用户创建镜像拉取密钥。
okteto build <service>Pending / unschedulable
Pending / 无法调度
The pod has been accepted by Kubernetes but hasn't been scheduled onto a node.
bash
kubectl describe pod <pod-name> -n "$ns"Pod已被Kubernetes接受,但尚未调度到节点上。
bash
kubectl describe pod <pod-name> -n "$ns"Also check recent namespace events for quota / resource pressure
同时检查命名空间近期事件,排查配额/资源压力
kubectl get events -n "$ns" --sort-by=.lastTimestamp | tail -20
**Look for in `kubectl describe pod` → Events:**
- `Insufficient cpu` or `Insufficient memory` — node has no room; check resource requests
- `0/N nodes are available` — no node matches the scheduling constraints
- `node(s) had untolerated taint` — pod needs a toleration for a taint on the nodes
- `node(s) didn't match node affinity/selector` — nodeSelector or affinity rules are too strict
- Resource quota exceeded — check `kubectl describe resourcequota -n "$ns"`
**Fix pattern:**
Match the error to the constraint. For resource requests, lower the request or ask the user to scale the node pool. For taints/selectors, show the current constraint and suggest removing or correcting it.
---kubectl get events -n "$ns" --sort-by=.lastTimestamp | tail -20
**在`kubectl describe pod` → Events中需关注:**
- `Insufficient cpu`或`Insufficient memory`——节点资源不足;检查资源请求配置
- `0/N nodes are available`——无节点匹配调度约束
- `node(s) had untolerated taint`——Pod需要节点污点容忍配置
- `node(s) didn't match node affinity/selector`——nodeSelector或亲和规则过于严格
- 超出资源配额——检查`kubectl describe resourcequota -n "$ns"`
**修复方案:**
根据错误匹配对应的约束。对于资源请求,降低请求值或建议用户扩容节点池。对于污点/选择器,显示当前约束并建议移除或修正。
---Runtime error (Running but unhealthy)
运行时错误(Running但状态异常)
Pods are but the service isn't responding, health checks are failing, or the user sees errors in requests.
Runningbash
undefinedPod处于状态,但服务无响应、健康检查失败,或用户在请求中看到错误。
Runningbash
undefinedGet recent application logs
获取近期应用日志
okteto logs <service> --since 10m -n "$ns"
okteto logs <service> --since 10m -n "$ns"
If that's not enough context
如果上下文信息不足
okteto logs <service> --tail 200 -n "$ns"
**Look for:**
- Stack traces or `panic:` lines — note the source file and line number
- Connection refused / timeout errors to dependencies — service is up but a downstream is not
- HTTP 5xx errors logged by a middleware or proxy
- "address already in use" — port conflict inside the container
**Fix pattern:**
Quote the most relevant 5–10 lines of the stack trace or error. Identify the source file if named. Suggest the specific fix — a code change, a missing env var, or a dependent service that needs to be started.
---okteto logs <service> --tail 200 -n "$ns"
**需关注:**
- 堆栈跟踪或`panic:`行——记录源文件和行号
- 依赖项连接被拒绝/超时错误——服务已启动但下游依赖未就绪
- 中间件或代理记录的HTTP 5xx错误
- "address already in use"——容器内部端口冲突
**修复方案:**
引用最相关的5-10行堆栈跟踪或错误信息。如果有文件名,标识出来。建议具体的修复方式——代码变更、缺失的环境变量,或需要启动的依赖服务。
---Deploy failure
部署失败
The pods never appeared — failed before creating them.
okteto deploybash
undefinedPod从未出现——在创建Pod之前失败。
okteto deploybash
undefinedCheck if the manifest is valid first
先检查清单是否有效
okteto validate
okteto validate
Check deploy logs if validate passes
如果验证通过,检查部署日志
okteto logs --deploy -n "$ns"
**Look for:**
- `okteto validate` errors — YAML syntax, schema violations, missing required fields
- Helm template rendering errors in deploy logs
- Image build failures (Dockerfile errors, build context too large)
**Fix pattern:**
If `okteto validate` catches it, show the exact error and line. If it's a Helm error, show the template path. If it's a build error, show the Dockerfile stage that failed.
---okteto logs --deploy -n "$ns"
**需关注:**
- `okteto validate`错误——YAML语法、架构违规、缺失必填字段
- 部署日志中的Helm模板渲染错误
- 镜像构建失败(Dockerfile错误、构建上下文过大)
**修复方案:**
如果`okteto validate`检测到问题,显示精确错误和行号。如果是Helm错误,显示模板路径。如果是构建错误,显示Dockerfile中失败的阶段。
---Sync / dev mode issue
同步/开发模式问题
All pods are and , but the developer's code changes aren't being reflected in the dev container.
RunningReadyokteto statusokteto up <service>bash
okteto status -n "$ns"所有Pod均为且,但开发者的代码变更未反映在开发容器中。
RunningReadyokteto statusokteto up <service>bash
okteto status -n "$ns"If the summary isn't enough, get syncthing troubleshooting links
如果摘要信息不足,获取syncthing故障排查链接
okteto status --info -n "$ns"
**Look for:**
- `Sync status: error` or `Sync status: paused`
- File counts that aren't progressing
- A path in the sync output that doesn't match the actual source directory
The richest signal is the `okteto up` terminal itself — sync errors and conflict warnings surface there first, and you cannot see that session. Ask the user to paste its output.
**Fix pattern:**
Check the `sync` paths in `okteto.yaml` against the actual directory structure. If paths are correct, try `okteto down` followed by `okteto up <service>` (the user must run `okteto up` interactively — never run it yourself). If sync is stuck, `okteto doctor` will generate a diagnostic bundle.
---okteto status --info -n "$ns"
**需关注:**
- `Sync status: error`或`Sync status: paused`
- 文件计数未增长
- 同步输出中的路径与实际源目录不匹配
最丰富的信号来自`okteto up`终端本身——同步错误和冲突警告会首先在那里显示,而您无法查看该会话。请用户粘贴该终端的输出。
**修复方案:**
检查`okteto.yaml`中的`sync`路径与实际目录结构是否匹配。如果路径正确,尝试运行`okteto down`后再执行`okteto up <service>`(用户必须交互式运行`okteto up`——请勿自行运行)。如果同步卡住,`okteto doctor`会生成诊断包。
---Output format
输出格式
Always emit one block per unhealthy service:
undefined每个异常服务需输出一个区块:
undefinedDiagnosis: <service-name>
诊断结果: <service-name>
Root cause: <one sentence>
Evidence:
<relevant excerpt from logs or describe output — 5 to 20 lines, no more>
Fix:
<exact command to run or code change to make>
Confidence: High / Medium / Low
Use **Low** confidence when:
- The container has only crashed once (no `--previous` logs available)
- The error message is ambiguous or missing
- Multiple possible root causes match the evidence
If all pods are healthy, report:All services are Running and Ready. No obvious failures detected.
If you're still seeing issues, run to generate a full diagnostic bundle.
okteto doctor
---根本原因: <一句话总结>
证据:
<日志或describe输出的相关片段——5至20行,请勿超出>
修复方案:
<需执行的精确命令或需修改的代码>
置信度: 高 / 中 / 低
在以下情况使用**低**置信度:
- 容器仅崩溃一次(无`--previous`日志可用)
- 错误消息模糊或缺失
- 多个可能的根本原因与证据匹配
如果所有Pod均健康,输出:所有服务均处于Running且Ready状态。未检测到明显故障。
如果您仍遇到问题,请运行生成完整诊断包。
okteto doctor
---Common gotchas
常见注意事项
- kubectl and okteto can disagree — kubectl uses its own kubeconfig context, which may point at a different namespace or cluster than the Okteto context. If kubectl output doesn't match what commands report, run
oktetoand re-check withokteto kubeconfigbefore drawing any conclusion.-n "$ns" - fails on first crash — the container must have restarted at least once. Fall back to
kubectl logs --previous(current instance) or describe events.kubectl logs - Exit code 137 = OOM, not app error — if you see in a CrashLoopBackOff, treat it as OOM kill, not a crash loop.
exit code: 137 - pods don't have logs — skip
Pendingentirely and go straight tokubectl logs+kubectl describe pod.kubectl get events - vs
okteto logs— preferkubectl logsfor application output; useokteto logswhen you needkubectl logsor when the pod name is needed for--previous.describe - Never run as part of debugging — diagnose first. Only suggest teardown if the environment is unrecoverable and the user explicitly asks.
okteto destroy - Never run — it is interactive. If the fix requires re-entering dev mode, tell the user to run
okteto upin their terminal.okteto up <service>
- kubectl与okteto可能不一致——kubectl使用自身的kubeconfig上下文,其指向的命名空间或集群可能与Okteto上下文不同。如果kubectl输出与命令报告的内容不匹配,请先运行
okteto并添加okteto kubeconfig重新检查,再得出结论。-n "$ns" - 首次崩溃时会失败——容器必须至少重启一次。请回退到
kubectl logs --previous(当前实例)或查看describe事件。kubectl logs - 退出码137=内存溢出,而非应用错误——如果在CrashLoopBackOff中看到,请按内存溢出终止处理,而非崩溃循环。
exit code: 137 - Pending状态的Pod无日志——完全跳过,直接执行
kubectl logs+kubectl describe pod。kubectl get events - vs
okteto logs——优先使用kubectl logs获取应用输出;当需要okteto logs或Pod名称用于--previous时,使用describe。kubectl logs - 调试时请勿运行——先诊断。仅当环境无法恢复且用户明确要求时,才建议销毁。
okteto destroy - 请勿运行——该命令为交互式命令。如果修复需要重新进入开发模式,请告知用户在终端中运行
okteto up。okteto up <service>