Kubernetes: Nodes and Pods Command

created:

updated:

tags: kubernetes

Kubernetes Pods

How to create a new Pod

kubectl run <name_of_pod> --image=<name_of_image>

# Through a pod definition YAML file
kubectl create -f <yaml_file>
kubectl apply -f <yaml_file>

# This will dry run the pod and output a yaml format and store it in redis.yaml file
kubectl run <name_of_pod> --image=<name_of_image> --dry-run=client -o yaml > redis.yaml
# Create a pod with a specified port
kubectl run <name_of_pod> --image=<name_of_image> --port <port>
# Create a pod as well as a service for it together
# It'll create a service with the same name as the pod
kubectl run <name_of_pod> --image=<name_of_image> --port=80 --expose=true

How to get pods information

kubectl get pods
# Get more in-depth information about the pod
kubectl describe pod <name_of_pod>
kubectl get pods -o wide
# Extract the pod definition in YAML format to a file
kubectl get pod <name_of_pod> -o yaml > pod-file.yaml

How to change the image of a pod

kubectl edit

or modify the yaml file for the pod and run again by kubectl apply -f <yaml_file>.

# Replace Pod information using replace
# This will delete the pod and create a new pod with the new definition file.
kubectl replace --force -f <pod_definition_file_to_replace_with>
# Pass additional arguments to kubectl run
kubectl run <name_of_pod> --image=<name_of_image> -- <arg1> <arg2> ...
kubectl run <name_of_pod> --image=<name_of_image> --command -- <cmd> <arg1> ...

How to delete a pod

kubectl delete pod <pod_name>

Kubernetes Nodes command

Get the Nodes information

kubectl get nodes
kubectl describe node <node_name>

Referenes