avatarEbube Ndubuisi

Summary

The author has created a Kubernetes Cheat Sheet to help manage and analyze Kubernetes clusters quickly and efficiently.

Abstract

The author of this article, who has been working on multiple Kubernetes projects, found it challenging to remember all the necessary commands. To solve this problem, they created a database of commands that would help them analyze the cluster and complete different tasks quickly. The author decided to share this database with others and has organized the commands based on the tasks they accomplish. The commands are categorized into sections such as creating resources, viewing resources, deleting resources, cluster & resource management, contexts, cluster management, nodes, namespaces, pods, deployments, replicasets, daemonsets, services, service accounts, config maps, secrets, statefulsets, and storage. The author has also provided detailed explanations for each command and its usage. The article ends with a call to action for readers to connect with the author on LinkedIn and try out the AI service they recommend.

Bullet points

  • The author has created a Kubernetes Cheat Sheet to help manage and analyze Kubernetes clusters quickly and efficiently.
  • The author has organized the commands based on the tasks they accomplish.
  • The commands are categorized into sections such as creating resources, viewing resources, deleting resources, cluster & resource management, contexts, cluster management, nodes, namespaces, pods, deployments, replicasets, daemonsets, services, service accounts, config maps, secrets, statefulsets, and storage.
  • The author has provided detailed explanations for each command and its usage.
  • The article ends with a call to action for readers to connect with the author on LinkedIn and try out the AI service they recommend.

I made a Kubernetes Cheat Sheet: I was tired of looking up all the Kubernetes commands

Kubernetes Cheatsheet

Have you ever found yourself wasting twenty minutes trying to find the right command to complete a task while working on a Kubernetes project? I certainly have. I’ve been working on several Kubernetes projects lately, and I found remembering all the necessary commands challenging.

To solve this problem, I created a database of commands that would help me analyze the cluster and complete different tasks quickly. This way, I don’t have to memorize everything, and I can always access my documentation whenever needed.

Since I believe many people might benefit from such a database, I decided to share it with others. I will keep updating it as I learn more and complete different tasks.

To make it easy to use, I’ve organized the commands based on the tasks they accomplish. Here are the commands:

Create Resources

  • Kubectl run … : creates a pod
  • Kubectl create … : reates a deployment, service, replicasets, or other resources
  • Kubectl create -h : get help on using the create command
  • Kubectl run -h : Get help on using the run command
  • Kubectl apply -f : create a resource from a definition file

View Resources

  • Kubectl get : list a resource in the current namespace
  • Kubectl get -o wide : list the specified resource with more details
  • Kubectl get — -all-namespaces and Kubectl get -A : lists all the specified resources in all the namespaces
  • Kubectl get -n : lists all the specified resources in a specified namespace
  • Kubectl get -o yaml > : get a resource in a definition file format
  • Kubectl get -l = : Lists all the resources with the specified label
  • Kubectl describe : View detailed information about a resource

Delete Resources

  • Kubectl delete : deletes a Kubernetes resource
  • Kubectl delete : delete multiple resources
  • Kubectl delete -all : deletes all of the specified resource types
  • Kubectl delete -n : Delete all specified resources in a specific namespace
  • Kubectl delete — -all -n : Delete all specified resources in a specific namespace

Cluster & Resource Management

Contexts

  • The kubeconfig file for the cluster is located at ~/.kube/config
  • Kubectl config — -help — get the help commands for Kubectl config commands
  • Kubectl config view : view the kube config file
  • Kubectl config current-context : get the current context
  • Kubectl config set-context — -current — -namespace= : set the namespace of the current config

Cluster Management

  • Kubectl cluster-info — get cluster information
  • Kubectl version : display Kubernetes version
  • Kubectl config view : view the current configuration of the cluster
  • Kubectl api-resources : list all API resources
  • Kubectl get all — -all-namespaces : lists everything

Nodes

  • Kubectl get nodes : list the available nodes in the cluster
  • Kubectl describe node : get detailed info on a specific node
  • Kubectl drain node : drain resources from a node for maintenance or removal
  • Kubectl uncordon node : Uncordon a node after maintenance
  • Kubectl label node = : add a label to a node
  • Kubectl label node - : remove a label from a node
  • Kubectl taint node : update taints on a node
  • Kubectl top node : display resource usage of a node

Namespaces

  • Kubectl get namespaces : list all the namespaces
  • Kubectl create namespace : create a namespace
  • Kubectl config set-context — -current — -namespace= : switch to a different namespace
  • Kubectl delete namespace : delete a namespace
  • Kubectl edit namespace : Edit and update namespace definition
  • Kubectl top namespace : display resources (CPU/Memory/Storage) usage of a namespace

Pods

  • Kubectl run — -image= : create a pod
  • Kubectl create -f : create a pod from a definition file
  • Kubectl get pods : list the pods in the current namespace
  • Kubectl get pods -A : list pods in all namespaces
  • Kubectl get pod -n : list all the pods in a namespace
  • Kubectl get pods -o wide : get more details about pods
  • Kubectl get pods — -namespace- : view pods in a namespace
  • Kubectl get pod -o yaml > : get a pod in a definition file format
  • Kubectl describe pod : list details about a pod
  • Kubectl run — image= — command — …. : create a pod and make it run a command
  • Kubectl logs : view the logs of a pod
  • Kubectl logs -f : stream the logs of a pod
  • Kubectl exec -it — - : Exec into a pod and run a command
  • Kubectl delete : Delete a pod

Deployments

  • Kubectl create deployment — -image=: create a deployment imperatively
  • Kubectl apply -f :create a deployment from a definition file
  • Kubectl get deployments : list all the deployments
  • Kubectl get deployments -o wide : get detailed list of deployments
  • kubectl get deployment -o yaml > : get deployment in a definition file format
  • Kubectl describe deployment : describe a specific deployment
  • Kubectl scale deployment –replicas= : scale a deployment
  • Kubectl set image deployment/ = : update a deployments image
  • Kubectl rollout status deployment/ : view rollout status of a deployment
  • Kubectl rollout pause deployment/ : Pause a deployment rollout
  • Kubectl rollout resume deployment/ : Resume a deployment rollout
  • kubectl rollout undo deployment/ : rollback a deployment to a previous version
  • kubectl rollout undo deployment/ — -to-revision= : rollback a deployment to a specific version
  • Kubectl delete deployment : delete a deployment

Replicasets

  • kubectl apply -f : create a replicaset from a definition file
  • kubectl get replicasets : list the replica sets
  • kubectl describe replicaset : describe a specific replicaset
  • kubectl scale replicaset –replicas= : scale a replicaset

Daemonsets

  • Kubectl apply -f : create a daemonset
  • Kubectl get daemonset : list daemonsets
  • Kubectl get daemonsets -A : get daemonsets in all namespaces
  • Kubectl get daemonsets — -namespace= : get daemonsets in a namespace
  • Kubectl get daemonset -o yaml > : get a daemonset in a definition file format
  • Kubectl edit daemonset : edit a daemonset
  • Kubectl rollout daemonset : rollout a daemonset
  • Kubectl describe ds -n : get detailed information on a daemonset
  • Kubectl delete daemonset : delete a daemonset

Services

  • Kubectl create service — -tcp= : create a service imperatively
  • Kubectl apply -f : create a service from a definition file
  • kubectl get services: list all services
  • Kubectl expose deployment –port= : expose a deployment as a service
  • Kubectl describe service : Get more information on a specific service
  • Kubectl get endpoints : Get information about a service
  • kubectl delete service : Delete a service

ServiceAccounts

  • Kubectl create sa : create a service account
  • Kubectl get serviceaccounts : list the service accounts
  • Kubectl describe serviceaccount : get detailed information on a service account
  • Kubectl replace serviceaccount : replace a serviceaccount
  • Kubectl delete serviceaccount : delete a specific service account

ConfigMaps

  • kubectl create configmap — -from-file= : create a config map from a file
  • Kubectl apply -f : create a configmap from a file
  • kubectl get configmaps : list all configmaps
  • kubectl describe configmap : describe a specific config map
  • kubectl delete configmap : delete a specific configmap

Secrets

  • kubectl create secret –from-literal== : create a secret
  • Kubectl apply -f : create a secret from a definition file
  • Kubectl get secrets : list all the secrets
  • Kubectl describe secret : get detailed information about a secret
  • Kubectl delete secret : delete a secret

Statefulsets

  • kubectl apply -f : create a statefulset from a definition file
  • kubectl get statefulsets : list all statefulsets
  • kubectl describe statefulset : describe a specific statefulset
  • kubectl scale statefulset –replicas= : scale a statefulset
  • Kubectl delete statafulset : delete a specified stateful set

Storage

Persistent Volume and Persistent Volume Claim

  • kubectl apply -f : create a persistent volume from a definition file
  • kubectl get pv : list the persistent volumes
  • Kubectl describe pv : get more information on a persistent volume
  • Kubectl delete pv : delete a persistent volume
  • kubectl apply -f : create a persistent volume claim from a file
  • kubectl get pvc : list PersistentVolumeClaims
  • kubectl describe pvc : describe a specific PersistentVolumeClaims
  • Kubectl delete pvc : delete a persistent volume claim

Thank you so much for reading. I hope this can help you with your projects. To stay updated, give me a follow and subscribe. Good Luck with your projects!

Let’s connect on LinkedIn: https://www.linkedin.com/in/ebube-ndubuisi-38a125101/

Kubernetes
Kubernetes Cheatsheet
Minikube
Recommended from ReadMedium