Essential Kubernetes Commands with Simple Explanations
Kubernetes, or K8s, is a leading container orchestration platform that simplifies the deployment and management of applications. Knowing the right commands is key to navigating Kubernetes effectively. Here’s a guide to important Kubernetes commands explained in simple terms.
1. kubectl version
Command:
kubectl version --short
This command shows the versions of both the client and server components of Kubernetes. It helps ensure your kubectl tool is compatible with the cluster.
2. kubectl get
Command:
kubectl get pods
kubectl get services
kubectl get nodes
kubectl get pods
lists all pods in the current namespace.kubectl get services
displays all services, such as load balancers and cluster IPs.kubectl get nodes
shows all nodes in the cluster.
You can use the -A
or --all-namespaces
flag to view resources across all namespaces.
3. kubectl describe
Command:
kubectl describe pod <pod-name>
kubectl describe service <service-name>
This command provides detailed information about a specific resource. For instance, kubectl describe pod <pod-name>
displays details like events, resource limits, and configurations for the specified pod.
4. kubectl create
Command:
kubectl create deployment nginx --image=nginx
Creates a deployment with a specified name and container image. For example, the above command deploys an NGINX server.
5. kubectl apply
Command:
kubectl apply -f <manifest.yaml>
Applies a configuration file (YAML or JSON) to create or update resources declaratively.
6. kubectl delete
Command:
kubectl delete pod <pod-name>
kubectl delete -f <manifest.yaml>
Deletes specified resources. You can remove individual resources or those defined in a manifest file.
7. kubectl logs
Command:
kubectl logs <pod-name>
kubectl logs <pod-name> -c <container-name>
Fetches logs from a pod. If the pod has multiple containers, you can specify one using the -c
flag.
8. kubectl exec
Command:
kubectl exec -it <pod-name> -- /bin/bash
Opens an interactive shell session in a running pod. This is especially useful for debugging or troubleshooting applications.
9. kubectl port-forward
Command:
kubectl port-forward pod/<pod-name> 8080:80
Forwards a local port to a port on a pod, allowing you to access services running within the pod locally.
10. kubectl scale
Command:
kubectl scale deployment <deployment-name> --replicas=3
Scales a deployment to the desired number of replicas. This adjusts the number of pods running for an application.
11. kubectl rollout
Command:
kubectl rollout status deployment <deployment-name>
kubectl rollout undo deployment <deployment-name>
rollout status
monitors the status of a deployment rollout.rollout undo
rolls back to a previous version of a deployment.
12. kubectl top
Command:
kubectl top pod
kubectl top node
Displays resource usage, such as CPU and memory, for pods or nodes. Make sure the Metrics Server is installed for this command.
13. kubectl config
Command:
kubectl config get-contexts
kubectl config use-context <context-name>
Manages Kubernetes contexts, enabling you to switch between clusters or namespaces.
14. kubectl expose
Command:
kubectl expose deployment <deployment-name> --type=NodePort --port=80
Exposes a deployment as a service, making it accessible externally or internally based on the type specified.
15. kubectl get events
Command:
kubectl get events
Lists cluster events, including warnings and errors. This is useful for monitoring and troubleshooting.
Kubernetes commands can simplify complex tasks, making cluster management more efficient. By mastering these essential commands, you can navigate Kubernetes with confidence and tackle day-to-day tasks effectively. Start practicing today and enhance your Kubernetes skills!
Labels: Essential Kubernetes Commands with Simple Explanations
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home