13 most commonly used command for Kubernetes (Command + Purpose + Example) 🎯

Here are 13 of the most commonly used kubectl commands for managing a real production Kubernetes environment, along with explanations and common use cases:



✅Core Management

#1 kubectl get (Lists Kubernetes resources.)

Include:

→ kubectl get pods (list pods)

→ kubectl get deployments (list deployments)

→ kubectl get services (list services)

→ kubectl get all (list most resources in a namespace)


#2 kubectl describe (Provides detailed information about a resource.)

Include:

→ kubectl describe pod my-pod

→ kubectl describe node my-node


#3 kubectl create (Creates resources from files or standard input. Often used with YAML manifest files)

→ kubectl create -f my-deployment.yaml


#4 kubectl apply (Creates or updates resources based on a configuration file. The safer way to manage changes in production as it keeps track of applied changes.)

→ kubectl apply -f my-deployment.yaml (apply a deployment definition)


#5 kubectl delete (Deletes resources. Use with caution! )

→ kubectl delete pod my-pod

→ kubectl delete service my-service


✅Debugging and Troubleshooting

#6 kubectl logs (Gets logs from a container within a pod)

→ kubectl logs my-pod

→ kubectl logs my-pod -c my-container (specify a container)


#7 kubectl exec (Executes a command inside a container. Powerful for debugging)

→ kubectl exec -it my-pod -- bash (interactive shell)


#8 kubectl port-forward (Forwards a local port to a port on a pod. Useful for accessing services not directly exposed)

→ kubectl port-forward my-pod 8080:80


✅Monitoring and Analysis

#9 kubectl top (Displays resource usage (CPU/memory) for pods and nodes)

→ kubectl top pod (pod resource usage) 

→ kubectl top node (node resource usage)


#10 kubectl explain (Describes the fields of a Kubernetes resource)

→ kubectl explain pod 

→ kubectl explain pod.spec (more specific)


✅Managing Workloads

#11 kubectl rollout (Management for deployments, including updates and rollbacks)

→ kubectl rollout status deployment/my-deployment 

→ kubectl rollout undo deployment/my-deployment


#12 kubectl scale (Scales the number of replicas in a deployment or replica set)

→ kubectl scale deployment/my-deployment --replicas=5


#13 kubectl edit (Edits a resource's configuration directly on the cluster. Use with caution in production.)

→ kubectl edit deployment my-deployment


Important Notes:

→ Namespaces: Most commands can be used with -n <namespace> to target specific namespaces

→ Output Formats: Use -o wide, -o yaml, or -o json with commands like get and describe to control output formatting.


If you find this post helpful then you can connect with me for such quick contents:




Blog (for Roadmap & Quick Guide): https://techyoutube.com/

Comments

Popular posts from this blog

Free Courses - Git & GitHub (DevOps)

6 FREE courses to learn AWS & AWS DevOps (Concepts + Hands-on + Interview)