Table of contents
Introduction:
Kubernetes has become the de facto standard for container orchestration, providing a powerful platform for managing and scaling containerized applications. As a developer working with Kubernetes, it's important to have a solid understanding of the essential kubectl commands to navigate and interact with your clusters effectively. In this blog post, we will explore 25 useful kubectl commands with explanations and examples.
kubectl get pods:
Description: Lists all running pods in the current namespace.
Example: kubectl get pods.
kubectl create deployment --image=:
Description: Creates a new deployment with the specified name and image. Example: kubectl create deployment nginx-deployment --image=nginx
kubectl expose deployment --port=:
Description: Creates a new service for the specified deployment and exposes it on the specified port.
Example: kubectl expose deployment nginx-deployment --port=80
kubectl scale deployment --replicas=:
Description: Scales the specified deployment to the specified number of replicas.
Example: kubectl scale deployment nginx-deployment --replicas=3
kubectl delete deployment :
Description: Deletes the specified deployment.
Example: kubectl delete deployment nginx-deployment
kubectl delete pod :
Description: Deletes the specified pod.
Example: kubectl delete pod nginx-pod
kubectl logs :
Description: Shows the logs for the specified pod.
Example: kubectl logs nginx-pod
kubectl exec -it -- /bin/bash:
Description: Opens a shell in the specified pod.
Example: kubectl exec -it nginx-pod -- /bin/bash
kubectl port-forward ::
Description: Forwards traffic from the specified local port to the specified remote port on the specified pod.
Example: kubectl port-forward nginx-pod 8080:80
kubectl describe :
Description: Provides detailed information about the specified resource.
Example: kubectl describe pod nginx-pod
kubectl get nodes:
Description: Lists all the nodes in the cluster.
Example: kubectl get nodes
kubectl get services:
Description: Lists all the services in the current namespace.
Example: kubectl get services
kubectl get deployments:
Description: Lists all the deployments in the current namespace.
Example: kubectl get deployments
kubectl get configmaps:
Description: Lists all the configmaps in the current namespace.
Example: kubectl get configmaps
kubectl get secrets:
Description: Lists all the secrets in the current namespace.
Example: kubectl get secrets
kubectl apply -f :
Description: Applies the configuration file.
Example: kubectl apply -f deployment.yaml
kubectl rollout status deployment :
Description: Shows the status of the specified deployment rollout.
Example: kubectl rollout status deployment nginx-deployment
kubectl rollout history deployment :
Description: Shows the revision history of the specified deployment. Example: kubectl rollout history deployment nginx-deployment
kubectl rollout undo deployment :
Description: Undoes the last rollout of the specified deployment.
Example: kubectl rollout undo deployment nginx-deployment
kubectl top :
Description: Shows the resource usage statistics for the specified resource type.
Example: kubectl top pods
kubectl create namespace :
Description: Creates a new namespace with the specified name.
Example: kubectl create namespace my-namespace
kubectl get namespaces:
Description: Lists all the namespaces in the cluster.
Example: kubectl get namespaces
kubectl config get-contexts:
Description: Lists all the contexts in the Kubernetes configuration file. Example: kubectl config get-contexts
kubectl config set-context --namespace=:
Description: Sets the namespace for the specified context.
Example: kubectl config set-context my-context --namespace=my-namespace
kubectl edit :
Description: Opens the specified resource in the default editor.
Example: kubectl edit deployment nginx-deployment.
Conclusion:
These 25 kubectl commands are essential for developers working with Kubernetes. By leveraging these commands, you can effectively manage deployments, pods, services, namespaces, and more. Experiment with these commands in your Kubernetes environment and unlock the full potential of this powerful container orchestration platform.
Remember to refer to the official Kubernetes documentation for more detailed explanations and examples of each command. Happy Kubernetes development!
Hope you like my blog...!
if u like the content follow me on LinkedIn: https://www.linkedin.com/in/ashok-sana
Follow my Whatsapp & telegram community: https://chat.whatsapp.com/BzX1aruZIH645l29LxvgO3
Happy learning......!