This is the minimum YAML needed:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx:latest
β 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"
π§© 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"]
β All containers share:
- Same Pod IP
- Same network namespace
- Volumes (if defined)
π οΈ How to Create the Pod
Save the file as:
pod.yaml
Then apply:
kubectl apply -f pod.yaml
Check the pod:
kubectl get pods
Describe details:
kubectl describe pod my-pod
View logs:
kubectl logs my-pod
To create a Pod in Kubernetes
Define a YAML with
`apiVersion: v1`,
`kind: Pod`,
metadata (name), and a
spec with one or more containers.
Then apply it using kubectl apply -f <file>
Top comments (0)