Published on

๐ŸŒ๐Ÿš€๐ŸŽฏ Must Book Mark Kubernetes Cheat Sheet ๐ŸŒŸ๐Ÿ”ฅโœจ

Authors

featured-image.jpg

Table of Contents
# Ger logs of Pods in a Deployment. This is the recommended way to fetch logs, as the deployment name remains the same even if pods change upon creation.
kubectl logs deploy/<deployment-name>

# View the latest logs from the end. This can be useful when there are a large number of logs generated by a pod.
kubectl logs deploy/<deployment-name> --tail=2000

# Access a Pod within a Deployment using an interactive bash shell. This is the recommended method as the deployment name remains the same, unlike the pods that change upon creation.
kubectl exec -it deploy/<deployment-name> -- bash

# Access a Pod within a Deployment using an interactive shell. Use this if the previous method fails, as the pod does not support bash.
kubectl exec -it deploy/<deployment-name> -- sh

# Apply a folder or file containing Kubernetes manifests.
kubectl apply -f <folder-name-or-filename>

# Delete a folder or file containing Kubernetes manifests.
kubectl delete -f <folder-name-or-filename>

# Delete a deployment.
kubectl delete deployment <deployment-name>

# Forcefully delete a deployment without waiting for graceful termination.
kubectl delete deployment <deployment-name> --grace-period=0 --force

# Display the logs of a specific pod.
kubectl logs <pod-name>

# Stream and display the logs of a specific pod.
kubectl logs <pod-name> --follow

# Delete all jobs.
kubectl delete jobs `kubectl get jobs -o custom-columns=:.name`

# Delete pods based on a selector.
kubectl delete pods -l <pod-selector-key>=<pod-selector-value>

Pods

# List all pods in the current namespace.
kubectl get pods

# Get detailed information about a pod.
kubectl describe pod <pod-name>

# Create a new pod.
kubectl create pod <pod-name> 

# Delete a pod.
kubectl delete pod <pod-name> 

Nodes

# List all nodes in the cluster.
kubectl get nodes 

# Get detailed information about a node.
kubectl describe node <node-name> 

# Create a new node
kubectl create node <node-name> 

# Delete a node
kubectl delete node <node-name> 

Services

# List all services in the cluster.
kubectl get services 

# Get detailed information about a service.
kubectl describe service <service-name> 

# Create a new service.
kubectl create service <service-name> 

# Delete a service.
kubectl delete service <service-name> 

Deployments

# List all deployments in the cluster.
kubectl get deployments 

# Get detailed information about a deployment.
kubectl describe deployment <deployment-name> 

# Create a new deployment.
kubectl create deployment <deployment-name> 

# Delete a deployment.
kubectl delete deployment <deployment-name> 

ReplicaSets

# List all replica sets in the cluster.
kubectl get replicasets 

# Get detailed information about a replica set.
kubectl describe replicaset <replicaset-name> 

# Create a new replica set.
kubectl create replicaset <replicaset-name> 

# Delete a replica set.
kubectl delete replicaset <replicaset-name> 

StatefulSets

# List all stateful sets in the cluster.
kubectl get statefulsets 

# Get detailed information about a stateful set.
kubectl describe statefulset <statefulset-name> 

# Create a new stateful set.
kubectl create statefulset <statefulset-name> 

# Delete a stateful set.
kubectl delete statefulset <statefulset-name> 

Jobs

# List all jobs in the cluster.
kubectl get jobs 

# Get detailed information about a job.
kubectl describe job <job-name>

# Create a new job.
kubectl create job <job-name> 

# Delete a job.
kubectl delete job <job-name> 

CronJobs

# List all cron jobs in the cluster.
kubectl get cronjobs 

# Get detailed information about a cron job.
kubectl describe cronjob <cronjob-name> 

# Create a new cron job.
kubectl create cronjob <cronjob-name> 

# Delete a cron job.
kubectl delete cronjob <cronjob-name> 

ConfigMaps

# List all config maps in the cluster.
kubectl get configmaps 

# Get detailed information about a config map.
kubectl describe configmap <configmap-name> 

# Create a new config map.
kubectl create configmap <configmap-name> 

# Delete a config map.
kubectl delete configmap <configmap-name> 

Secrets

# List all secrets in the cluster.
kubectl get secrets 

# Get detailed information about a secret.
kubectl describe secret <secret-name> 

# Create a new secret.
kubectl create secret <secret-name> 

# Delete a secret.
kubectl delete secret <secret-name> 

Ingresses

# List all ingresses in the cluster.
kubectl get ingresses 

# Get detailed information about an ingress.
kubectl describe ingress <ingress-name>

# Create a new ingress.
kubectl create ingress <ingress-name> 

# Delete an ingress.
kubectl delete ingress <ingress-name> 

PersistentVolumes

# List all persistent volumes in the cluster.
kubectl get pv 

# Get detailed information about a persistent volume.
kubectl describe pv <persistentvolume-name> 

# Create a new persistent volume.
kubectl create pv <persistentvolume-name> 

# Delete a persistent volume.
kubectl delete pv <persistentvolume-name> 

PersistentVolumesClaims

# List all persistent volumes in the cluster.
kubectl get pvc

# Get detailed information about a persistent volume.
kubectl describe pvc <persistentvolumesclaim-name> 

# Create a new persistent volume.
kubectl create pvc <persistentvolumesclaim-name> 

# Delete a persistent volume.
kubectl delete pvc <persistentvolumesclaim-name>