Essential Linux Commands for Kubernetes Practitioners
March 31, 2025
Essential Linux Commands for Kubernetes Practitioners
When working with Kubernetes, you'll often need to manipulate files, inspect logs, or debug containers using Linux commands. Here are the most frequently used ones I've encountered:
1. File Navigation & Inspection
pwd
- Know Where You Are
pwd
# Output: /home/user/k8s-configs
ls
- List Files Like a Pro
ls -lha /etc/kubernetes/ # Check Kubernetes config files
# -l = long format, -h = human-readable, -a = show hidden
find
- Locate Files Quickly
find /var/log -name "*.log" -mtime -7 # Find recent logs
2. File Manipulation
cat
/less
- View File Contents
cat deployment.yaml # Quick view
less /var/log/syslog # Paginated view (press 'q' to quit)
grep
- The Search Ninja
grep -r "image:" ./k8s/ # Find all container images in YAMLs
grep -i "error" /var/log/containers/* # Case-insensitive error search
jq
- JSON Wizardry (for K8s API responses)
kubectl get pods -o json | jq '.items[].metadata.name'
3. File Operations
curl
- API & File Downloads
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
tar
- Handle Archives
tar -xzvf helm-v3.12.0-linux-amd64.tar.gz # Extract Helm
diff
- Compare Files
diff -u old-deployment.yaml new-deployment.yaml
4. System & Process Management
ps
- Process Inspection
ps aux | grep kubelet # Check if kubelet is running
top
/htop
- Resource Monitoring
htop # Interactive process viewer (install with `apt install htop`)
5. Networking
netstat
/ss
- Port Checking
ss -tulnp | grep 6443 # Check if Kubernetes API port is open
dig
/nslookup
- DNS Debugging
dig +short my-svc.default.svc.cluster.local # Debug K8s DNS
6. Permission Management
chmod
- Make Scripts Executable
chmod +x install-k8s-tools.sh
sudo
- When You Need Superpowers
sudo systemctl restart kubelet # Requires root
Practical Examples
1. Base64 for Kubernetes Secrets
# Encode
echo -n "secret-data" | base64
# Decode
echo "c2VjcmV0LWRhdGE=" | base64 --decode
2. Bulk Rename K8s Configs
for file in *.yaml; do mv "$file" "k8s-$file"; done
3. Count Running Pods from Logs
kubectl get pods | grep Running | wc -l
Pro Tips
-
Chain commands with
|
(pipe):cat /var/log/pods/* | grep "OOMKilled" | wc -l
-
Redirect outputs:
kubectl describe node > node-details.txt 2>&1
-
Use
watch
for real-time monitoring:watch -n 2 'kubectl get pods | grep Pending'
Key Takeaway: Kubernetes runs on Linux. Mastering these commands will make you 10x more effective at debugging and automation.