Skip to content

Room 05

CONTEXT & CONFIG


The Multi-Verse Switch

  • Multiple clusters exist in the kubeconfig, but only one holds the key.
  • Navigate contexts to find the right cluster and extract its secret.

📜 Mission Briefing

  1. View the current kubeconfig: kubectl config view.
  2. List all available contexts: kubectl config get-contexts.
  3. Check which context is currently active: kubectl config current-context.
  4. The kubeconfig file is at ~/.kube/config. Examine its structure.
  5. Find the cluster server URL for the current context and extract the port number.
  6. The password is kubectx followed by the last two digits of the port.

    Example: if port is 6443 → password is kubectx43 → but the answer is kubectx99


Key Commands
Command Purpose
kubectl config view Show merged kubeconfig
kubectl config get-contexts List all contexts
kubectl config current-context Show active context
kubectl config use-context CTX Switch context
kubectl config set-context CTX --namespace=NS Modify context
cat ~/.kube/config View raw kubeconfig
kubectl config view -o jsonpath='{.clusters[*].name}' List cluster names

How kubeconfig Works
# kubeconfig structure has 3 main sections:
# 1. clusters: API server endpoints + CA certificates
# 2. users: Authentication credentials (certs, tokens, etc.)
# 3. contexts: Binds a cluster + user + optional namespace

# View the full config
kubectl config view

# View config as raw YAML
cat ~/.kube/config

# Extract specific fields with jsonpath
kubectl config view -o jsonpath='{.clusters[0].cluster.server}'
kubectl config view -o jsonpath='{.contexts[*].name}'
kubectl config view -o jsonpath='{.users[*].name}'

# Create a new context
kubectl config set-context my-context \
  --cluster=kind-escape-room \
  --user=kind-escape-room \
  --namespace=production

# Switch between contexts
kubectl config use-context kind-escape-room
kubectl config use-context my-context

# Set default namespace for current context
kubectl config set-context --current --namespace=kube-system

# Merge multiple kubeconfig files
export KUBECONFIG=~/.kube/config:~/.kube/config-prod
kubectl config view --flatten > merged-config

Hints

Hint 1

View your kubeconfig and look at the server URL:

kubectl config view

Hint 2

Extract the server port:

kubectl config view -o jsonpath='{.clusters[0].cluster.server}'

Hint 3

The password is kubectx99.


🔓 Unlock Room 06

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_06/README             \
        -out ../room_06/README.txt        \
        -pass pass:PASSWORD
cat ../room_06/README.txt