Mastering Kubernetes: A Comprehensive Cheat Sheet
Kubernetes, often referred to as K8s, is a powerful open-source platform for automating deployment, scaling, and management of containerized applications. Whether you're a seasoned Kubernetes user or just starting out, this cheat sheet will serve as a handy reference for essential commands.
Getting Started
Before diving into the commands, ensure you have kubectl installed and configured to communicate with your Kubernetes cluster. You can verify this by running:
kubectl version
Cluster Information
To get an overview of your cluster, use the following commands:

kubectl cluster-info- Displays information about the server version and services.kubectl get nodes- Lists all nodes in the cluster with their status.
Managing Resources
Kubernetes resources are the building blocks of your cluster. Here are some essential commands for managing them:
Pods
Pods are the smallest deployable units in Kubernetes. Here's how you can manage them:
kubectl get pods- Lists all pods in the current namespace.kubectl describe pod <pod-name>- Displays detailed information about a specific pod.kubectl delete pod <pod-name>- Deletes a specific pod.
Deployments
Deployments ensure that a specified number of pod replicas are running. Here are some commands to manage deployments:

kubectl get deployments- Lists all deployments in the current namespace.kubectl apply -f <file.yaml>- Applies a configuration file to create or update a deployment.kubectl rollout restart deployment <deployment-name>- Rolls out a new version of the deployment.
Configuring Resources
Kubernetes uses YAML files to define resources. Here's how you can create and update resources using these files:
Creating and Updating Resources
To create or update a resource, use the kubectl apply command:
kubectl apply -f <file.yaml>
For example, to create a new deployment, you can use a YAML file like this:

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0
Deleting Resources
To delete a resource, use the kubectl delete command:
kubectl delete -f <file.yaml>
Troubleshooting
When encountering issues, use the following commands to diagnose problems:
Logging and Debugging
To view logs from a specific pod, use:
kubectl logs <pod-name>
To execute a command in a running container, use:
kubectl exec <pod-name> -- <command>
Describing Resources
To get detailed information about a resource, use the kubectl describe command:
kubectl describe <resource-type> <resource-name>
For example, to describe a specific deployment:
kubectl describe deployment my-app
Conclusion
This cheat sheet covers essential Kubernetes commands for managing and troubleshooting your cluster. By keeping this reference handy, you'll be well-equipped to handle various scenarios in your Kubernetes journey. Happy clustering!






















