Kubernetes Shortcuts


Common kubectl alias

alias k=kubectl
alias kns="kubectl config set-context --current --namespace"
alias kdr="kubectl --dry-run=client -o yaml"

Tools for Multiple Kubernetes clusters management

k9s

  • A terminal-based UI to interact with your Kubernetes clusters.
  • Installation brew install derailed/k9s/k9s

kubecm

  • Faster kubeconfig context and namespace switching.
  • Enable merging of multiple kubeconfig files.
  • Installation. brew install kubecm

Useful k8s commands

Get all deployment image version

❯  kubectl get deployments -o=jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{range .spec.template.spec.containers[*]}{.image}{"\n"}{end}{end}'

monitoring	kube-prom-stack-grafana	quay.io/kiwigrid/k8s-sidecar:1.30.0 quay.io/kiwigrid/k8s-sidecar:1.30.0 docker.io/grafana/grafana:11.6.0
monitoring	kube-prom-stack-grafana-image-renderer	docker.io/grafana/grafana-image-renderer:v4.0.11
monitoring	kube-prom-stack-kube-prome-operator	quay.io/prometheus-operator/prometheus-operator:v0.81.0
monitoring	kube-prom-stack-kube-state-metrics	registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.15.0
monitoring	loki-gateway	docker.io/nginxinc/nginx-unprivileged:1.27-alpine

Network Debugging pod

Creating a temporary netshoot pod for network troubleshooting

kubectl run netshoot --rm -i --tty --image nicolaka/netshoot

Get decode secret

Get and decode kubernetes secret values

❯ kubectl get secret secret -o json | jq -r '.data | map_values(@base64d)'

{
  "PAPERLESS_CSRF_TRUSTED_ORIGINS": "********",
  "PAPERLESS_DBENGINE": "********",
  "PAPERLESS_DBHOST": "********",
  "PAPERLESS_DBNAME": "********",
  "PAPERLESS_DBPASS": "********",
}



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Don’t Repeat Yourself with YAML anchor
  • Monitor SNMP ด้วย CloudProxy-vROps
  • การสร้าง Root HTTPProxy บน Contour
  • Crontab but Kubernetes
  • Automate your Proxmox with Packer