What You Will Learn
Beginner
- All essential kubectl commands
- How to inspect and manage K8s resources
- Common flags and patterns
Essential Commands
| Command | What it does |
|---|---|
kubectl get pods | List Pods |
kubectl get svc | List Services |
kubectl get deploy | List Deployments |
kubectl describe pod NAME | Detail about a Pod |
kubectl logs POD_NAME | View Pod logs |
kubectl exec -it POD -- bash | Shell into a Pod |
kubectl apply -f file.yaml | Create/update from YAML |
kubectl delete pod NAME | Delete a Pod |
kubectl port-forward POD 8080:80 | Forward local port to Pod |
kubectl get all | List everything |
Useful Flags
Terminalbash
# Wide output (more columns)
kubectl get pods -o wide
# All namespaces
kubectl get pods --all-namespaces
# YAML output
kubectl get pod my-app -o yaml
# Watch (live updates)
kubectl get pods -w
# Labels
kubectl get pods --show-labels
kubectl get pods -l app=my-appCommon Patterns
Terminalbash
# Get a shell in a Pod
kubectl exec -it my-pod -- bash
# View logs (follow)
kubectl logs -f my-pod
# Port forward to access locally
kubectl port-forward svc/my-service 8080:80
# Scale a deployment
kubectl scale deployment my-app --replicas=5
# Rollout status
kubectl rollout status deployment/my-appPractical Exercise
Run: kubectl get pods
Run: kubectl get pods -o wide
Run: kubectl describe pod
Run: kubectl logs
Run: kubectl get all --all-namespaces
Key Takeaways
- get: list resources. describe: detailed info.
- logs: view output. exec: shell into Pod.
- apply -f: create/update from YAML.
- port-forward: access Pod locally.
- -o wide: more columns. -w: watch. --all-namespaces: everything.
Comments
Comments
Post a Comment