Member-only story
AhmetB started an excellent thread yesterday where he asked people to share a Kubernetes CLI (kubectl) tip that they think a lot of users don’t know about.
There are so many excellent tips I decide to collect the most interesting ones in a single post. The first thing that I typically do when I am on a new machine is to set the alias for kubectl
:
alias k=kubectl
If you’re working with Kubernetes, you’ll be typing kubectl
a lot, so why not make it shorter.
Enjoy the tips below and let us know if you have any other tips you want to share. Here are all the tips in no particular order.
1. Set up load-based horizontal pod autoscaling on your Kubernetes resources
By @pixie_run
kubectl autoscale deployment foo --min=2 --max=10
2. Create a new job from a cronjob
By @mauilion
kubectl create job --from=cronjob/<name of cronjob> <name of this run>
3. Enumerate permissions for a given service account
By @mauilion
kubectl -n <namespace> auth can-i --list --as system:serviceaccount:<namespace>:<service account name>
4. Annotate resources
By @hikvar
# To add annotation
kubectl annotate <resource-type>/<resource-name> foo=bar# To remove annotation
kubectl annotate <resource-type>/<resource-name> foo-
5. Get a list of endpoints across all namespaces
By @ivnrcki
kubectl get ep -A
6. Get a list of events sorted by lastTimestamp
By RewssPozzi
kubectl get events --sort-by=".lastTimestamp"
7. Watch all warnings across the namespaces
By @LachlanEvenson and @jpetazzo
kubectl get events -w --field-selector=type=Warning -A