> ## Documentation Index
> Fetch the complete documentation index at: https://docs.karchunt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pod

## What is a Pod?

Pod is a **single instance of an application** and is the **smallest unit** of a Kubernetes application. It basically **wraps container** or provides an **abstraction layer** over container which **isolates** the application from the underlying infrastructure.

```mermaid theme={"theme":"github-dark-dimmed"}
flowchart
  subgraph Pod
    container
  end
```

Normally, pod is **only run one application container** inside it (**one-to-one relationship**). However, there are some cases where you can run **multiple containers** inside a pod, which is called **multi-container pod**.

Each pod will have its own **IP address** and **port space**, which means that the containers inside the pod can communicate with each other using **localhost** and **ports**, as they're **sharing** the **same network space**. They can also **share** the **same storage space**, which is called **volume**.

<Info>
  When a pod is **recreated**, it will get a new IP address. So, if you want to communicate from a pod to another pod, you should use the **service name** instead of its IP address.
</Info>

## Pod YAML File

Below is the sample pod YAML file that contains the basic fields of a pod definition.

```yaml icon="file-code" title="pod.yaml" lines theme={"theme":"github-dark-dimmed"}
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx:1.29
      ports:
        - containerPort: 80
```

To create a pod using the above YAML file, you can use the following command:

```bash icon="terminal" theme={"theme":"github-dark-dimmed"}
kubectl apply -f pod.yaml
```

{/* ## Commands

```bash
# Deploy nginx image to pod with the pod-name "nginx"
kubectl run <pod-name> --image=<image>

# Example
kubectl run nginx --image=nginx
kubectl run nginx --image=nginx --port=8000 # container exposes port
kubectl run nginx --image=nginx --port=8080 --expose # Create a cluster IP associated with the pod port number

kubectl get pods
kubectl get pod <pod-name>
kubectl describe pod <pod-name>
kubectl delete pod <pod-name>

kubectl exec <pod-name> -- <command>
kubectl exec mypod -- /bin/bash

kubectl apply -f <filename>
kubectl create -f <filename>

kubectl edit pod <pod-name>

# extract pod definition to a file
kubectl get pod <pod-name> -o yaml > pod.yaml

# get more pod information like IP address, etc
kubectl get pods -o wide
``` */}

{/* As mentioned in the previous section, when the Pod template for a workload resource is changed, the controller creates new Pods based on the updated template instead of updating or patching the existing Pods.

Kubernetes doesn't prevent you from managing Pods directly. It is possible to update some fields of a running Pod, in place. However, Pod update operations like patch, and replace have some limitations:

Most of the metadata about a Pod is immutable. For example, you cannot change the namespace, name, uid, or creationTimestamp fields.

If the metadata.deletionTimestamp is set, no new entry can be added to the metadata.finalizers list.

Pod updates may not change fields other than spec.containers[*].image, spec.initContainers[*].image, spec.activeDeadlineSeconds, spec.terminationGracePeriodSeconds, spec.tolerations or spec.schedulingGates. For spec.tolerations, you can only add new entries.

When updating the spec.activeDeadlineSeconds field, two types of updates are allowed:
- setting the unassigned field to a positive number;
- updating the field from a positive number to a smaller, non-negative number. */}
