Node Exploration
View Node Information
To gather information about your Kubernetes nodes, use the following commands:
kubectl get no
For a more detailed view, including internal IP addresses and node conditions, use:
kubectl get no -o wide
To delve even deeper into a specific node, run:
kubectl describe no <node-name>
Pod Insights
List Pods
To list all pods in the default namespace, use:
kubectl get po
For a wider view, including additional information like node placement, execute:
kubectl get po -o wide
Pod Details and Configuration
Retrieve the YAML representation of a pod for detailed information:
kubectl get po <pod name> -o yaml
Alternatively, obtain the JSON representation:
kubectl get po <pod name> -o json
For an insightful narrative about a specific pod, use:
kubectl describe po <pod name>
Pod Operations
Delete a specific pod:
kubectl delete po <pod name>
Or, clear the slate by deleting all pods:
kubectl delete po --all
Apply changes from a pod definition file:
kubectl apply -f <pod.yaml> -n <namespace-name>
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
Edit pod properties in-place:
kubectl edit po <pod-name>
Pod Creation
Create a simple nginx pod with dry-run:
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
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
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)