Kubernetes Cheat Sheet: Essential Commands

blank
Kubernetes cheat sheet

Kubernetes is a powerful tool for managing containerized applications, but its complexity can be daunting. Whether you’re deploying a new application, scaling services, or troubleshooting issues, having a Kubernetes cheat sheet at your fingertips can save you time and effort.

This guide expands on the basics, providing detailed tables of commands, advanced tips, and FAQs to help you become a Kubernetes expert.


Essential Kubernetes Commands

1. Cluster Management Commands

CommandDescription
kubectl cluster-infoDisplays information about the Kubernetes cluster.
kubectl get nodesLists all nodes in the cluster.
kubectl describe node <node-name>Provides detailed information about a specific node.
kubectl config viewDisplays the current Kubernetes configuration.
kubectl config use-context <context>Switches to a different Kubernetes context.

2. Pod Management Commands

CommandDescription
kubectl get podsLists all pods in the current namespace.
kubectl describe pod <pod-name>Provides detailed information about a specific pod.
kubectl logs <pod-name>Displays logs for a specific pod.
kubectl exec -it <pod-name> -- /bin/shOpens an interactive shell inside a running pod.
kubectl delete pod <pod-name>Deletes a specific pod.

3. Deployment Commands

CommandDescription
kubectl create deployment <name> --image=<image>Creates a new deployment using a specified container image.
kubectl get deploymentsLists all deployments in the current namespace.
kubectl describe deployment <name>Provides detailed information about a specific deployment.
kubectl scale deployment <name> --replicas=<number>Scales a deployment to the desired number of replicas.
kubectl rollout status deployment/<name>Displays the rollout status of a deployment.

4. Service Management Commands

CommandDescription
kubectl get servicesLists all services running in the cluster.
kubectl describe service <service-name>Provides detailed information about a specific service.
kubectl expose deployment <name> --type=LoadBalancer --port=<port>Exposes a deployment as a service.
kubectl delete service <service-name>Deletes a specific service.

5. Namespace Commands

CommandDescription
kubectl get namespacesLists all namespaces in the cluster.
kubectl create namespace <name>Creates a new namespace.
kubectl delete namespace <name>Deletes a specific namespace.
kubectl config set-context --current --namespace=<name>Switches to a different namespace.

6. ConfigMap and Secret Commands

CommandDescription
kubectl create configmap <name> --from-literal=<key>=<value>Creates a ConfigMap from a literal value.
kubectl get configmapsLists all ConfigMaps in the current namespace.
kubectl describe configmap <name>Provides detailed information about a specific ConfigMap.
kubectl create secret generic <name> --from-literal=<key>=<value>Creates a Secret from a literal value.
kubectl get secretsLists all Secrets in the current namespace.

Advanced Kubernetes Commands

1. Resource Monitoring

CommandDescription
kubectl top nodesDisplays resource usage (CPU, memory) for nodes.
kubectl top podsDisplays resource usage (CPU, memory) for pods.

2. Rolling Updates and Rollbacks

CommandDescription
kubectl set image deployment/<name> <container>=<new-image>Updates the image of a deployment.
kubectl rollout history deployment/<name>Displays the rollout history of a deployment.
kubectl rollout undo deployment/<name>Rolls back a deployment to the previous version.

3. Job and CronJob Commands

CommandDescription
kubectl create job <name> --image=<image>Creates a new job.
kubectl get jobsLists all jobs in the current namespace.
kubectl delete job <name>Deletes a specific job.
kubectl create cronjob <name> --image=<image> --schedule="<schedule>"Creates a new CronJob.
kubectl get cronjobsLists all CronJobs in the current namespace.

Common Kubernetes Challenges and Solutions

ChallengeSolution
Pods stuck in “Pending” stateCheck node resources and taints with kubectl describe node <node-name>.
Services not accessibleVerify service type and endpoints with kubectl describe service <name>.
Configuration errorsValidate YAML files with kubectl apply -f <file>.yaml --dry-run=client.
Resource limits exceededMonitor usage with kubectl top and adjust resource requests/limits.

FAQs About Kubernetes

What is the Difference Between a Pod and a Deployment?

A pod is the smallest deployable unit in Kubernetes, while a deployment manages the lifecycle of pods, ensuring the desired number of replicas are running.

How Do I Access Kubernetes Dashboard?

To access the Kubernetes dashboard, run: bash kubectl proxy. Then, open your browser and navigate to the provided URL.

Can I Use Kubernetes for Small Projects?

Yes, Kubernetes can be used for small projects, but it may be overkill for very simple applications. Consider using simpler tools like Docker Compose for smaller setups.


This Kubernetes cheat sheet is your ultimate guide to mastering Kubernetes commands and workflows. With detailed tables, advanced tips, and FAQs, you’ll be able to tackle any challenge with confidence. Bookmark this page for quick reference, and happy orchestrating!

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
blank

Securing Amazon S3 Buckets in AWS

Next Post
blank

Terraform Cheat Sheet: Quick Reference Guide

Related Posts