{"id":7496,"date":"2021-01-02T09:51:17","date_gmt":"2021-01-02T08:51:17","guid":{"rendered":"https:\/\/blog.via-internet.de\/?p=7496"},"modified":"2021-01-02T09:51:17","modified_gmt":"2021-01-02T08:51:17","slug":"kubernetes-cheat-sheet","status":"publish","type":"post","link":"https:\/\/via-internet.de\/blog\/2021\/01\/02\/kubernetes-cheat-sheet\/","title":{"rendered":"Kubernetes | Cheat Sheet"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Readings<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/talos-systems\/talos\">https:\/\/github.com\/talos-systems\/talos<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"kubectl-autocomplete\">Kubectl autocomplete<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#kubectl-autocomplete\"><\/a><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bash\">BASH<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">source &lt; (kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.\necho \"source &lt;(kubectl completion bash)\" >> ~\/.bashrc<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"bash\"><a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#bash\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use a shorthand alias for&nbsp;<code>kubectl<\/code>&nbsp;that also works with completion:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">alias k=kubectl\ncomplete -F __start_kubectl k\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"zsh\">ZSH<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#zsh\"><\/a><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">source &lt;(kubectl completion zsh)  # setup autocomplete in zsh into the current shell\necho \"[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)\" >> ~\/.zshrc # add autocomplete permanently to your zsh shell\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"kubectl-context-and-configuration\">Kubectl context and configuration<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#kubectl-context-and-configuration\"><\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Set which Kubernetes cluster&nbsp;<code>kubectl<\/code>&nbsp;communicates with and modifies configuration information. See&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/tasks\/access-application-cluster\/configure-access-multiple-clusters\/\">Authenticating Across Clusters with kubeconfig<\/a>&nbsp;documentation for detailed config file information.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl config view # Show Merged kubeconfig settings.\n# use multiple kubeconfig files at the same time and view merged config\nKUBECONFIG=~\/.kube\/config:~\/.kube\/kubconfig2 \nkubectl config view\n# get the password for the e2e user\nkubectl config view -o jsonpath='{.users[?(@.name == \"e2e\")].user.password}'\nkubectl config view -o jsonpath='{.users[].name}'    # display the first user\nkubectl config view -o jsonpath='{.users[*].name}'   # get a list of users\nkubectl config get-contexts                          # display list of contexts \nkubectl config current-context                       # display the current-context\nkubectl config use-context my-cluster-name           # set the default context to my-cluster-name\n# add a new user to your kubeconf that supports basic auth\nkubectl config set-credentials kubeuser\/foo.kubernetes.com --username=kubeuser --password=kubepassword\n# permanently save the namespace for all subsequent kubectl commands in that context.\nkubectl config set-context --current --namespace=ggckad-s2\n# set a context utilizing a specific username and namespace.\nkubectl config set-context gce --user=cluster-admin --namespace=foo \n  &amp;&amp; kubectl config use-context gce\nkubectl config unset users.foo                       # delete user foo\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"kubectl-apply\">Kubectl apply<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#kubectl-apply\"><\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>apply<\/code>&nbsp;manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running&nbsp;<code>kubectl apply<\/code>. This is the recommended way of managing Kubernetes applications on production. See&nbsp;<a href=\"https:\/\/kubectl.docs.kubernetes.io\/\">Kubectl Book<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-objects\">Creating objects<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#creating-objects\"><\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes manifests can be defined in YAML or JSON. The file extension&nbsp;<code>.yaml<\/code>,&nbsp;<code>.yml<\/code>, and&nbsp;<code>.json<\/code>&nbsp;can be used.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f .\/my-manifest.yaml            # create resource(s)\nkubectl apply -f .\/my1.yaml -f .\/my2.yaml      # create from multiple files\nkubectl apply -f .\/dir                         # create resource(s) in all manifest files in dir\nkubectl apply -f https:\/\/git.io\/vPieo          # create resource(s) from url\nkubectl create deployment nginx --image=nginx  # start a single instance of nginx\n# create a Job which prints \"Hello World\"\nkubectl create job hello --image=busybox -- echo \"Hello World\" \n# create a CronJob that prints \"Hello World\" every minute\nkubectl create cronjob hello --image=busybox   --schedule=\"*\/1 * * * *\" -- echo \"Hello World\"    \nkubectl explain pods                           # get the documentation for pod manifests\n# Create multiple YAML objects from stdin\ncat &lt;&lt;EOF | kubectl apply -f -\napiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox-sleep\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    args:\n    - sleep\n    - \"1000000\"\n---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox-sleep-less\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    args:\n    - sleep\n    - \"1000\"\nEOF\n# Create a secret with several keys\ncat &lt;&lt;EOF | kubectl apply -f -\napiVersion: v1\nkind: Secret\nmetadata:\n  name: mysecret\ntype: Opaque\ndata:\n  password: $(echo -n \"s33msi4\" | base64 -w0)\n  username: $(echo -n \"jane\" | base64 -w0)\nEOF\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"viewing-finding-resources\">Viewing, finding resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#viewing-finding-resources\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Get commands with basic output\nkubectl get services                          # List all services in the namespace\nkubectl get pods --all-namespaces             # List all pods in all namespaces\nkubectl get pods -o wide                      # List all pods in the current namespace, with more details\nkubectl get deployment my-dep                 # List a particular deployment\nkubectl get pods                              # List all pods in the namespace\nkubectl get pod my-pod -o yaml                # Get a pod's YAML\n# Describe commands with verbose output\nkubectl describe nodes my-node\nkubectl describe pods my-pod\n# List Services Sorted by Name\nkubectl get services --sort-by=.metadata.name\n# List pods Sorted by Restart Count\nkubectl get pods --sort-by='.status.containerStatuses[0].restartCount'\n# List PersistentVolumes sorted by capacity\nkubectl get pv --sort-by=.spec.capacity.storage\n# Get the version label of all pods with label app=cassandra\nkubectl get pods --selector=app=cassandra -o \n  jsonpath='{.items[*].metadata.labels.version}'\n# Retrieve the value of a key with dots, e.g. 'ca.crt'\nkubectl get configmap myconfig \n  -o jsonpath='{.data.ca.crt}'\n# Get all worker nodes (use a selector to exclude results that have a label\n# named 'node-role.kubernetes.io\/master')\nkubectl get node --selector='!node-role.kubernetes.io\/master'\n# Get all running pods in the namespace\nkubectl get pods --field-selector=status.phase=Running\n# Get ExternalIPs of all nodes\nkubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type==\"ExternalIP\")].address}'\n# List Names of Pods that belong to Particular RC\n# \"jq\" command useful for transformations that are too complex for jsonpath, it can be found at https:\/\/stedolan.github.io\/jq\/\nsel=${$(kubectl get rc my-rc --output=json | jq -j '.spec.selector | to_entries | .[] | \"(.key)=(.value),\"')\necho $(kubectl get pods --selector=$sel --output=jsonpath={.items..metadata.name})\n# Show labels for all pods (or any other Kubernetes object that supports labelling)\nkubectl get pods --show-labels\n# Check which nodes are ready\nJSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \n &amp;&amp; kubectl get nodes -o jsonpath=\"$JSONPATH\" | grep \"Ready=True\"\n# List all Secrets currently in use by a pod\nkubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq\n# List all containerIDs of initContainer of all pods\n# Helpful when cleaning up stopped containers, while avoiding removal of initContainers.\nkubectl get pods --all-namespaces -o jsonpath='{range .items[*].status.initContainerStatuses[*]}{.containerID}{\"n\"}{end}' | cut -d\/ -f3\n# List Events sorted by timestamp\nkubectl get events --sort-by=.metadata.creationTimestamp\n# Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.\nkubectl diff -f .\/my-manifest.yaml\n# Produce a period-delimited tree of all keys returned for nodes\n# Helpful when locating a key within a complex nested JSON structure\nkubectl get nodes -o json | jq -c 'path(..)|[.[]|tostring]|join(\".\")'\n# Produce a period-delimited tree of all keys returned for pods, etc\nkubectl get pods -o json | jq -c 'path(..)|[.[]|tostring]|join(\".\")'\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"updating-resources\">Updating resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#updating-resources\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl set image deployment\/frontend www=image:v2               # Rolling update \"www\" containers of \"frontend\" deployment, updating the image\nkubectl rollout history deployment\/frontend                      # Check the history of deployments including the revision \nkubectl rollout undo deployment\/frontend                         # Rollback to the previous deployment\nkubectl rollout undo deployment\/frontend --to-revision=2         # Rollback to a specific revision\nkubectl rollout status -w deployment\/frontend                    # Watch rolling update status of \"frontend\" deployment until completion\nkubectl rollout restart deployment\/frontend                      # Rolling restart of the \"frontend\" deployment\ncat pod.json | kubectl replace -f -                              # Replace a pod based on the JSON passed into std\n# Force replace, delete and then re-create the resource. Will cause a service outage.\nkubectl replace --force -f .\/pod.json\n# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000\nkubectl expose rc nginx --port=80 --target-port=8000\n# Update a single-container pod's image version (tag) to v4\nkubectl get pod mypod -o yaml | sed 's\/(image: myimage):.*$\/1:v4\/' | kubectl replace -f -\nkubectl label pods my-pod new-label=awesome                      # Add a Label\nkubectl annotate pods my-pod icon-url=http:\/\/goo.gl\/XXBTWq       # Add an annotation\nkubectl autoscale deployment foo --min=2 --max=10                # Auto scale a deployment \"foo\"\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"patching-resources\">Patching resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#patching-resources\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Partially update a node\nkubectl patch node k8s-node-1 -p '{\"spec\":{\"unschedulable\":true}}'\n# Update a container's image; spec.containers[*].name is required because it's a merge key\nkubectl patch pod valid-pod -p '{\"spec\":{\"containers\":[{\"name\":\"kubernetes-serve-hostname\",\"image\":\"new image\"}]}}'\n# Update a container's image using a json patch with positional arrays\nkubectl patch pod valid-pod --type='json' -p='[{\"op\": \"replace\", \"path\": \"\/spec\/containers\/0\/image\", \"value\":\"new image\"}]'\n# Disable a deployment livenessProbe using a json patch with positional arrays\nkubectl patch deployment valid-deployment  --type json   -p='[{\"op\": \"remove\", \"path\": \"\/spec\/template\/spec\/containers\/0\/livenessProbe\"}]'\n# Add a new element to a positional array\nkubectl patch sa default --type='json' -p='[{\"op\": \"add\", \"path\": \"\/secrets\/1\", \"value\": {\"name\": \"whatever\" } }]'\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"editing-resources\">Editing resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#editing-resources\"><\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Edit any API resource in your preferred editor.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl edit svc\/docker-registry                      # Edit the service named docker-registry\nKUBE_EDITOR=\"nano\" kubectl edit svc\/docker-registry   # Use an alternative editor\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scaling-resources\">Scaling resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#scaling-resources\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl scale --replicas=3 rs\/foo                                 # Scale a replicaset named 'foo' to 3\nkubectl scale --replicas=3 -f foo.yaml                            # Scale a resource specified in \"foo.yaml\" to 3\nkubectl scale --current-replicas=2 --replicas=3 deployment\/mysql  # If the deployment named mysql's current size is 2, scale mysql to 3\nkubectl scale --replicas=5 rc\/foo rc\/bar rc\/baz                   # Scale multiple replication controllers\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"deleting-resources\">Deleting resources<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#deleting-resources\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl delete -f .\/pod.json                                              # Delete a pod using the type and name specified in pod.json\nkubectl delete pod,service baz foo                                        # Delete pods and services with same names \"baz\" and \"foo\"\nkubectl delete pods,services -l name=myLabel                              # Delete pods and services with label name=myLabel\nkubectl -n my-ns delete pod,svc --all                                      # Delete all pods and services in namespace my-ns,\n# Delete all pods matching the awk pattern1 or pattern2\nkubectl get pods  -n mynamespace --no-headers=true | awk '\/pattern1|pattern2\/{print $1}' | xargs  kubectl delete -n mynamespace pod\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"interacting-with-running-pods\">Interacting with running Pods<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#interacting-with-running-pods\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl logs my-pod                                 # dump pod logs (stdout)\nkubectl logs -l name=myLabel                        # dump pod logs, with label name=myLabel (stdout)\nkubectl logs my-pod --previous                      # dump pod logs (stdout) for a previous instantiation of a container\nkubectl logs my-pod -c my-container                 # dump pod container logs (stdout, multi-container case)\nkubectl logs -l name=myLabel -c my-container        # dump pod logs, with label name=myLabel (stdout)\nkubectl logs my-pod -c my-container --previous      # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container\nkubectl logs -f my-pod                              # stream pod logs (stdout)\nkubectl logs -f my-pod -c my-container              # stream pod container logs (stdout, multi-container case)\nkubectl logs -f -l name=myLabel --all-containers    # stream all pods logs with label name=myLabel (stdout)\nkubectl run -i --tty busybox --image=busybox -- sh  # Run pod as interactive shell\nkubectl run nginx --image=nginx -n \nmynamespace                                         # Run pod nginx in a specific namespace\nkubectl run nginx --image=nginx                     # Run pod nginx and write its spec into a file called pod.yaml\n--dry-run=client -o yaml > pod.yaml\nkubectl attach my-pod -i                            # Attach to Running Container\nkubectl port-forward my-pod 5000:6000               # Listen on port 5000 on the local machine and forward to port 6000 on my-pod\nkubectl exec my-pod -- ls \/                         # Run command in existing pod (1 container case)\nkubectl exec --stdin --tty my-pod -- \/bin\/sh        # Interactive shell access to a running pod (1 container case) \nkubectl exec my-pod -c my-container -- ls \/         # Run command in existing pod (multi-container case)\nkubectl top pod POD_NAME --containers               # Show metrics for a given pod and its containers\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"interacting-with-nodes-and-cluster\">Interacting with Nodes and cluster<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#interacting-with-nodes-and-cluster\"><\/a><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl cordon my-node                                                # Mark my-node as unschedulable\nkubectl drain my-node                                                 # Drain my-node in preparation for maintenance\nkubectl uncordon my-node                                              # Mark my-node as schedulable\nkubectl top node my-node                                              # Show metrics for a given node\nkubectl cluster-info                                                  # Display addresses of the master and services\nkubectl cluster-info dump                                             # Dump current cluster state to stdout\nkubectl cluster-info dump --output-directory=\/path\/to\/cluster-state   # Dump current cluster state to \/path\/to\/cluster-state\n# If a taint with that key and effect already exists, its value is replaced as specified.\nkubectl taint nodes foo dedicated=special-user:NoSchedule\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"resource-types\">Resource types<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#resource-types\"><\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">List all supported resource types along with their shortnames,&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/kubernetes-api\/#api-groups\">API group<\/a>, whether they are&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/working-with-objects\/namespaces\">namespaced<\/a>, and&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/working-with-objects\/kubernetes-objects\">Kind<\/a>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl api-resources\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Other operations for exploring API resources:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl api-resources --namespaced=true      # All namespaced resources\nkubectl api-resources --namespaced=false     # All non-namespaced resources\nkubectl api-resources -o name                # All resources with simple output (just the resource name)\nkubectl api-resources -o wide                # All resources with expanded (aka \"wide\") output\nkubectl api-resources --verbs=list,get       # All resources that support the \"list\" and \"get\" request verbs\nkubectl api-resources --api-group=extensions # All resources in the \"extensions\" API group\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"formatting-output\">Formatting output<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#formatting-output\"><\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To output details to your terminal window in a specific format, add the&nbsp;<code>-o<\/code>&nbsp;(or&nbsp;<code>--output<\/code>) flag to a supported&nbsp;<code>kubectl<\/code>&nbsp;command.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Output format<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>-o=custom-columns=&lt;spec&gt;<\/code><\/td><td>Print a table using a comma separated list of custom columns<\/td><\/tr><tr><td><code>-o=custom-columns-file=&lt;filename&gt;<\/code><\/td><td>Print a table using the custom columns template in the&nbsp;<code>&lt;filename&gt;<\/code>&nbsp;file<\/td><\/tr><tr><td><code>-o=json<\/code><\/td><td>Output a JSON formatted API object<\/td><\/tr><tr><td><code>-o=jsonpath=&lt;template&gt;<\/code><\/td><td>Print the fields defined in a&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/jsonpath\">jsonpath<\/a>&nbsp;expression<\/td><\/tr><tr><td><code>-o=jsonpath-file=&lt;filename&gt;<\/code><\/td><td>Print the fields defined by the&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/jsonpath\">jsonpath<\/a>&nbsp;expression in the&nbsp;<code>&lt;filename&gt;<\/code>&nbsp;file<\/td><\/tr><tr><td><code>-o=name<\/code><\/td><td>Print only the resource name and nothing else<\/td><\/tr><tr><td><code>-o=wide<\/code><\/td><td>Output in the plain-text format with any additional information, and for pods, the node name is included<\/td><\/tr><tr><td><code>-o=yaml<\/code><\/td><td>Output a YAML formatted API object<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Examples using&nbsp;<code>-o=custom-columns<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># All images running in a cluster\nkubectl get pods -A -o=custom-columns='DATA:spec.containers[*].image'\n # All images excluding \"k8s.gcr.io\/coredns:1.6.2\"\nkubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!=\"k8s.gcr.io\/coredns:1.6.2\")].image'\n# All fields under metadata regardless of name\nkubectl get pods -A -o=custom-columns='DATA:metadata.*'\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">More examples in the kubectl&nbsp;<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/overview\/#custom-columns\">reference documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"kubectl-output-verbosity-and-debugging\">Kubectl output verbosity and debugging<a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\/#kubectl-output-verbosity-and-debugging\"><\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kubectl verbosity is controlled with the&nbsp;<code>-v<\/code>&nbsp;or&nbsp;<code>--v<\/code>&nbsp;flags followed by an integer representing the log level. General Kubernetes logging conventions and the associated log levels are described&nbsp;<a href=\"https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/devel\/sig-instrumentation\/logging.md\">here<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Verbosity<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>--v=0<\/code><\/td><td>Generally useful for this to&nbsp;<em>always<\/em>&nbsp;be visible to a cluster operator.<\/td><\/tr><tr><td><code>--v=1<\/code><\/td><td>A reasonable default log level if you don&#8217;t want verbosity.<\/td><\/tr><tr><td><code>--v=2<\/code><\/td><td>Useful steady state information about the service and important log messages that may correlate to significant changes in the system. This is the recommended default log level for most systems.<\/td><\/tr><tr><td><code>--v=3<\/code><\/td><td>Extended information about changes.<\/td><\/tr><tr><td><code>--v=4<\/code><\/td><td>Debug level verbosity.<\/td><\/tr><tr><td><code>--v=6<\/code><\/td><td>Display requested resources.<\/td><\/tr><tr><td><code>--v=7<\/code><\/td><td>Display HTTP request headers.<\/td><\/tr><tr><td><code>--v=8<\/code><\/td><td>Display HTTP request contents.<\/td><\/tr><tr><td><code>--v=9<\/code><\/td><td>Display HTTP request contents without truncation of contents.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Readings https:\/\/github.com\/talos-systems\/talos Kubectl autocomplete BASH You can also use a shorthand alias for&nbsp;kubectl&nbsp;that also works with completion: ZSH Kubectl context and configuration Set which Kubernetes cluster&nbsp;kubectl&nbsp;communicates with and modifies configuration information. See&nbsp;Authenticating Across Clusters with kubeconfig&nbsp;documentation for detailed config file information. Kubectl apply apply&nbsp;manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running&nbsp;kubectl apply. This is the recommended way of managing Kubernetes applications on production. See&nbsp;Kubectl Book. Creating objects Kubernetes manifests can be defined in YAML or JSON. The file extension&nbsp;.yaml,&nbsp;.yml, and&nbsp;.json&nbsp;can be used. Viewing, finding resources Updating resources Patching resources Editing resources Edit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7500,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22,43],"tags":[],"class_list":["post-7496","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","category-kubernetes"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/7496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/comments?post=7496"}],"version-history":[{"count":0,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/7496\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media?parent=7496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/categories?post=7496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/tags?post=7496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}