--- assignees: - bgrant0607 - erictune - krousey - clove title: kubectl Cheat Sheet --- See also: [Kubectl Overview](/docs/user-guide/kubectl-overview/) and [JsonPath Guide](/docs/user-guide/jsonpath). ## Kubectl Autocomplete ```console $ source <(kubectl completion bash) # setup autocomplete in bash $ source <(kubectl completion zsh) # setup autocomplete in zsh ``` ## Kubectl Context and Configuration Set which Kubernetes cluster `kubectl` communicates with and modify configuration information. See [kubeconfig file](/docs/user-guide/kubeconfig-file/) documentation for detailed config file information. ```console $ kubectl config view # Show Merged kubeconfig settings. # use multiple kubeconfig files at the same time and view merged config $ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view # Get the password for the e2e user $ kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}' $ kubectl config current-context # Display the current-context $ kubectl config use-context my-cluster-name # set the default context to my-cluster-name # add a new cluster to your kubeconf that supports basic auth $ kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword # set a context utilizing a specific username and namespace. $ kubectl config set-context gce --user=cluster-admin --namespace=foo \ && kubectl config use-context gce ``` ## Creating Objects Kubernetes manifests can be defined in json or yaml. The file extension `.yaml`, `.yml`, and `.json` can be used. ```console $ kubectl create -f ./my-manifest.yaml # create resource(s) $ kubectl create -f ./my1.yaml -f ./my2.yaml # create from multiple files $ kubectl create -f ./dir # create resource(s) in all manifest files in dir $ kubectl create -f https://git.io/vPieo # create resource(s) from url $ kubectl run nginx --image=nginx # start a single instance of nginx $ kubectl explain pods,svc # get the documentation for pod and svc manifests # Create multiple YAML objects from stdin $ cat <` | Print a table using a comma separated list of custom columns `-o=custom-columns-file=` | Print a table using the custom columns template in the `` file `-o=json` | Output a JSON formatted API object `-o=jsonpath=