Introduction
I often forget these kubernetes or K8s commands. So I have created this sheet to quickly look any command.
It might be helpful for you to quickly look for any command. You can bookmark this blog for quick search.
π¦ Kubectl Basics
kubectl version                             # Show kubectl & cluster version
kubectl config view                         # View kubeconfig details
kubectl get nodes                           # List all cluster nodes
kubectl get all                             # List all resources in the current namespace
kubectl get pods -A                         # List all pods in all namespaces
kubectl get services                        # List all services
π Pods
kubectl run nginx --image=nginx             # Create a new pod
kubectl get pods                            # List all pods
kubectl describe pod <pod-name>             # Detailed info about a pod
kubectl logs <pod-name>                     # View logs
kubectl exec -it <pod-name> -- /bin/bash    # Shell into a pod
kubectl delete pod <pod-name>               # Delete a pod
ποΈ Deployments
kubectl create deployment myapp --image=myimage    # Create a deployment
kubectl get deployments                            # List deployments
kubectl scale deployment myapp --replicas=3        # Scale deployment
kubectl edit deployment myapp                      # Edit deployment config
kubectl rollout status deployment/myapp            # Check rollout status
kubectl rollout undo deployment/myapp              # Rollback deployment
kubectl delete deployment myapp                    # Delete deployment
π Services
kubectl expose deployment myapp --type=ClusterIP --port=80     # Create service
kubectl get svc                                                 # List services
kubectl describe svc myapp                                      # Service details
kubectl delete svc myapp                                        # Delete service
- 
Service Types: 
ClusterIP(default),NodePort,LoadBalancer,ExternalName 
π οΈ ConfigMaps & Secrets
kubectl create configmap myconfig --from-literal=key=value
kubectl get configmaps
kubectl describe configmap myconfig
kubectl create secret generic mysecret --from-literal=password=mypassword
kubectl get secrets
kubectl describe secret mysecret
π Namespaces
kubectl get namespaces
kubectl create namespace dev
kubectl config set-context --current --namespace=dev
π YAML Manifest Commands
kubectl apply -f config.yaml           # Apply from file
kubectl delete -f config.yaml          # Delete resources from file
kubectl create -f config.yaml          # Create resources from file
kubectl explain pod                    # Explain resource structure
π Monitoring & Debugging
kubectl top pod                        # Show resource usage
kubectl describe node <node-name>     # Node info
kubectl get events                    # Cluster event
π Bonus: Useful Shortcuts
kubectl get po                         # po = pods
kubectl get deploy                     # deploy = deployments
kubectl get svc                        # svc = services
kubectl get ns                         # ns = namespaces
    
Top comments (0)