The Ultimate Guide: Conquer Kubernetes with 50 Essential kubectl Commands

Kubernetes has revolutionized container orchestration, becoming an indispensable tool for modern DevOps practices. But navigating its functionalities requires familiarity with kubectl, the command-line interface that grants you control over your Kubernetes clusters.

This comprehensive guide equips you with the knowledge to become a Kubernetes commander, wielding 50 essential kubectl commands like a pro. With clear descriptions, practical examples, and valuable insights, you’ll be adept at managing your Kubernetes deployments with confidence.

  1. kubectl get pods
    • Description: Fetch information about running pods.
    • Example:
      • kubectl get pods
  2. kubectl describe pod
    • Description: Provide detailed insights into a specific pod.
    • Example:
      • kubectl describe pod <pod-name>
  3. kubectl get nodes
    • Description: List all nodes within the Kubernetes cluster.
    • Example:
      • kubectl get nodes
  4. kubectl describe node
    • Description: Display comprehensive node details.
    • Example:
      • kubectl describe node <node-name>
  5. kubectl create deployment
    • Description: Initiate a new deployment.
    • Example:
      • kubectl create deployment <deployment-name> –image=<image-name>
  6. kubectl get deployments
    • Description: Retrieve a list of deployments.
    • Example:
      • kubectl get deployments
  7. kubectl scale deployment
    • Description: Adjust the number of replicas in a deployment.
    • Example:
      • kubectl scale deployment <deployment-name> –replicas=<replica-count>
  8. kubectl delete deployment
    • Description: Remove a deployment from the cluster.
    • Example:
      • kubectl delete deployment <deployment-name>
  9. kubectl get services
    • Description: List all services in the cluster.
    • Example:
      • kubectl get services
  10. kubectl expose
    • Description: Expose a deployment as a service.
    • Example:
      • kubectl expose deployment <deployment-name> –port=<port> –type=<service-type>
  11. kubectl delete service
    • Description: Delete a service.
    • Example:
      • kubectl delete service <service-name>
  12. kubectl get namespaces
    • Description: View all namespaces in the cluster.
    • Example:
      • kubectl get namespaces
  13. kubectl create namespace
    • Description: Establish a new namespace.
    • Example:
      • kubectl create namespace <namespace-name>
  14. kubectl describe namespace
    • Description: Provide detailed information about a namespace.
    • Example:
      • kubectl describe namespace <namespace-name>
  15. kubectl delete namespace
    • Description: Remove a namespace.
    • Example:
      • kubectl delete namespace <namespace-name>
  16. kubectl logs
    • Description: Access logs from a pod.
    • Example:
      • kubectl logs <pod-name>
  17. kubectl exec
    • Description: Execute commands within a running container.
    • Example:
      • kubectl exec -it <pod-name> — <command>
  18. kubectl apply
    • Description: Apply configuration changes to a resource.
    • Example:
      • kubectl apply -f <file.yaml>
  19. kubectl edit
    • Description: Modify a resource’s configuration directly.
    • Example:
      • kubectl edit <resource-type> <resource-name>
  20. kubectl rollout
    • Description: Manage deployments’ rollout status.
    • Example:
      • kubectl rollout status deployment <deployment-name>
  21. kubectl get configmaps
    • Description: List all ConfigMaps in the cluster.
    • Example:
      • kubectl get configmaps
  22. kubectl create configmap
    • Description: Create a new ConfigMap.
    • Example:
      • kubectl create configmap <configmap-name> –from-file=<path-to-file>
  23. kubectl describe configmap
    • Description: Retrieve detailed information about a ConfigMap.
    • Example:
      • kubectl describe configmap <configmap-name>
  24. kubectl delete configmap
    • Description: Eliminate a ConfigMap.
    • Example:
      • kubectl delete configmap <configmap-name>
  25. kubectl get secrets
    • Description: List all secrets in the cluster.
    • Example:
      • kubectl get secrets
  26. kubectl create secret
    • Description: Generate a new secret.
    • Example:
      • kubectl create secret generic <secret-name> –from-literal=<key>=<value>
  27. kubectl describe secret
    • Description: Provide detailed insights into a secret.
    • Example:
      • kubectl describe secret <secret-name>
  28. kubectl delete secret
    • Description: Remove a secret from the cluster.
    • Example:
      • kubectl delete secret <secret-name>
  29. kubectl get ingress
    • Description: List all ingresses in the cluster.
    • Example:
      • kubectl get ingress
  30. kubectl create ingress
    • Description: Create a new ingress.
    • Example:
      • kubectl create ingress <ingress-name> –rule=<rule>
  31. kubectl describe ingress
    • Description: Retrieve detailed information about an ingress.
    • Example:
      • kubectl describe ingress <ingress-name>
  32. kubectl delete ingress
    • Description: Delete an existing ingress.
    • Example:
      • kubectl delete ingress <ingress-name>
  33. kubectl get pv
    • Description: List all persistent volumes in the cluster.
    • Example:
      • kubectl get pv
  34. kubectl describe pv
    • Description: Display comprehensive details about a persistent volume.
    • Example:
      • kubectl describe pv <pv-name>
  35. kubectl delete pv
    • Description: Remove a persistent volume.
    • Example:
      • kubectl delete pv <pv-name>
  36. kubectl get pvc
    • Description: List all persistent volume claims in the cluster.
    • Example:
      • kubectl get pvc
  37. kubectl describe pvc
    • Description: Retrieve detailed information about a persistent volume claim.
    • Example:
      • kubectl describe pvc <pvc-name>
  38. kubectl delete pvc
    • Description: Delete a persistent volume claim.
    • Example:
      • kubectl delete pvc <pvc-name>
  39. kubectl port-forward
    • Description: Forward local ports to a pod.
    • Example:
      • kubectl port-forward <pod-name> <local-port>:<remote-port>
  40. kubectl apply -f
    • Description: Apply configuration changes from a file or URL.
    • Example:
      • kubectl apply -f <file.yaml>
  41. kubectl rollout history
    • Description: Access deployment rollout history.
    • Example:
      • kubectl rollout history deployment <deployment-name>
  42. kubectl rollout undo
    • Description: Rollback a deployment to a previous revision.
    • Example:
      • kubectl rollout undo deployment <deployment-name>
  43. kubectl label
    • Description: Add or update labels on resources.
    • Example:
      • kubectl label <resource-type> <resource-name> <key>=<value>
  44. kubectl annotate
    • Description: Add or update annotations on resources.
    • Example:
      • kubectl annotate <resource-type> <resource-name> <key>=<value>
  45. kubectl top
    • Description: View resource (CPU/Memory) usage.
    • Example:
      • kubectl top <resource-type> <resource-name>
  46. kubectl create service
    • Description: Create a new service.
    • Example:
      • kubectl create service <service-type> <service-name> –tcp=<port>:<target-port>
  47. kubectl run
    • Description: Run an image on the cluster.
    • Example:
      • kubectl run <pod-name> –image=<image-name>
  48. kubectl expose pod
    • Description: Expose a pod as a service.
    • Example:
      • kubectl expose pod <pod-name> –port=<port> –target-port=<target-port>
  49. kubectl rollout restart
    • Description: Restart a deployment rollout.
    • Example:
      • kubectl rollout restart deployment <deployment-name>
  50. kubectl api-resources
    • Description: List supported API resources on the cluster.
    • Example:
      • kubectl api-resources

By incorporating these 50 essential kubectl commands into your workflow, you’ll streamline your Kubernetes management tasks, enhance efficiency, and gain deeper control over your containerized applications.

Ready to embark on your Kubernetes mastery journey? Start wielding these powerful commands today!

Reference Links:

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *