πŸ”₯ K9s Cheat Sheet – The Ultimate Guide

Posted February 11, 2025
Are using k9s terminal UI for managing Kubernetes clusters? Dive and master a K9s Cheat Sheet

Are using K9s terminal UI for managing Kubernetes clusters? Dive and master a K9s Cheat Sheet.

If you wanna navigate faster, troubleshoot, and control your cluster like a pro, this guide’s Cheat Sheet got you covered.


πŸš€ 1. Starting k9s

Command Description
k9s Launch k9s using the default kubeconfig
k9s -n <namespace> Start k9s in a specific namespace
k9s --context <context> Start k9s with a specific cluster context
k9s --kubeconfig <path> Use a different kubeconfig file
k9s --readonly Run k9s in read-only mode (no changes allowed)

🎯 2. Navigation Shortcuts

Key Action
: Enter command mode
/ Filter resources (by name or label)
Esc Clear filters or exit a view
Ctrl + A Toggle between current namespace & all namespaces
Tab Switch between views (YAML, logs, etc.)
Ctrl + C Exit k9s

🌎 3. Switching Namespaces & Clusters

Command Description
:ns Show and switch namespaces
0 List available cluster contexts and switch
:ctx Show current cluster contexts
:context <name> Switch to a different cluster context
kubectl config use-context <context> Change cluster before launching k9s

Related: K9s for K3s Kubernetes Cluster

πŸ“Œ 4. Viewing & Managing Kubernetes Resources

Command Description
:pods Show all Pods
:deploy Show all Deployments
:svc List all Services
:ing Show all Ingresses
:nodes Show all Nodes
:cm Show ConfigMaps
:sec Show Secrets
:jobs Show Jobs

πŸ”Ή Sorting & Filtering

Key Action
Shift + i Sort by CPU usage
Shift + o Sort by Memory usage
Shift + p Sort by Pod restarts

πŸ› 5. Debugging & Logs

Key Action
l View logs of selected Pod
Shift + l View logs of a specific container inside a Pod
Ctrl + f Search logs
Shift + f Toggle log auto-scroll
Ctrl + s Save logs to a file

πŸ”Ή Follow logs in real-time (CLI)

kubectl logs -f <pod-name>

πŸ› οΈ 6. Executing Commands in a Pod

Key Description
Shift + x Open a shell inside a running Pod

πŸ”Ή Manually via CLI

kubectl exec -it <pod-name> -- /bin/sh

For Debian/Ubuntu:

kubectl exec -it <pod-name> -- /bin/bash

For Alpine-based containers:

kubectl exec -it <pod-name> -- /bin/ash

For Debian/Ubuntu:

kubectl exec -it <pod-name> -- /bin/bash

πŸ”„ 7. Restarting & Scaling Pod Resources

Key Description
r Restart a Pod
Shift + r Restart multiple selected Pods
:scale <deployment> <replicas> Scale a Deployment up/down

Example:

:scale my-app-deployment 5

🌐 8. Port Forwarding

Key Description
Shift + f Port-forward a Pod

πŸ”Ή Manually via CLI

kubectl port-forward <pod-name> 8080:80

For a Service:

kubectl port-forward svc/<service-name> 9090:80

πŸ”‘ 9. Managing Secrets & ConfigMaps

Command Description
:sec Show all Secrets
:cm Show all ConfigMaps

πŸ”Ή Decode a Secret (CLI)

kubectl get secret <secret-name> -o jsonpath="{.data.<key-name>}" | base64 --decode

πŸ“Š 10. Checking Node Health Status & Metrics

Key Description
:nodes Show all Nodes
Shift + m Show node metrics (CPU, memory)

πŸ”ΉManually via CLI

kubectl get nodes -o wide
kubectl describe node <node-name>

🎨 11. Switching k9s UI Themes

Change k9s theme by editing the config:

nano ~/.k9s/config.yaml

Add or update:

k9s:
  ui:
    skin: <dark|light|custom>

πŸ”’ 12. Running k9s in Safe Mode

Wanna make sure nothing gets messed up? Run in read-only mode to prevent accidental changes:

k9s --readonly

πŸ“‚ 13. Handling Multiple Kubeconfig File

If you’re juggling multiple kubeconfig files, merge them:

KUBECONFIG=/path1/config:/path2/config kubectl config view --merge --flatten > ~/.kube/config

❌ 14. Quitting k9s

Key Description
Ctrl + C Quit k9s
:q or :quit Quit k9s

🎯 Wrapping up!

And that’s it! Now you’re a k9s ninja with a complete K9s Cheat Sheet! If you need more details, hit me up! πŸ˜ŽπŸš€

πŸ”₯ K9s Cheat Sheet – The Ultimate Guide

Written By:

Joseph Chege