Image credit: unsplash.com

Abbreviations

  • po — pods, pod

Setting up alias and autocompletion with alias

alias k=kubectl

source <(kubectl completion bash | sed ‘s/kubectl/k/g’)

View current context

kubectl config current-context

Core Concepts

Set image of pod nginx : image name is nginx and correct value is nginx

k set image po nginx nginx=nginx

Force delete a pod

K delete po nains -n mynamespace — grace-period=0 — force

Verbosity level of information: level — v=0 till — v=9

k get po nginxtag — v=9

Get custom columns in pod summary. Notation is similar to jsonpath notation. File can also be used with custom-columns-file

kubectl get po -o=custom-columns=”POD_NAME:.metadata.name, POD_STATUS:.status.containerStatuses[].state”

Get pod field details using jsonpath notation. File can also be used with jsonpath-file

K get po -o=jsonpath=“$.spec.containers[].name”

Sort pod summary by name

k get po — sort-by=”{.metadata.name}”

Sort pod summary by timestamp

k get po — sort-by=.metadata.creationTimestamp

Logging and Debugging

Get log dump of a pod

k logs

Tail logs of a pod or follow logs

k logs -f

Get logs of a container in multi container pod

k logs -c

Get previous logs of a container

k logs -c — p

Node and pod meterics. Below commands only run if metric server is installed.

k top po nginx — containers k…

Sumit Sachdeva

I got to where I am today by being me.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store