Devops Shack k8 Cheat Sheet
Devops Shack k8 Cheat Sheet
Display cluster
Cluster Information kubectl cluster-info
information.
List all nodes in the
kubectl get nodes
cluster.
Show detailed
kubectl describe node <node-name> information about a
specific node.
Show resource usage
kubectl top node
of nodes.
Show resource usage
kubectl top pod
of pods.
Display client and
kubectl version
server versions.
Namespaces kubectl get namespaces List all namespaces.
Create a new
kubectl create namespace <name>
namespace.
kubectl delete namespace <name> Delete a namespace.
kubectl config set-context --current --
Set default namespace.
namespace=<namespace>
List all pods in the
Pods kubectl get pods
current namespace.
List all pods across all
kubectl get pods -A
namespaces.
Show detailed
kubectl describe pod <pod-name> information about a
specific pod.
View logs of a specific
kubectl logs <pod-name>
pod.
kubectl logs <pod-name> -c <container- View logs of a specific
name> container in a pod.
Execute a shell
kubectl exec -it <pod-name> -- sh command inside a
running pod.
kubectl port-forward <pod-name> <local- Forward port to access
port>:<pod-port> a pod locally.
kubectl delete pod <pod-name> Delete a specific pod.
kubectl cp <file-path> <pod-name>:/<path> Copy files to a pod.
Deployments kubectl get deployments List all deployments.
kubectl describe deployment <name> Show detailed
information about a
specific deployment.
Apply configuration
kubectl apply -f <file.yaml>
from a YAML file.
kubectl scale deployment <name> --
Scale a deployment.
replicas=<n>
kubectl rollout restart deployment <name> Restart a deployment.
kubectl delete deployment <name> Delete a deployment.
Undo the last
kubectl rollout undo deployment <name>
deployment rollout.
kubectl set image deployment/<name> Update container
<container-name>=<new-image> image in a deployment.
kubectl expose deployment <name> -- Expose a deployment
port=<port> as a service.
Services kubectl get services List all services.
Show detailed
kubectl describe service <name> information about a
specific service.
kubectl expose pod <name> -- Expose a pod as a
type=NodePort --port=<port> service.
kubectl delete service <name> Delete a service.
kubectl port-forward service/<service- Forward a port to
name> <local-port>:<service-port> access a service locally.
kubectl create configmap <name> --from-
ConfigMaps Create a ConfigMap.
literal=<key>=<value>
kubectl get configmaps List all ConfigMaps.
Show detailed
kubectl describe configmap <name> information about a
ConfigMap.
kubectl delete configmap <name> Delete a ConfigMap.
Apply ConfigMap from
kubectl apply -f <configmap-file.yaml>
a file.
kubectl create secret generic <name> --
Secrets Create a secret.
from-literal=<key>=<value>
kubectl get secrets List all secrets.
Show detailed
kubectl describe secret <name> information about a
secret.
kubectl delete secret <name> Delete a secret.
kubectl apply -f <secret-file.yaml> Apply a secret from a
YAML file.
kubectl create job <name> --
Jobs Create a simple job.
image=<image>
kubectl get jobs List all jobs.
Show detailed
kubectl describe job <name> information about a
specific job.
kubectl delete job <name> Delete a specific job.
kubectl create cronjob <name> --
CronJobs Create a cron job.
image=<image> --schedule="* * * * *"
kubectl get cronjobs List all cron jobs.
kubectl delete cronjob <name> Delete a cron job.
List all Persistent
Persistent Volumes kubectl get pv
Volumes (PVs).
List all Persistent
kubectl get pvc
Volume Claims (PVCs).
Show detailed
kubectl describe pv <name> information about a
PV.
Show detailed
kubectl describe pvc <name> information about a
PVC.
kubectl delete pv <name> Delete a PV.
kubectl delete pvc <name> Delete a PVC.
List all ingress
Ingress kubectl get ingress
resources.
Show detailed
kubectl describe ingress <name> information about a
specific ingress.
Create or update an
kubectl apply -f <ingress-file.yaml>
ingress resource.
Delete an ingress
kubectl delete ingress <name>
resource.
List all events in the
Debugging kubectl get events
cluster.
Show detailed
kubectl describe <resource> <name> information about any
resource.
Stream logs from a
kubectl logs -f <pod-name>
pod.
Access a shell inside a
kubectl exec -it <pod-name> -- sh
running pod.
kubectl port-forward <pod-name> <local- Forward a local port to
port>:<pod-port> a pod.
Apply configurations
General Management kubectl apply -f <file.yaml>
from a YAML file.
Delete resources
kubectl delete -f <file.yaml>
defined in a YAML file.
Edit a resource
kubectl edit <resource> <name>
configuration directly.
Explain a resource
kubectl explain <resource>
type.
View the current
kubectl config view Kubernetes
configuration.