Mastering Kubernetes: A Comprehensive Cheat Sheet
Kubernetes, often referred to as K8s, is an open-source platform designed to automate deploying, scaling, and operating application containers. Whether you're a seasoned developer or just starting your Kubernetes journey, this cheat sheet will serve as a handy reference for common tasks and commands.
Getting Started
Before diving into the cheat sheet, ensure you have the following prerequisites:
- Kubernetes cluster (e.g., set up using Minikube for local development)
- kubectl, the Kubernetes command-line tool, installed and configured
- Basic understanding of container orchestration and YAML
Kubernetes Objects: A Quick Overview
Kubernetes uses various objects to manage and deploy applications. Here's a brief overview:

- Pod: The smallest and simplest unit of the Kubernetes Platform that you create or deploy.
- Service: An abstraction which defines a policy by which to access the pods.
- Volume: A way to store data, used by the containers in your pod.
- Namespace: A way to divide cluster resources among multiple users.
- Deployment: Ensures that a specified number of pod replicas are running.
Essential kubectl Commands
The following kubectl commands are crucial for managing your Kubernetes cluster.
| Command | Description |
|---|---|
| kubectl get <resource> | Display one or many resources in a table. |
| kubectl apply -f <filename> | Create an object, update an existing object, or replace an object. |
| kubectl describe <resource> <name> | Show details of a specific resource. |
| kubectl delete <resource> <name> | Delete a resource by type and name. |
| kubectl exec <pod-name> -it -- /bin/bash | Execute a command in a running container. |
| kubectl port-forward <pod-name> <local-port>:<pod-port> | Connect local port to a pod's port. |
Deploying an Application
To deploy an application, you'll typically create a Deployment object, which manages the desired state of your application. Here's an example of a simple Deployment YAML file:
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
Scaling and Updating Deployments
Once your application is deployed, you can scale the number of replicas or update the application image using the following commands:

- Scale up/down:
kubectl scale deployment my-app --replicas=5 - Update image:
kubectl set image deployment my-app my-app=my-app:2.0
Troubleshooting Common Issues
When facing issues, use the following commands to diagnose problems:
- Check pod status:
kubectl get pods - Describe a pod:
kubectl describe pod <pod-name> - Check events:
kubectl get events - View logs:
kubectl logs <pod-name>























