The Ultimate Kubectl Cheat Sheet You Ever Need

Introduction

Kubernetes has rapidly become the de facto standard for container orchestration, powering modern, scalable, and reliable applications. Managing Kubernetes clusters and workloads effectively is crucial, and one of the most essential tools in a Kubernetes administrator’s arsenal is kubectl. In this article, we will go over the Kubectl Cheat Sheet you ever need.

This command-line tool allows you to interact with your Kubernetes clusters, and having a solid understanding of its commands is vital. In this tech blog, we’ll provide you with a comprehensive Kubectl Cheat Sheet, covering some of the most common and useful kubectl commands.

Installation

Before you start using kubectl, ensure it is installed. You can download it from the official Kubernetes website or use a package manager like brew or apt.

Kubectl Cheat Sheet

Version Check

  • Displays the client and server Kubernetes version.
   kubectl version
kubectl-version

Cluster Info

  • Shows information about the Kubernetes cluster.
   kubectl cluster-info

Context

  • Lists available contexts and sets the current context.
   kubectl config get-contexts
   kubectl config use-context <context-name>

Namespace Management

  • List, create, and delete namespaces.
   kubectl get namespaces
   kubectl create namespace <namespace-name>
   kubectl delete namespace <namespace-name>

Pod Management

List Pods

   kubectl get pods
   kubectl get pods -n <namespace>

Pod Describe

   kubectl describe pod <pod-name>

Logs

  • View pod logs, and optionally follow the logs in real time.
   kubectl logs <pod-name>
   kubectl logs -f <pod-name>

Exec into a Pod

  • Opens a shell inside a pod.
   kubectl exec -it <pod-name> -- /bin/sh

Deployment Management

List Deployments

   kubectl get deployments
   kubectl get deployments -n <namespace>

Scale Deployment

kubectl scale deployment <deployment-name> --replicas=<replica-count>

Rollout Status

kubectl rollout status deployment/<deployment-name>

Rollback Deployment

kubectl rollout undo deployment/<deployment-name>

Service Management

List Services

kubectl get services kubectl get services -n <namespace>

Expose a Deployment

kubectl expose deployment <deployment-name> --port=<port> --type=<service-type>

Delete a Service

kubectl delete service <service-name>

Configuration and Secrets

ConfigMap Management

kubectl create configmap <configmap-name> --from-file=<path-to-file>kubectl get configmap <configmap-name>

Secret Management

kubectl create secret generic <secret-name> --from-literal=<key>=<value>kubectl get secret <secret-name>

Node Management

List Nodes

kubectl get nodes

Node Describe

kubectl describe node <node-name>

Node Drain

kubectl drain <node-name>

Conclusion

Mastering kubectl commands is a crucial skill for anyone working with Kubernetes. This cheat sheet provides a solid foundation for managing Kubernetes clusters, pods, deployments, services, and more.

Remember that this is just the tip of the iceberg, and Kubernetes offers a vast ecosystem of features and resources to explore. Continue to learn and experiment to become proficient in Kubernetes administration.

Whether you’re a seasoned Kubernetes pro or just getting started, this kubectl cheat sheet should prove invaluable in your day-to-day operations.

It’s a handy reference to help streamline your Kubernetes management tasks and ensure the smooth operation of your containerized applications. Happy Kubernetes tinkering!

Leave a Comment