Skip to content

Pods

An example pod-definition.yml...

apiVersion: v1

kind: Pod

metadata:
  name: myapp-pod
  labels:
    app: myapp

spec:
  containers:
    - name: nginx-container
      image: nginx

    - name: backend-container
      image: redis

To use kubectl to create the above, you'd use the following command...

kubectl create -f pod-definition.yml
kubectl get pods

Create a pod

From a spec...

kubectl run nginx --image=nginx

Dynamically generating a spec...

kubectl run redis --image=redis --dry-run=client -o yaml > pod.yaml
kubectl apply -f pod.yaml

Note that this spins up new pods.

To get the details of a given pod...

kubectl describe pod newpods-44xdd | grep image

Get more pod info

For example, seeing which node a pod is running on...

kubectl get pods -o wide

How many containers are part of the pod webapp?

kubectl get pods webapp

Pulling an image...

Note the state / reason:

  agentx:
    Container ID:
    Image:          agentx
    Image ID:
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       ErrImagePull
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-pgznf (ro)

Deleting a pod

kubectl delete pod <podname>

Editing an existing pod

Update the definition file and run the following...

kubectl apply

Or edit via the following...

kubectl edit pod <name>

If you don't have the original pod definition file...

kubectl get pod <pod-name> -o yaml > pod-definition.yaml

Pod editing limitations

Note you cannot edit the specifications of an existing pod other than the following:

  • spec.container[*].image
  • spec.initContainers[*].image
  • spec.activeDeadlineSeconds
  • spec.tolerations

For example, you can't edit...

  • environment variables
  • service accounts
  • resource limits