Key Kubernetes Command
1. Working with Pods.................................................................................................................. 1
2. Working with Deployments.....................................................................................................1
3. Working with Services............................................................................................................ 2
4. Working with ConfigMaps and Secrets................................................................................. 2
5. Working with Namespaces..................................................................................................... 2
6. Managing Nodes...................................................................................................................... 3
t
7. Working with Persistent Volumes (PV) and Claims (PVC)................................................... 3
s
8. Configuring and Viewing Contexts........................................................................................ 3
9. Debugging Resources.............................................................................................................4
ni
10. Managing Jobs and CronJobs............................................................................................. 4
11. Applying and Deleting Manifests......................................................................................... 4
o
1. Working with Pods
si
kubectl get pods -> # Lists all pods in the current
Fu
namespace
kubectl get pods -A -> # Lists all pods across all
namespaces
kubectl describe pod <pod> -> # Displays detailed info about a
specific pod
h
kubectl delete pod <pod> -> # Deletes a specific pod
kubectl logs <pod> -> # Displays logs for a specific pod
c
kubectl exec -it <pod> -- /bin/sh -> # Executes a shell inside a
running pod
Te
2. Working with Deployments
kubectl get deployments -> # Lists all deployments
kubectl create deployment <name> --image=<image> -> # Creates a
deployment
kubectl scale deployment <name> --replicas=<num> -> # Scales a
deployment
kubectl rollout status deployment <name> -> # Checks rollout
status
t
kubectl rollout undo deployment <name> -> # Rolls back the
s
last deployment
ni
3. Working with Services
o
kubectl get services si -> # Lists all services
kubectl describe svc <service> -> # Displays detailed info about a
service
kubectl expose deployment <name> --port=<port> --type=<type> -> #
Fu
Exposes a deployment as a service
kubectl delete svc <service> -> # Deletes a specific service
4. Working with ConfigMaps and Secrets
h
kubectl create configmap <name> --from-literal=key=value -> #
c
Creates a ConfigMap
kubectl get configmaps -> # Lists
Te
all ConfigMaps
kubectl describe configmap <name> -> #
Describes a ConfigMap
kubectl create secret generic <name> --from-literal=key=value -> #
Creates a secret
kubectl get secrets -> # Lists
all secrets
kubectl describe secret <name> -> #
Describes a secret
5. Working with Namespaces
kubectl get namespaces -> # Lists all namespaces
kubectl create namespace <name> -> # Creates a new namespace
kubectl delete namespace <name> -> # Deletes a namespace
kubectl config set-context --current --namespace=<name> -> # Sets
default namespace for current context
s t
ni
6. Managing Nodes
kubectl get nodes -> # Lists all nodes in the cluster
o
kubectl describe node <node> -> # Displays detailed info about a node
kubectl drain <node> -> # Safely evicts pods from a node (for
maintenance)
kubectl cordon <node>
si
-> # Marks node as unschedulable
Fu
kubectl uncordon <node> -> # Marks node as schedulable again
7. Working with Persistent Volumes (PV) and Claims (PVC)
h
kubectl get pv -> # Lists all persistent
volumes
c
kubectl get pvc -> # Lists all persistent
volume claims
Te
kubectl describe pv <pv> -> # Displays info about a
persistent volume
kubectl describe pvc <pvc> -> # Displays info about a
persistent volume claim
kubectl delete pvc <pvc> -> # Deletes a specific PVC
8. Configuring and Viewing Contexts
kubectl config get-contexts -> # Lists all available
contexts
kubectl config use-context <context> -> # Switches to a specific
context
kubectl config current-context -> # Displays the current
context
kubectl config delete-context <context>-> # Deletes a specific context
s t
9. Debugging Resources
ni
kubectl describe <resource> <name> -> # Describes any Kubernetes
o
resource
kubectl logs <pod> si -> # Displays logs of a pod
kubectl logs -f <pod> -> # Follows pod logs in
real-time
kubectl get events -> # Lists cluster events
Fu
kubectl debug <pod> -> # Debugs a running pod
h
10. Managing Jobs and CronJobs
c
kubectl get jobs -> # Lists all jobs
kubectl delete job <job> -> # Deletes a specific job
Te
kubectl get cronjobs -> # Lists all cronjobs
kubectl delete cronjob <cronjob> -> # Deletes a specific cronjob
11. Applying and Deleting Manifests
kubectl apply -f <file.yaml> -> # Applies configuration from
a YAML file
kubectl delete -f <file.yaml> -> # Deletes resources defined
in a YAML file
kubectl diff -f <file.yaml> -> # Shows differences before
applying a YAML file
s t
Hope you find this document helpful!
ni
For more such content you can check : https://techyoutube.com/
o
Telegram: https://t.me/LearnDevOpsForFree
Twitter: https://twitter.com/techyoutbe
si
Youtube: https://www.youtube.com/@T3Ptech
Fu
c h
Te