DEV Community

Shiva Charan
Shiva Charan

Posted on

🧩 Basic Syntax for Creating a Pod

This is the minimum YAML needed:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-container
      image: nginx:latest
Enter fullscreen mode Exit fullscreen mode

βœ” apiVersion: v1

Pods always use API version v1.

βœ” kind: Pod

Defines the type of Kubernetes object.

βœ” metadata:

Name of your pod (must be unique in the namespace).

βœ” spec:

Describes what the Pod should run β†’ containers.

βœ” containers:

A Pod must have at least one container.


🧩 2. Pod With Port, Environment Variables & Resource Limits

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
    - name: nginx-container
      image: nginx:latest
      ports:
        - containerPort: 80
      env:
        - name: ENVIRONMENT
          value: production
      resources:
        limits:
          memory: "256Mi"
          cpu: "500m"
Enter fullscreen mode Exit fullscreen mode

🧩 3. Pod With Multiple Containers (Sidecar Pattern)

apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  containers:
    - name: app-container
      image: busybox
      command: ["sh", "-c", "echo Hello from App; sleep 3600"]

    - name: log-container
      image: busybox
      command: ["sh", "-c", "echo Logging; sleep 3600"]
Enter fullscreen mode Exit fullscreen mode

βœ” All containers share:

  • Same Pod IP
  • Same network namespace
  • Volumes (if defined)

πŸ› οΈ How to Create the Pod

Save the file as:

pod.yaml
Enter fullscreen mode Exit fullscreen mode

Then apply:

kubectl apply -f pod.yaml
Enter fullscreen mode Exit fullscreen mode

Check the pod:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Describe details:

kubectl describe pod my-pod
Enter fullscreen mode Exit fullscreen mode

View logs:

kubectl logs my-pod
Enter fullscreen mode Exit fullscreen mode

To create a Pod in Kubernetes

Define a YAML with

`apiVersion: v1`, 
`kind: Pod`,
metadata (name), and a 
spec with one or more containers. 
Enter fullscreen mode Exit fullscreen mode

Then apply it using kubectl apply -f <file>

Top comments (0)