11 tricks to improve your productivity and reduce your frustration with kubernetes
Abstract
- Run a local cluster.
- Running a local cluster with multiple nodes.
- Why: test taints, tolerations, node affinity, DaemonSet, node failures and failover.
- Waiting for that cluster to be ready.
- Switch between namespaces or clusters: use
kubectx
andkubens
- You can add an alias like
kns
andkctx
for shorter commands.- You can use fzf for extra convenience.
kns -
switches back to the previous namespace.
- Waiting for a Deployment to be ready.
- Waiting for a Service to be ready.
- Waiting for a Loadbalancer to be ready.
kubectl wait
default timeout is 30s. Can be changed to:
0
: check once and report status,- negative value (wait 1 week).
kubectl wait --for=delete
also possible.- We can also use kapp:
kapp deploy -a hello -f hello.yaml
kapp
will apply the manifests- wait for resources to be “up”
- record what it did (so we can delete/rollback later, helm-style)
- Better
kubectl--watch
- Use k9s.
- Use kubecolor.
- Documentation right from the CLI
kubectl
patch all the things.
kubectl set {image,serviceaccount,resources,env...}
kubectl get nodes --label-columns kubenertes.io/arch,node.kubernetes.io/instance-type
- Check which controllers own our pod.
- List the permissions we have.
- Turn a Deployment off and on again:
kubectl rollout restart deployment hello
- Useful if you want to fix some bug, so you don’t want any Pod from this Deployment, but you don’t want to re-create the Deployment afterwards.
- Also useful to turn off stuff that’s not in use to save cost.
- Check cluster resource usage:
kubectl view-allocations -u -r memory -r cpu -g node
- Get an image with almost any tool you want:
docker run -it nixery.dev/shell/kubectl/curl/jq
terminationMessagePath
+terminationMessagePolicy
Reviews
Why did I want to read/watch this? At my company, there’s a project to migrate to kubernetes, so I had to re-dive into kubernetes. Thus, I was quite eager to know more tips about kubernetes.
What did I get out of it? Nice tips, really useful for sysadmins. One I particularly like is using
gron
for making JSON grepable andnixery.dev
for generating a docker image with the needed tools.