Kubernetes Command-Line Interface (kubectl) is a powerful tool for managing and interacting with Kubernetes clusters. Here are the top 10 Kubernetes CLI commands that are frequently used by DevOps engineers and administrators:
View Cluster Info: View basic information about your cluster, including the current context and cluster details.
kubectl cluster-info
List Pods: List all the pods running in a particular namespace.
kubectl get pods -n <namespace>
List Services: List all the services running in a particular namespace.
kubectl get services -n <namespace>
Deploy an Application: Deploy an application from a YAML file.
kubectl apply -f <deployment.yaml>
Scale a Deployment: Scale the number of replicas for a deployment.
kubectl scale deployment/<deployment-name> --replicas=<replica-count>
Port Forwarding: Forward a local port to a pod for debugging or testing.
kubectl port-forward <pod-name> <local-port>:<pod-port>
Logs: View the logs of a pod.
kubectl logs <pod-name>
Exec into a Container: Open a shell inside a running container for troubleshooting.
kubectl exec -it <pod-name> -- /bin/sh
Rollout Status: Check the status of a deployment rollout.
kubectl rollout status deployment/<deployment-name>
Delete Resources: Delete resources such as pods, services, or deployments.
kubectl delete pod/<pod-name>