Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
Kubernetes - Kubectl Commands
Next article icon

Kubectl Command Cheat Sheet

Last Updated : 27 Feb, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

If you are inspired to become a DevOps (Devlopment+Operations)'s Engineer and start your journey as a beginner, or if you're a professional looking to refresh your DevOps knowledge or transition into DevOps, or even if you're a learning geek seeking to expand your knowledge base, then you landed to the right place. Nowadays, Kubernetes (sometimes shortened to K8s with the 8 standing for the number of letters between the “K” and the “s” ) is a trending technology in the field of DevOps, and having a good understanding of it is crucial.

The Kubernetes Cheat Sheet is a comprehensive guide that serves as a quick reference for learning both the basics and advanced commands of Kubernetes. Whether you are a beginner just starting your journey with Kubernetes or an experienced professional with over 5 years of experience, this guide provides all the necessary commands for managing clusters, nodes, namespaces, and more.

Kubernetes Cheatsheet

Pre-requisites: Before moving to the Cheat sheet you should have a basic understanding of What Kubernetes exactly is, what are their uses, and how it helps. and knowledge of EKS, and AKS are additional advantages.

What is Kubernetes?

Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, and container load balancing (also called a container orchestration tool). It is written in Golang and has a vast community because it was first developed by Google and later donated to CNCF (Cloud Native Computing Foundation). Kubernetes can group ‘n’ number of containers into one logical unit for managing and deploying them easily. It works brilliantly with all cloud vendors i.e. public, hybrid, and on-premises. 

Kubectl (CLI): Kubectl is a command line configuration tool (CLI) for kubernetes used to interact with a master node of Kubernetes. Kubectl has a config file called kubeconfig, this file has the information about the server and authentication information to access the API Server.

Kubernetes (Kubectl) CheatSheet

Kubernetes CheatSheet servers as a quick reference guide for some commands and operations which are widely used in the kubernetes cluster. In this cheat sheet, Cluster management, node management, namespace management, resource creation, resource viewing and finding, resource deletion, file and directory copying, resource patching, resource scaling, pod management, deployment management, ReplicaSets management, service management, config maps and secrets, networking, storage, stateful sets, monitoring, troubleshooting, and other operations will be covered.

Kubernetes Master Node Components Important Terminologies

  1. API Server
  2. Scheduler
  3. Controller-Manager
  4. etcd

API Server

Kube API Server interacts with API, its a frontend of the kubernetes control plane. Communication center for developers and other kubernetes components.Receiving queries from multiple clients, including the kubectl command-line tool, the API server serves as the front-end interface for the Kubernetes control plane, coordinating cluster-wide operations.

Scheduler

The scheduler watches the pods and assigns the pods to run on specific hosts. A new pod does not have a specific node assigned when it is formed, whether by a user, a deployment controller, or a replication controller. The scheduler chooses a suitable node for the pod to run on after assessing the resource needs of the pod, such as CPU and memory usage, as well as any restrictions or affinity/anti-affinity rules supplied.

Controller-Manager

The controller manager runs the controllers in the background which run different tasks in the kubernetes cluster. Performs cluster-level functions(Replication, Tracking worker nodes, Handling failures).

etcd

etcd is a simple distributed key-value store. kubernetes uses etcd as its database to store all cluster data. Some of the data stored in etcd is job scheduling information, pods, state information and etc.

Kubernetes Worker Node Components Important Terminologies

Worker nodes are the node where the application actually runs in a kubernetes cluster, it is also known as a minion. These worker nodes are controlled by the master node using Kublet processes.

  1. kubelet
  2. kube-Proxy
  3. Container runtime

Kubelet

The main node agent, known as Kubelet, operates on each node and reads the container manifests to make sure that the containers are active and in good condition. It ensures that pods of containers are operating. Containers that weren't made by Kubernetes are not managed by the kubelet.

Kube-Proxy

By managing network rules on the host and managing connections, kube-proxy supports the kubernetes service abstraction. On nodes, Kube-proxy keeps track of network rules. Network connectivity to your pod is permitted by these network rules from both inside and outside of your cluster. Having a network proxy and load balancer for the service on a single worker node is beneficial to us.

Container Runtime

To process commands from the master server to run containers, each node needs a container runtime, such as Docker, containerd, or another container runtime.

Kubernetes (Kubectl) Commands

For Cluster Management

Command

Description

kubectl cluster-infokubectlGet cluster information.
kubectl get nodesViews all the nodes present in the cluster.

For Node Management

Command

Description

kubectl get nodesList all nodes in the cluster.
kubectl describe node <node-name>Describe a specific node.
kubectl drain <node-name>Drain a node for maintenance.
kubectl uncordon <node-name>Uncordon a node after maintenance.
kubectl label node <node_name> <key>=<value>You can label the node by using key-value pair.
kubectl label node <node_name> <label_key>-You can remove the label which is already attached to the node.

For Namespace Management

Command

Description

kubectl describe namespace <namespace-name> Describe a namespace.
kubectl create namespace <namespace-name>Create a namespace.
kubectl get namespacesList all namespaces.
kubectl config set-context --current --namespace=<namespace-name>Switch to a different namespace.
kubectl delete namespace <namespace-name>Delete a namespace.
kubectl edit namespace <namespace_name>Edit and update the namespace definition.

For Creating Resources

Command

Definition

kubectl apply -f <resource-definition.yaml>Create or Update a resource from a YAML file.
kubectl createCreate an object imperatively.
kubectl apply -f https://url-to-resource-definition.yamlCreate a resource by using the URL.

For Viewing and Finding Resources

Command

Description

kubectl get <resource-type>List all resources of a specific type.
kubectl get <resource-type> -o wideList all resources with additional details.
kubectl describe <resource-type> <resource-name>Describe a specific resource.
kubectl get <resource-type> -l <label-key>=<label-value>List all resources with a specific label.
kubectl get <resource-type> --all-namespacesList all resources in all namespaces.
kubectl get <resource-type> --sort-by=<field>List all resources sorted by a specific field.
kubectl get <resource-type> -l <label-selector>List resources with a specific label selector.
kubectl get <resource-type> --field-selector=<field-selector>List resources with a specific field selector.
kubectl get <resource-type> -n <namespace>List all resources in a specific namespace.

For Deleting Resources

Command

Description

kubectl delete <resource-type> <resource-name>Delete a resource.
kubectl delete <resource-type1> <resource-name1> <resource-type2> <resource-name2>Delete multiple resources.
kubectl delete <resource-type> --allDelete all resources of a specific type.
kubectl delete -f <resource-definition.yaml>kubectl delete -f https://url-to-resource-definition.yamlDelete the resource by using url.
kubectl delete <resource-type> --all -n <namespace>Delete all resources in a specific namespace.

For Copying Files and Directories

Command

Description

kubectl cp <local-path> <namespace>/<pod-name>:<container-path>Copy files and directories to a container.
kubectl cp <namespace>/<pod-name>:<container-path> <local-path>Copy files and directories from a container.
kubectl cp <namespace>/<pod-name>:<source-container-path> <destination-namespace>/<destination-pod-name>:<destination-container-path>Copying files from one container to another within the same pod.
kubectl cp <namespace>/<source-pod-name>:<source-container-path> <destination-namespace>/<destination-pod-name>:<destination-container-path>Copying files from one container to another in a different pod.

For Patching Resources

Command

Description

kubectl patch <resource-type> <resource-name> -p '<patch-document>Patch a resource using a JSON or YAML document.
kubectl patch <resource-type> <resource-name> --patch-file=<patch-file>Patch a resource using a JSON or YAML file.

For Scaling Resources

Command

Description

kubectl scale deployment <deployment-name> --replicas=<replica-count>Scale a deployment.
kubectl scale statefulset <statefulset-name> --replicas=<replica-count>Scale a statefulset.
kubectl scale replicaset <replicaset-name> --replicas=<replica-count>Scale a replica set.

For Pod Management

Command

Description

kubectl create -f <pod-definition.yaml>Create a pod from a YAML file.
kubectl get podsList all pods in the cluster.
kubectl describe pod <pod-name>Describe a specific pod.
kubectl logs <pod-name>Get logs from a pod.
kubectl logs -f <pod-name>Stream logs from a pod.
kubectl logs -l <label-key>=<label-value>Get logs with a specific label.
kubectl exec -it <pod-name> -- <command>Exec into a pod.
kubectl delete pod <pod-name>Delete a pod.
kubectl create pod <pod-name>Create a pod with the name.
kubectl get pod -n <namespace_name>List all pods in a namespace.

For Deployment Management

Command

Description

kubectl create deployment <deployment-name> --image=<image-name>Create a deployment.
kubectl get deploymentsList all deployments.
kubectl describe deployment <deployment-name>Describe a specific deployment.
kubectl scale deployment <deployment-name> --replicas=<replica-count>Scale a deployment.
kubectl set image deployment/<deployment-name> <container-name>=<new-image-name>Update a deployment's image.
kubectl rollout status deployment/<deployment-name>Rollout status of a deployment.
kubectl rollout pause deployment/<deployment-name>Pause a deployment rollout.
kubectl rollout resume deployment/<deployment-name>Resume a deployment rollout.
kubectl rollout undo deployment/<deployment-name>Rollback a deployment to the previous revision.
kubectl rollout undo deployment/<deployment-name> --to-revision=<revision-number>Rollback a deployment to a specific revision.
kubectl delete deployment <deployment-name>Delete deployment name.

For ReplicaSets Management

Command

Description

kubectl create -f <replicaset-definition.yaml>Create a ReplicaSet.
kubectl get replicasetsList all ReplicaSets.
kubectl describe replicaset <replicaset-name>Describe a specific ReplicaSet.
kubectl scale replicaset <replicaset-name> --replicas=<replica-count>Scale a ReplicaSet.

For Service Management

Command

Description

kubectl create service <service-type> <service-name> --tcp=<port>Create a service.
kubectl get servicesList all services.
kubectl expose deployment <deployment-name> --port=<port>Expose a deployment as a service.
kubectl describe service <service-name>Describe a specific service.
kubectl delete service <service-name>Delete a service.
kubectl get endpoints <service-name>Get information about a service.

For Config Maps and Secrets

Command

Description

kubectl create configmap <config-map-name> --from-file=<path-to-file>Create a config map from a file.
kubectl create secret <secret-type> <secret-name> --from-literal=<key>=<value>Create a secret.
kubectl get configmapsList all config maps.
kubectl get secretsList all secrets.
kubectl describe configmap <config-map-name>Describe a specific config map.
kubectl describe secret <secret-name>Describe a specific secret.
kubectl delete secret <secret_name>Delete a specific secret.
kubectl delete configmap <config-map-name>Delete a specific config map.

For Networking

Command

Description

kubectl port-forward <pod-name> <local-port>:<pod-port>Port forward to a pod.
kubectl expose deployment <deployment-name> --type=NodePort --port=<port>Expose a deployment as a NodePort service.
kubectl create ingress <ingress-name> --rule=<host>/<path>=<service-name> --<service-port>Create an Ingress resource.
kubectl describe ingress <ingress-name>Get information about an Ingress.
kubectl get ingress <ingress-name> -o jsonpath='{.spec.rules[0].host}'Retrieves the most value from the first rule of the specified Ingress resource.

For Storage

Command

Description

kubectl create -f <persistent-volume-definition.yaml>Create a PersistentVolume.
kubectl get pvList all PersistentVolumes.
kubectl describe pv <pv-name>Describe a specific PersistentVolume.
kubectl create -f <persistent-volume-claim-definition.yaml>Create a PersistentVolumeClaim.
kubectl get pvcList all PersistentVolumeClaims.
kubectl describe pvc <pvc-name>Describe a specific PersistentVolumeClaim.

For StatefulSets

Command

Description

kubectl create -f <statefulset-definition.yaml>Create a StatefulSet.
kubectl get statefulsetsList all StatefulSets.
kubectl describe statefulset <statefulset-name>Describe a specific StatefulSet.
kubectl scale statefulset <statefulset-name> --replicas=<replica-count>Scale a StatefulSet.

For Monitoring and Troubleshooting

Command

Description

kubectl get eventsCheck cluster events.
kubectl get component statusesGet cluster component statuses.
kubectl top nodesGet resource utilization of nodes.
kubectl top podsGet resource utilization of pods.
kubectl debug <pod-name> -it --image=<debugging-image>Enable container shell access debugging.

Miscellaneous

Command

Description

kubectl delete <resource-type> <resource-name>Delete a resource.
kubectl describe <resource-type> <resource-name>Get detailed information about a resource.
kubectl proxyAccess the Kubernetes dashboard.
kubectl completion <shell-type>Install kubectl completion.

Kubectl Output Verbosity and Debugging

The verbosity of kubernetes can be controlled by using a command which is kubectl verbosity. We can add no flags according to our requirements.

Command

Command

kubectl get <resource-type> --v=<verbosity-level

By using this command you set the level of verbosity output.

kubectl get <resource-type> --v=0Used to be visible to a cluster operator.
kubectl get <resource-type> --v=3

You can more information like extended information about changes.

kubectl get <resource-type> --v=7Displays the HTTPS request headers.
kubectl get <resource-type> --v=8Display HTTP request contents.

Conclusion

The Kubernetes Cheatsheet will help to have a quick reference of the most commonly used in Kubernetes (kuberctl commands). Kubernetes is one of the powerful container orchestration platforms by which you can manage applications in the form of containers. The commands which are mentioned in the Cheat Sheet provide a quick reference guide for both beginners and experienced before attending any interviews also.


Next Article
Kubernetes - Kubectl Commands

I

ishankhandkkvs
Improve
Article Tags :
  • Cloud Computing
  • Kubernetes-Basics

Similar Reads

    Kubernetes - Kubectl Commands
    Pre-requisites: Kubernetes The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. Some basic Kubectl commands in a Kubernetes cluster are as follows:kubectl Co
    5 min read
    Kubernetes - Kubectl Delete
    Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called a container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later don
    8 min read
    Kubernetes - Kubectl Create and Kubectl Apply
    Kubernetes is an open-source Container Orchestrating software platform that is widely used in modern application deployment and management. It comes up with many internal resources to manage the other working nodes Organizing as a Cluster facilitates seamless automatic scaling, and deployment update
    8 min read
    How To kubectl Exec Into Pod?
    To run a command within a container that is already executing inside a pod, use the command "kubectl exec into pod." This feature helps with debugging, troubleshooting, and administrative chores in the containerized environment. What Is Kubectl?A command-line interface for working with Kubernetes cl
    5 min read
    Kubernetes - Architecture
    Kubernetes Cluster mainly consists of Worker Machines called Nodes and a Control Plane. In a cluster, there is at least one worker node. The Kubectl CLI communicates with the Control Plane and the Control Plane manages the Worker Nodes. In this article, we are going to discuss in detail the architec
    5 min read
    How to Run curl Command From Within a Kubernetes Pod?
    Ever needed to fetch data or test connectivity from within a Kubernetes pod? The curl command becomes your trusty companion in these situations. This guide explores different approaches to execute curl commands directly from within your Kubernetes pod, empowering you to diagnose issues and interact
    3 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences