Merry Christmas & Happy 2027! Less downtime. More good times. Celebrating 13 years of sorlavit.com
Skip to content
Sorlavit KimIT Support, Network & Infrastructure Services Let’s talk

ปุ่มแปลไทยจะเปิดบทความผ่าน Google Translate เพื่อแปลอัตโนมัติ โดยคงโค้ดและคำสั่งไว้ตามต้นฉบับ

Kubernetes / Pods, Containers & Application Health

Confirm the Kubernetes context and namespace before troubleshooting

Prove which Kubernetes cluster, identity and namespace a diagnostic command will use, then inspect Pods without changing the shared current context.

Start hands-on practice · เริ่มภาคปฏิบัติ ↓

Compiled for Sorlavit Kim · Published · Updated · 3 min read

Practical guide · คู่มือลงมือทำ

Download worksheet · ดาวน์โหลดขั้นตอน

Detailed practical guide

Prepare your workspace and inputs

Obtain the expected context name, API hostname and namespace from the workload owner. The examples use team-lab and app; replace both with approved values. Do not paste a raw kubeconfig into a ticket because it may contain credentials.

Platform context: kubectl with a supported cluster connection and an existing namespace; read-only RBAC for the chosen test namespace.

Scenario to reproduce or investigate

Two clusters have an app namespace and similar Pod names. A successful kubectl command against the wrong cluster produces plausible evidence and can lead to an incorrect change.

Evidence to record in your worksheet
  • Actual target and platform release
  • Exact inputs or substituted values
  • Baseline result
  • Per-step expected and observed output
  • Failure encountered and corrective action
  • Final acceptance and recovery state
  1. Compare configured and expected cluster identity

    Run the following read-only commands. The first shows the selected context; the second lists available context-to-cluster mappings; the third shows only the server URL for the explicitly named context. Compare the server hostname with approved inventory rather than trusting a display name.

    Command, configuration or input

    kubectl config current-context
    kubectl config get-contexts
    kubectl --context=team-lab config view --minify -o jsonpath='{.clusters[0].cluster.server}'
    Expected result · ผลที่ควรเห็น

    The team-lab mapping points to the approved API endpoint. A different current context is acceptable because later commands explicitly name team-lab.

    If it fails · เมื่อไม่ผ่าน

    If team-lab is absent, stop and obtain the approved kubeconfig through your normal access process. Do not rename an unrelated context to make the check pass.

  2. Check the actual delegated read before listing workload data

    Ask the API authorization endpoint whether the current identity may list Pods in app. Then list only that namespace, preserving context and namespace flags. A Forbidden response is an access decision, not evidence that the namespace is empty.

    Command, configuration or input

    kubectl --context=team-lab -n app auth can-i list pods
    kubectl --context=team-lab -n app get pods -o wide
    Expected result · ผลที่ควรเห็น

    The authorization check prints yes and the Pod list is from the expected app namespace. No resources found is a valid empty result only after identity and namespace are verified.

    If it fails · เมื่อไม่ผ่าน

    If it prints no or the list is Forbidden, request the required namespace read permission from the owner; do not use cluster-admin as a diagnostic shortcut. A connection timeout needs endpoint, route or VPN checks first.

  3. Capture a bounded, reproducible handover

    Record the verified context label, API hostname, namespace, observation time and relevant Pod names in the ticket. Repeat the command from the same context to show that the evidence is reproducible. Keep identity tokens and full configuration files out of the handover.

    Command, configuration or input

    kubectl --context=team-lab -n app get pods --field-selector=status.phase=Pending -o wide
    Expected result · ผลที่ควรเห็น

    The follow-up list contains only Pending Pods from the intended target and can be matched with the earlier all-Pod snapshot.

    If it fails · เมื่อไม่ผ่าน

    If no Pending Pods remain, record the observation time and changed state instead of claiming the first result was false. If a context override changes between commands, repeat the identity check.

Check the result before marking this passed

The explicit context resolves to the expected API endpoint, delegated Pod reads are authorized and the workload namespace is verified. The ticket contains enough identity and timing information to reproduce the diagnostic without exposing kubeconfig secrets.

Record the observed result and evidence location in the downloaded worksheet. Mark unresolved or untested conditions explicitly.

Recovery and cleanup

These commands do not modify resources or current-context. If another operator changed shared kubeconfig during investigation, coordinate ownership and use an approved separate kubeconfig rather than overwriting their selection.

Apply to actual work and known limits

Use explicit context and namespace flags in incident commands, automation and handover records. This procedure verifies access to the API; it does not establish application health or authorize a resource change.

Authored against the cited documentation. Execution on the stated vendor product or physical equipment remains to be verified.

Background, explanations and original notes

Problem

A valid kubectl command can inspect the wrong cluster and produce convincing but irrelevant evidence. Establish the target before collecting an incident baseline.

Start with this check

Confirm the environment and replace sample objects, namespaces, images, paths and hosts with approved targets. Share only relevant, sanitized output. Follow the workload owner’s process for changes.

kubectl config current-context
kubectl -n app get pods -o wide

Read the result

The context names the selected client configuration; the Pod list is limited to the example namespace. Neither establishes that the cluster is the intended business environment.

Resolve and verify

Compare the context, API endpoint through approved inventory and namespace with the support request. Use the verified target consistently in later checks.

Before changing production

Do not share raw kubeconfig credentials or change the current context inside another operator's workflow without coordination.

Source & further reading

Kubernetes multiple-cluster access

Independently written summary reviewed on 2026-11-04. The example illustrates a possible application; it is not a client case study.

Share this article

Back to results