123
Kubernetes provides the kubectl command-line tool to interact with clusters. Below are some commonly used commands with examples to help you manage resources effectively.
1. List Resources
To view resources like pods, services, or nodes:
kubectl get pods
kubectl get services
kubectl get nodes
Use -o wide for detailed output:
kubectl get pods -o wide
2. Create Resources
Create resources using YAML files or directly via commands:
kubectl create -f deployment.yaml
kubectl run nginx --image=nginx --port=80
3. Apply Changes
Apply or update configurations from a file:
kubectl apply -f config.yaml
4. Delete Resources
Delete specific resources or all of a type:
kubectl delete pod my-pod
kubectl delete pods --all
5. View Resource Details
Get detailed information about a resource:
kubectl describe pod my-pod
6. Logs and Debugging
View logs of a pod or container:
kubectl logs my-pod
kubectl logs -f my-pod # Stream logs
Execute commands inside a container:
kubectl exec -it my-pod -- /bin/bash
7. Scaling and Rollouts
Scale deployments or manage rollouts:
kubectl scale deployment my-deployment --replicas=3
kubectl rollout status deployment/my-deployment
8. Copy Files
Copy files between host and container:
kubectl cp /local/path pod-name:/container/path
No comments:
Post a Comment