Helpful K8s Commands

Tyler Kron
sipsak
Published in
1 min readJul 21, 2019

I have IBBS (itty-bitty-brain-syndrome), so this article is written selfishly for myself to reference kubernetes commands that I find helpful. It will be added to as I find more and more useful commands.

Photo by Marek Levák on Unsplash

Forward a port from a pod to your local machine

The command below forwards port 80on the pod pact-broker-5cdc98cc4b-jgfzf to port 9000 locally on your machine.

kubectl port-forward pact-broker-5cdc98cc4b-jgfzf 9000:80

Decoding Secrets

  1. First, view the secrets (these are base64 encoded)
kubectl get secrets

2. Decode the secret so it is human readable

kubectl get secret <secret-name> -o yaml
Echo '<secret-value>' | base64 --decode | pbcopy

Easily switch between clusters and namespaces

This can get real monotonous real quick. Luckily there are tools that make this a breeze.

Simply install both (on Mac) by running the following command

brew install kubectx fzf

Now you can switch k8s cluster simply by the command kubectx and switch namespaces with the command kubens

View secrets

kubectl get secret [SECRET NAME] -o go-template='
{{range $k,$v := .data}}{{printf "%s: " $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}'

Resources

--

--

Tyler Kron
sipsak
Editor for

Husband, Software Engineer, Entrepreneur, Broncos and Nuggets fan