Kubernetes

Kubernetes and Helm.

File aliases/k8s.sh. Disable: export ALIASX_DISABLE="k8s"

kubectl

NameRunsWhat it does
kkubectlkubectlneeds kubectl
kgkubectl getget resourcesneeds kubectl
kdkubectl describedescribe resourceneeds kubectl
kakubectl apply -fapply manifest fileneeds kubectl
kekubectl editedit resourceneeds kubectl
kdiffkubectl diff -fdiff manifest against clusterneeds kubectl

Resources

NameRunsWhat it does
kgpkubectl get podspodsneeds kubectl
kgpakubectl get pods --all-namespacespods, all namespacesneeds kubectl
kgpwkubectl get pods --watchwatch podsneeds kubectl
kgdkubectl get deploymentsdeploymentsneeds kubectl
kgskubectl get servicesservicesneeds kubectl
kgikubectl get ingressingressesneeds kubectl
kgnkubectl get nodesnodesneeds kubectl
kgnskubectl get namespacesnamespacesneeds kubectl
kgcmkubectl get configmapsconfigmapsneeds kubectl
kdpkubectl describe poddescribe podneeds kubectl
kddkubectl describe deploymentdescribe deploymentneeds kubectl
kevkubectl get events --sort-by=.metadata.creationTimestampevents, oldest firstneeds kubectl

Logs and debugging

NameRunsWhat it does
klkubectl logspod logsneeds kubectl
klfkubectl logs --follow --tail=200follow last 200 pod log linesneeds kubectl
kexeckubectl exec -itexec into podneeds kubectl
ktopnkubectl top nodesnode CPU and memoryneeds kubectl
ktoppkubectl top podspod CPU and memoryneeds kubectl

Context and namespace

NameRunsWhat it does
kctxkubectl config current-contextcurrent contextneeds kubectl
kctxskubectl config get-contextsall contextsneeds kubectl
knskubectl config view --minify --output "jsonpath={..namespace}"current namespaceneeds kubectl

Rollout

NameRunsWhat it does
krollkubectl rollout statusrollout statusneeds kubectl
krestartkubectl rollout restartrestart rolloutneeds kubectl
khistorykubectl rollout historyrollout historyneeds kubectl

Troubleshooting

NameRunsWhat it does
kbadkubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeededpods not runningneeds kubectl
kimageskubectl get pods -A -o jsonpath="{..image}" | tr " " "\n" | sort | uniq -cimages in useneeds kubectl
kgallkubectl get alleverything in namespaceneeds kubectl
ksecret NAME KEYprint decoded value of one secret key
example
$ ksecret db-creds password
s3cret
needs kubectl
kshell PODshell into pod (sh)
example
$ kshell api-7d9f8b-x2k4
/app $
needs kubectl
krun [IMAGE]throwaway debug pod, removed on exit (default busybox)
example
$ krun
If you don't see a command prompt, try pressing enter.
/ #
needs kubectl
kuse CONTEXTswitch kubectl context
example
$ kuse prod
Switched to context "prod".
needs kubectl
knamespace NSset namespace for current context
example
$ knamespace payments
Context "prod" modified.
needs kubectl
kpf RESOURCE LOCAL:REMOTEport-forward
example
$ kpf svc/api 8080:80
Forwarding from 127.0.0.1:8080 -> 80
needs kubectl
kdebug POD [IMAGE]attach debug container (default busybox)
example
$ kdebug api-7d9f8b-x2k4
Defaulting debug container name to debugger-x7k2.
/ #
needs kubectl

Helm (prefix hm; h is history)

NameRunsWhat it does
hmhelmhelmneeds helm
hmlshelm listreleasesneeds helm
hmlsahelm list --all-namespacesreleases, all namespacesneeds helm
hmrepohelm repo listchart repositoriesneeds helm
hmrepouhelm repo updateupdate chart repositoriesneeds helm
hmsearchhelm search reposearch chartsneeds helm
hmstatushelm statusrelease statusneeds helm
hmhistoryhelm historyrelease historyneeds helm
hmtemplatehelm templaterender chart locallyneeds helm
hmlinthelm lintlint chartneeds helm