diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index e17919040c..5d313fa6da 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -5,15 +5,35 @@ reviewers: - erictune - krousey - clove +content_template: templates/concept --- +{{% capture overview %}} + See also: [Kubectl Overview](/docs/reference/kubectl/overview/) and [JsonPath Guide](/docs/reference/kubectl/jsonpath). +This page is an overview of the `kubectl` command. + +{{% /capture %}} + +{{% capture body %}} + +# kubectl - Cheat Sheet + ## Kubectl Autocomplete -```console -$ source <(kubectl completion bash) # setup autocomplete in bash, bash-completion package should be installed first. -$ source <(kubectl completion zsh) # setup autocomplete in zsh +### BASH + +```bash +source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first. +echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell. +``` + +### ZSH + +```bash +source <(kubectl completion zsh) # setup autocomplete in zsh into the current shell +echo "if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi" >> ~/.zshrc # add autocomplete permanently to your zsh shell ``` ## Kubectl Context and Configuration @@ -22,23 +42,23 @@ Set which Kubernetes cluster `kubectl` communicates with and modifies configurat information. See [Authenticating Across Clusters with kubeconfig](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) documentation for detailed config file information. -```console -$ kubectl config view # Show Merged kubeconfig settings. +```bash +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 +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 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 +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 +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 set-context gce --user=cluster-admin --namespace=foo \ && kubectl config use-context gce ``` @@ -47,16 +67,16 @@ $ kubectl config set-context gce --user=cluster-admin --namespace=foo \ 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 +```bash +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 <