Skip to content

Kubernetes: Productivity: aliases, contexts & output

11 Kubernetes commands: Productivity: aliases, contexts & output. Click a command to see what each part does.

Index
11 items
Click a command to see what each part does.

Productivity: aliases, contexts & output11

  • alias k=kubectl; source <(kubectl completion bash); complete -o default -F __start_kubectl kShort alias with completion (bash)

    What each part does

    1. alias k=kubectltype k get po instead of kubectl get pods
    2. kubectl completion bashtab completion for resources and names (zsh: completion zsh)
    3. complete ... kmake completion work for the alias too

    Tip PowerShell: Set-Alias -Name k -Value kubectl. Put these in ~/.bashrc to keep them.

  • kubectl config get-clusters; kubectl config get-usersList clusters and users in kubeconfig

    What each part does

    1. get-clusterscluster entries
    2. get-userscredential entries
  • kubectl config view --minifyShow the current context's config only

    What each part does

    1. config viewkubeconfig contents (secrets redacted)
    2. --minifyonly what the current context uses
  • KUBECONFIG=~/.kube/config:<other-config> kubectl config view --flatten > merged-configMerge several kubeconfig files

    What each part does

    1. KUBECONFIG=a:bcolon-separated list of files kubectl reads together
    2. view --flattenone self-contained file
  • kubectl config delete-context <context>Remove a context

    What each part does

    1. delete-contextremove it from kubeconfig (cluster and user entries stay)
  • kubectx <context>; kubens <namespace>Switch context / namespace quickly

    What each part does

    1. kubectxswitch context (plugin)
    2. kubensswitch default namespace
  • kubectl explain pod.spec.containers --recursive | lessExplain every field of a resource

    What each part does

    1. explain <path>docs for a field
    2. --recursivethe whole tree of sub-fields
  • kubectl get po -A --sort-by=.metadata.creationTimestampSort output

    What each part does

    1. --sort-by=<jsonpath>sort by any field: creation time, .status.startTime, restartCount...
  • kubectl plugin list; kubectl krew listList kubectl plugins

    What each part does

    1. plugin listkubectl-* binaries on your PATH
    2. krew listplugins installed with the krew plugin manager
  • kubectl attach -it <pod> -c <container>Attach to a running container

    What each part does

    1. attachconnect to the main process's stdin/stdout (exec starts a new process instead)
  • kubectl get po -v=6Show more detail about what kubectl does

    What each part does

    1. -v=6log the API calls kubectl makes (8 includes bodies): useful for auth and timeout problems

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…