Skip to content

Instantly share code, notes, and snippets.

@mhausenblas
Last active January 11, 2018 20:45
Show Gist options
  • Save mhausenblas/c89d09e656f740128d406321de1d553d to your computer and use it in GitHub Desktop.
Save mhausenblas/c89d09e656f740128d406321de1d553d to your computer and use it in GitHub Desktop.
My favs kubectl commands

Docs and config

What was that field in the manifest again?

$ kubectl explain statefulset.spec.template.spec

List contexts:

$ kubectl config get-contexts

Workloads

Simple jump pod:

$ kubectl run -i -t --rm jump --image=quay.io/mhausenblas/jump:v0.1 -- sh

Name of pod(s) labelled with app=example:

$ kubectl get po -l=app=example -o=custom-columns=:metadata.name --no-headers

RBAC

Can a certain SA list pods?

$ kubectl auth can-i list pods --as=system:serviceaccount:sec:myappsa

Create rolebinding for an SA in a specified namespace and just do a dry run:

$ kubectl create rolebinding podreaderbinding --role=sec:podreader --serviceaccount=sec:myappsa --namespace=sec --dry-run=true -o=yaml -n=sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment