# kubectl `kubectl` is used to interact with Kubernetes clusters via the CLI. ## Setup Add the following to your `.bashrc` to benefit from the really good auto-completion in kubectl ```bash ### Kubectl alias k='kubectl' source /etc/bash_completion # not needed on macos and Bluefin source <(kubectl completion bash) complete -o default -F __start_kubectl k # "k" with autocompletion ``` Also shorten the command to `k` via the `.bashrc` ```bash alias k=kubectl ``` ## Config The main config file on the local machine is located at `$HOME/.kube/config` and contains information about the clusters you connected to (e.g. certificates). ## Common usage ### Help - `kubectl -h` or for example `kubectl run -h` to display documentation - `kubectl explain <OPTION>` to display extensive documentation ### Contexts - `kubectl config current-context` to check in which context your are right now - `kubectl config use context <CLUSTER-NAME>` to switch to another context ### Namespaces - `kubectl get namespaces` to check available namespaces ### Pods - `kubectl get pod` to list all pods in the current namespace - `kubectl get pods --all-namespaces` to list pods in all namespaces - `kubectl run image` --- ## Related - **previous** [[Kubernetes]] - **see** none ## Sources - **references** [kubectl Quick Reference](https://kubernetes.io/docs/reference/kubectl/quick-reference/) as the documentation for the command ## Usage - **used in** none