Kubernetes provides a powerful command-line interface (CLI) called kubectl that allows you to interact with Kubernetes clusters. Here are some commonly used kubectl commands:
Cluster Information:
- View Cluster Information:
kubectl cluster-info - Display Nodes:
kubectl get nodes
Pods:
- List Pods:
kubectl get pods - Pod Details:
kubectl describe pod <pod_name> - Create Pod:
kubectl apply -f pod.yaml
Deployments:
- List Deployments:
kubectl get deployments - Scale Deployment:
kubectl scale deployment <deployment_name> --replicas=3 - Rollout History:
kubectl rollout history deployment <deployment_name>
Services:
- List Services:
kubectl get services - Service Details:
kubectl describe service <service_name>
ConfigMaps and Secrets:
- List ConfigMaps:
kubectl get configmaps - List Secrets:
kubectl get secrets
Logs and Exec:
- Pod Logs:
kubectl logs <pod_name> - Run Command in Pod:
kubectl exec -it <pod_name> -- /bin/sh
Namespaces:
- List Namespaces:
kubectl get namespaces - Switch Namespace:
kubectl config set-context --current --namespace=<namespace_name>
Contexts and Configuration:
- List Contexts:
kubectl config get-contexts - Switch Context:
kubectl config use-context <context_name>
Deleting Resources:
- Delete Pod:
kubectl delete pod <pod_name> - Delete Deployment:
kubectl delete deployment <deployment_name> - Delete Service:
kubectl delete service <service_name>
More Resources:
Remember to replace <pod_name>, <deployment_name>, <service_name>, etc., with the actual names of your Kubernetes resources.
These are just a few examples, and kubectl provides a wide range of commands for managing various aspects of Kubernetes clusters. Always refer to the official Kubernetes documentation for detailed information and options.