DEV Community

Mesrar
Mesrar

Posted on

Demystifying Kubernetes: A Guide to Node and Pod Management

Node Exploration

View Node Information

To gather information about your Kubernetes nodes, use the following commands:

kubectl get no
Enter fullscreen mode Exit fullscreen mode

For a more detailed view, including internal IP addresses and node conditions, use:

kubectl get no -o wide
Enter fullscreen mode Exit fullscreen mode

To delve even deeper into a specific node, run:

kubectl describe no <node-name>
Enter fullscreen mode Exit fullscreen mode

Pod Insights

List Pods

To list all pods in the default namespace, use:

kubectl get po
Enter fullscreen mode Exit fullscreen mode

For a wider view, including additional information like node placement, execute:

kubectl get po -o wide
Enter fullscreen mode Exit fullscreen mode

Pod Details and Configuration
Retrieve the YAML representation of a pod for detailed information:

kubectl get po <pod name> -o yaml
Enter fullscreen mode Exit fullscreen mode

Alternatively, obtain the JSON representation:

kubectl get po <pod name> -o json
Enter fullscreen mode Exit fullscreen mode

For an insightful narrative about a specific pod, use:

kubectl describe po <pod name>
Enter fullscreen mode Exit fullscreen mode

Pod Operations
Delete a specific pod:

kubectl delete po <pod name>
Enter fullscreen mode Exit fullscreen mode

Or, clear the slate by deleting all pods:

kubectl delete po --all
Enter fullscreen mode Exit fullscreen mode

Apply changes from a pod definition file:

kubectl apply -f <pod.yaml> -n <namespace-name>
Enter fullscreen mode Exit fullscreen mode

Pod Editing
Extract a pod's definition to a file for editing:

kubectl get po <pod-name> -o yaml > pod.yaml
vi pod.yaml
kubectl delete po <pod-name>
kubectl apply -f pod.yaml
Enter fullscreen mode Exit fullscreen mode

Edit pod properties in-place:

kubectl edit po <pod-name>
Enter fullscreen mode Exit fullscreen mode

Pod Creation
Create a simple nginx pod with dry-run:

kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
Enter fullscreen mode Exit fullscreen mode

Executing Commands Inside Pods
Execute a command inside a running container:

kubectl exec [POD] -- [COMMAND]
kubectl exec nginx -- ls /
kubectl exec -it nginx -- /bin/sh
kubectl exec -it web -c nginx -- /bin/bash
Enter fullscreen mode Exit fullscreen mode

Multicontainer Pods
In multicontainer pods, containers are created and destroyed together. InitContainers, located under spec, have properties like name and image.

Additional Tips
Use kubectl get po -A to list all pods in all namespaces.
Troubleshoot errors across namespaces with kubectl get events -A | grep error.
Pods have a restartPolicy property with values: Always, Never, or OnFailure (default is Always).
Note: kubectl run creates pods, not deployments. There's no imperative command like kubectl create po for pod creation.

Explore the vast world of Kubernetes management with confidence! Happy Kuberneting!

Top comments (0)