Kubernetes Cheat Sheet - Kubectl Commands And Objectives

blog_auth Blog Author

StarAgile

published Published

Sep 20, 2024

views Views

3,435

readTime Read Time

14 mins

Tabel of the content

DevOps professionals or freshers in this competitive digital age need to stay updated with Kubernetes. Kubernetes is the trending technology. Many professionals are looking to switch to DevOps to work on Kubernetes.

Kubernetes, also known as Kubectl or K8, provides a tough and native cloud environment. Sometimes, it becomes difficult to remember all the technical terms involved in Kubernetes, so the Kubernetes cheat sheet is important for DevOps professionals. Kubectl Cheat Sheet helps freshers to get a grasp of Kubernetes and make their journey to DevOps easier. 

In this article, we will talk about the Kubernetes cheat sheet required for DevOps programming.

Kubernetes cheat sheet

What is Kubernetes?

Before diving into the Kubernetes cheat sheet, let's understand what Kubernetes means. Kubernetes is software for automatic deployment, scaling, and managing containerised applications. It is open-source software. 

DevOps Certification

Training Course

100% Placement Guarantee

View course
 

Kubectl Cheat Sheet

There are many technical terms in Kubernetes. Let's understand some important terms used regularly in Kubectl.

  • Node (master) - These are physical/virtual servers controlling Kubernetes clusters.
  • Node (worker) - These are physical/virtual servers responsible for workload runs for the given container technology.
  • Cluster - These are the physical/virtual servers where the Kubernetes are installed.
  • Labels - These are user-defined keys - the value pair associated with the pods.
  • Pods - These are a group of volumes and containers that share the same namespace.
  • Service - This is an abstraction where the servers behave as a proxy for the pod's group performing a 'service'. 
  • Master - This is a control plane that provides access points to the admins. This helps them to manage their workloads.

Learn How To Install Kubernetes On Windows

Kubernetes have different kinds of objects. This can be controlled by using their full names or short forms. Let's look at some of the objects.

  • Services
    • EndpointSlice/endpointslices
    • Ingress/ingresses/ing
    • Endpoints/endpoints/ep
    • Service/Services/svc
    • IngressClass/ingressclasses
  • Clusters
    • Binding/bindings
    • ClusterRole/clusterroles
    • APIService/apiservices
    • CertificateSigningRequest/certificate signing requests/CSR
    • FlowSchema/flowschemas
    • Lease/leases
    • ClusterRoleBinding/clusterrolebindings
    • NameSpace/namespaces/ns
    • ComponentStatus/component statuses/cs
    • LocalSubjectAccessReview/localsubjectaccessreviews
    • Node/nodes/no
    • NetworkPolicy/network policies/netpol
    • PriorityLevelConfiguration/prioritylevelconfigurations/
    • PersistentVolume/persistentvolumes
    • Role/roles
    • ResourceQuots/resourcequotas/quota
    • RoleBinding/rolebindings
    • RunTimeClass/runtime classes
    • SelfSubjectAccessReview/selfsubjectaccessreviews
    • SelfSubjectRulesReview/selfsubjectrulesreviews
    • StorageVersion
    • TokenRequest
    • ServiceAccount/service accounts/sa
    • SubjectAccessReview/subjectaccessreviews
    • TokenReview/tokenreviews
  • Config & Storage 
    • CSIDriver/csidrivers
    • Secrets/secrets
    • CSINode/csinodes
    • ConfigMap/configmaps/cm
    • Volume
    • StorageClass/storageclasses/sc
    • VolumeAttachment/volumeattachements
    • PersistentVolumeClaim/persistentvolumeclaims/pvc
    • CSIStoragecapacity
  • Workloads
    • Daemonset/daemonset/ds
    • Container
    • Cronjobcronjobs/cj
    • Pod/pods/PO
    • Deployment/deployment/deploy
    • ReplicationController/replication controllers/RC
    • Replicaset/replicasets/rs
    • Statefulset/stateful sets/sts
  • Metadata
    • Event/events/ev
    • ControllerRevision/controllerrevisions
    • LimitRange/limitranges/limits
    • CustomResourceDefinition/custom resource definitions/crd/crds
    • PodTemplate/pod templates
    • MutatingWebhookConfiguration/mutatingwebhookconfigurations
    • HorizontalPodAutoscaler/horizonatalpodautoscalers/hpa
    • ValidatingWebhookConfiguration/validatingwebhookconfigurations
    • PodDisruptionBudget/pod disruption budgets/PDB
    • PriorityClass/priority classes/pc
    • PodSecurityPolicy/pod security policies/PSP

There are different kinds of Kubernetes commands that professionals in DevOps can use. Let's look at them in brief.

  • Nodes
    • Kubectl get node - It lists all worker nodes.
    • Kubectl top node - It displays the metrics of the given nodes
    • Kubectl delete node - It deletes the specified node in a cluster
    • Kubectl get pods -o wide | grep <node_name> - It lists all the pods with the current namespace.
    • Kubectl describe nodes | grep ALLOCATED -A 5 - It describes all the nodes in verbose.
    • Kubectl label node - It adds a label to the node.
    • Kubectl get no -o wide - It details all the nodes with more information.
    • Kubectl annotate node <node_name> - It adds the annotation to the node.
    • Kubectl uncordon node <node_name> - It marks the specific node into schedule.
  • Namespaces
    • Kubectl get namespace - It provides all the present namespaces in a single cluster.
    • Kubectl create namespace <namespace_name> - It creates a namespace.
    • Kubectl delete namespace <namespace_name> - It deletes a namespace.
    • Kubectl describe namespace <namespace_name> - It provides all the details of a particular namespace mentioned.
    • Kubectl edit namespace <namespace_name> - It helps to edit and update the definition of the mentioned namespace.
  • Pods
    • Kubectl get po - It provides the available in the mentioned namespace.
    • Kubectl delete pod <pod_name> - It deletes the mentioned pod.
    • Kubectl describe pod <pod_name> - It provides all the details of the mentioned pod.
    • Kubectl get pod -n <pod_name> - It arranges all the pods in the provided namespace.
    • Kubectl create pod <pod_name> - It creates a pod with the given name.
    • Kubectl create pod <pod_name> -n<name_space> - It creates a new pod with the given namespace.
  • Services
    • Kubectl get services - It provides one or more services.
    • Kubectl describe services <services_name> - It provides a detailed list of all services.
    • Kubectl delete service <service_name> - It deletes the mentioned service.
    • Kubectl delete service -o wide - It deletes all the services.
  • Deployments 
    • Kubectl get deployment - it lists more than one deployment.
    • Kubectl create deployment <deployment_name> - It creates a new deployment.
    • Kubectl describe deployment <deployment_name> - It provides the details of one or more mentioned deployments.
    • Kubectl delete deployment <deployment_name> - It deletes the mentioned deployment.
  • Events
    • Kubectl get events - It provides all the recent events from the entire resource in the system.
    • Kubectl get events - - field-selector involvedObject.kind! = Pod - It provides all the lists except the events in the pod.
    • Kubectl get events - - field-selector type ! = Normal - It leaves out the normal events from the entire list of events.
  • Logs
    • Kubectl logs <pod_name> - It displays the logs of the mentioned pod.
    • Kubectl logs - -since =1h <pod_name> - It displays the logs of the mentioned pod for one hour.
    • Kubectl logs -c <container_name> <pod_name> - It shows the logs of the mentioned container in the given pod.
    • Kubectl logs - -tail-20 <pod_name> - It shows the last 20 lines of the mentioned log.
    • Kubectl logs <pod_name> pod.log - It saves the log into a file with the extension pod.log.
  • Service Accounts
    • Kubectl describe serviceaccounts - It provides the details of more than one service account.
    • Kubectl get serviceaccounts - It provides all the service accounts.
    • Kubectl delete serviceaccounts <name> - It deletes the mentioned service accounts.
    • Kubectl replace serviceaccounts - It replaces the mentioned service accounts. 

DevOps Certification

Training Course

In Collaboration with IBM

View course
 

Conclusion

For professionals or freshers looking to undergo DevOps course, understanding Kubernetes is important. Kubernetes is an extensible, open-source, and easy-to-use platform for DevOps professionals. There are several codes and commands in Kubernetes. It is not easy to remember all. So, having a Kubectl Cheat Sheet is important. This article discussed several of the important codes and commands for user reference. 

For professionals who are looking to undergo DevOps Online Training, they can enrol themselves in the professional DevOps training at StarAgile. The candidates would get trained by experienced faculties with proper industry exposure. Professionals looking at Kubernetes training can also join StarAgile for expert training. 

Share the blog
readTimereadTimereadTime
Name*
Email Id*
Phone Number*

Keep reading about

Card image cap
DevOps
reviews5415
Top 10 DevOps programming languages in 20...
calender18 May 2020calender20 mins
Card image cap
DevOps
reviews4566
Top 9 Devops Engineer Skills
calender18 May 2020calender20 mins
Card image cap
DevOps
reviews4794
Best DevOps Tools in 2024
calender18 May 2020calender20 mins

Find DevOps Training in Top Cities

We have
successfully served:

3,00,000+

professionals trained

25+

countries

100%

sucess rate

3,500+

>4.5 ratings in Google

Drop a Query

Name
Email Id*
Phone Number*
City
Enquiry for*
Enter Your Query*