Google:

adverisment

KUBERNETES – ALL IMPORTANT COMMANDS

details img

1. Deployment Commands

Create Deployment

kubectl create deployment myapp --image=nginx

Get Deployments

kubectl get deploy
kubectl describe deploy myapp

Scale Deployment

kubectl scale deploy myapp --replicas=5

Update / Set Image

kubectl set image deploy/myapp nginx=nginx:1.25

Rollout History

kubectl rollout status deploy/myapp
kubectl rollout history deploy/myapp
kubectl rollout undo deploy/myapp

2. Service Commands

kubectl get svc
kubectl describe svc myservice
kubectl delete svc myservice

Create Service

kubectl expose deployment myapp --port=80 --type=NodePort
kubectl expose pod mypod --port=8080 --type=ClusterIP

3. Namespace Commands

kubectl get ns
kubectl create ns dev
kubectl delete ns dev
kubectl get pods -n dev

4. ConfigMaps & Secrets

kubectl create configmap myconfig --from-literal=key=value
kubectl create configmap myconfig --from-file=config.json

Get/Describe

kubectl get configmap
kubectl describe configmap myconfig

Create Secret

kubectl create secret generic db-secret --from-literal=password=12345

5. Cluster Information

kubectl version
kubectl cluster-info
kubectl get nodes
kubectl describe node <node-name>
kubectl top node

6. POD Commands

kubectl apply -f pod.yaml
kubectl run mypod --image=nginx

Get Pods

kubectl get pods
kubectl get pod -o wide
kubectl get pod -A        # all namespaces

Describe / Logs

kubectl describe pod <name>
kubectl logs <pod-name>
kubectl logs -f <pod-name>   # live stream
kubectl logs <pod> -c <container>

Exec inside Pod

kubectl exec -it <pod> -- bash
kubectl exec <pod> -- ls /app

Delete Pod

kubectl delete pod <name>
kubectl delete -f pod.yaml

7. Ingress Commands

kubectl get ingress
kubectl describe ingress my-ingress
kubectl apply -f ingress.yaml

8. Node & Cluster Management

kubectl cordon <node>
kubectl drain <node>
kubectl uncordon <node>

kubectl get events
kubectl top nodes
kubectl top pods

9. Debugging Tools

kubectl describe pod <pod>
kubectl logs <pod>
kubectl exec -it <pod> -- sh

kubectl get events --sort-by=.metadata.creationTimestamp

Debug Pod (Ephemeral Container)

kubectl debug <pod> -it --image=busybox

10. Apply / Delete / Edit

kubectl apply -f file.yaml
kubectl delete -f file.yaml
kubectl edit deploy myapp

11. Port Forwarding

kubectl port-forward pod/mypod 8080:80
kubectl port-forward svc/myservice 3000:80

12. Autoscaling

kubectl autoscale deploy myapp --min=2 --max=10 --cpu-percent=70
kubectl get hpa

13. Storage (PV / PVC)

ubectl get pv
kubectl get pvc
kubectl describe pvc myclaim

14. Multi-Resource Apply

kubectl apply -f .
kubectl delete -f .

15. Useful Shortcuts

kubectl get all
kubectl get all -n kube-system

 

 

 

 

 

Leave Comment