¶ Common Commands
kubectl get nodes: List all nodes in the cluster.
kubectl get pods: List all pods in the default namespace.
kubectl get pods -n <namespace>: List all pods in a specific namespace.
kubectl describe pod <pod-name>: Show detailed information about a specific pod.
kubectl logs <pod-name>: Print the logs for a specific pod.
kubectl exec -it <pod-name> -- /bin/bash: Execute a command in a running pod.
kubectl create -f <file.yaml>: Create resources defined in a YAML file.
kubectl apply -f <file.yaml>: Apply changes defined in a YAML file.
kubectl delete pod <pod-name>: Delete a specific pod.
kubectl scale --replicas=<number> -f <file.yaml>: Scale the number of replicas for a resource.
kubectl get services: List all services in the default namespace.
kubectl get deployments: List all deployments in the default namespace.
kubectl get namespaces: List all namespaces in the cluster.
kubectl get events: List all events in the default namespace.
- Always check the status of your nodes and pods to ensure your cluster is healthy.
- Use namespaces to organize your resources and avoid naming conflicts.
- Regularly check logs and events to troubleshoot issues.
- Use
kubectl apply for managing resources declaratively and kubectl create for imperative management.
- Scale your applications based on demand to optimize resource usage.