kubectl apply
DevOpsThe 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.
- kubectl get pods
- Description: Fetch information about running pods.
- Example:
- kubectl get pods
- kubectl describe pod
- Description: Provide detailed insights into a specific pod.
- Example:
- kubectl describe pod <pod-name>
- kubectl get nodes
- Description: List all nodes within the Kubernetes cluster.
- Example:
- kubectl get nodes
- kubectl describe node
- Description: Display comprehensive node details.
- Example:
- kubectl describe node <node-name>
- kubectl create deployment
- Description: Initiate a new deployment.
- Example:
- kubectl create deployment <deployment-name> –image=<image-name>
- kubectl get deployments
- Description: Retrieve a list of deployments.
- Example:
- kubectl get deployments
- kubectl scale deployment
- Description: Adjust the number of replicas in a deployment.
- Example:
- kubectl scale deployment <deployment-name> –replicas=<replica-count>
- kubectl delete deployment
- Description: Remove a deployment from the cluster.
- Example:
- kubectl delete deployment <deployment-name>
- kubectl get services
- Description: List all services in the cluster.
- Example:
- kubectl get services
- kubectl expose
- Description: Expose a deployment as a service.
- Example:
- kubectl expose deployment <deployment-name> –port=<port> –type=<service-type>
- kubectl delete service
- Description: Delete a service.
- Example:
- kubectl delete service <service-name>
- kubectl get namespaces
- Description: View all namespaces in the cluster.
- Example:
- kubectl get namespaces
- kubectl create namespace
- Description: Establish a new namespace.
- Example:
- kubectl create namespace <namespace-name>
- kubectl describe namespace
- Description: Provide detailed information about a namespace.
- Example:
- kubectl describe namespace <namespace-name>
- kubectl delete namespace
- Description: Remove a namespace.
- Example:
- kubectl delete namespace <namespace-name>
- kubectl logs
- Description: Access logs from a pod.
- Example:
- kubectl logs <pod-name>
- kubectl exec
- Description: Execute commands within a running container.
- Example:
- kubectl exec -it <pod-name> — <command>
- kubectl apply
- Description: Apply configuration changes to a resource.
- Example:
- kubectl apply -f <file.yaml>
- kubectl edit
- Description: Modify a resource’s configuration directly.
- Example:
- kubectl edit <resource-type> <resource-name>
- kubectl rollout
- Description: Manage deployments’ rollout status.
- Example:
- kubectl rollout status deployment <deployment-name>
- kubectl get configmaps
- Description: List all ConfigMaps in the cluster.
- Example:
- kubectl get configmaps
- kubectl create configmap
- Description: Create a new ConfigMap.
- Example:
- kubectl create configmap <configmap-name> –from-file=<path-to-file>
- kubectl describe configmap
- Description: Retrieve detailed information about a ConfigMap.
- Example:
- kubectl describe configmap <configmap-name>
- kubectl delete configmap
- Description: Eliminate a ConfigMap.
- Example:
- kubectl delete configmap <configmap-name>
- kubectl get secrets
- Description: List all secrets in the cluster.
- Example:
- kubectl get secrets
- kubectl create secret
- Description: Generate a new secret.
- Example:
- kubectl create secret generic <secret-name> –from-literal=<key>=<value>
- kubectl describe secret
- Description: Provide detailed insights into a secret.
- Example:
- kubectl describe secret <secret-name>
- kubectl delete secret
- Description: Remove a secret from the cluster.
- Example:
- kubectl delete secret <secret-name>
- kubectl get ingress
- Description: List all ingresses in the cluster.
- Example:
- kubectl get ingress
- kubectl create ingress
- Description: Create a new ingress.
- Example:
- kubectl create ingress <ingress-name> –rule=<rule>
- kubectl describe ingress
- Description: Retrieve detailed information about an ingress.
- Example:
- kubectl describe ingress <ingress-name>
- kubectl delete ingress
- Description: Delete an existing ingress.
- Example:
- kubectl delete ingress <ingress-name>
- kubectl get pv
- Description: List all persistent volumes in the cluster.
- Example:
- kubectl get pv
- kubectl describe pv
- Description: Display comprehensive details about a persistent volume.
- Example:
- kubectl describe pv <pv-name>
- kubectl delete pv
- Description: Remove a persistent volume.
- Example:
- kubectl delete pv <pv-name>
- kubectl get pvc
- Description: List all persistent volume claims in the cluster.
- Example:
- kubectl get pvc
- kubectl describe pvc
- Description: Retrieve detailed information about a persistent volume claim.
- Example:
- kubectl describe pvc <pvc-name>
- kubectl delete pvc
- Description: Delete a persistent volume claim.
- Example:
- kubectl delete pvc <pvc-name>
- kubectl port-forward
- Description: Forward local ports to a pod.
- Example:
- kubectl port-forward <pod-name> <local-port>:<remote-port>
- kubectl apply -f
- Description: Apply configuration changes from a file or URL.
- Example:
- kubectl apply -f <file.yaml>
- kubectl rollout history
- Description: Access deployment rollout history.
- Example:
- kubectl rollout history deployment <deployment-name>
- kubectl rollout undo
- Description: Rollback a deployment to a previous revision.
- Example:
- kubectl rollout undo deployment <deployment-name>
- kubectl label
- Description: Add or update labels on resources.
- Example:
- kubectl label <resource-type> <resource-name> <key>=<value>
- kubectl annotate
- Description: Add or update annotations on resources.
- Example:
- kubectl annotate <resource-type> <resource-name> <key>=<value>
- kubectl top
- Description: View resource (CPU/Memory) usage.
- Example:
- kubectl top <resource-type> <resource-name>
- kubectl create service
- Description: Create a new service.
- Example:
- kubectl create service <service-type> <service-name> –tcp=<port>:<target-port>
- kubectl run
- Description: Run an image on the cluster.
- Example:
- kubectl run <pod-name> –image=<image-name>
- kubectl expose pod
- Description: Expose a pod as a service.
- Example:
- kubectl expose pod <pod-name> –port=<port> –target-port=<target-port>
- kubectl rollout restart
- Description: Restart a deployment rollout.
- Example:
- kubectl rollout restart deployment <deployment-name>
- 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:
- Kubernetes Documentation: https://kubernetes.io/docs/home/
- kubectl Cheat Sheet: https://kubernetes.io/docs/reference/kubectl/quick-reference/
- Kubernetes API Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/