PODs
POD Definition
A pod definition file is used in Kubernetes to outline the pods and configuration involved in a deployment. Key configuration aspects to be defined within the pod definition file are:
| Metadata | Define pod name, labels, and annotations for identification. |
| Containers | Specify the container's name, image, and pull policy. |
| Resource Allocation |
|
| Ports |
|
| Environment Variables |
Pass environment variables to the container. |
| Volume Mounts | Mount persistent volumes or config files to the container. |
| Volumes | Define storage (PersistentVolumeClaim, ConfigMap, or Secret). |
| Probes | Health checks using liveness and readiness probes. |
| Command/Args | Custom commands and arguments for container startup. |
| Affinity/Anti-Affinity | Rules for scheduling the pod on specific nodes. |
| Node Selector | Simple label-based node constraints for scheduling. |
| Security Context | Set user/group IDs, filesystem permissions, and privilege levels. |
| DNS Policy |
|
| Restart Policy |
|
Create pods based on pod definition:
kubectl create -f pod-definition.yaml
Apply new changes to existing pods:
kubectl apply -f pod-definition.yaml
Example pod definition file
apiVersion: #v1 API version defined
kind: Pod #kind defined as pod
metadata: #begin metadata definitions
name: nginx-pod
labels:
app: webapp
spec: #Begin pod specification
containers: #Pod containers
- name: nginx #Container name
image: nginx:latest #Container image
ports: #Port configuration
- containerPort: 80