Skip to main content

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
  • Set requests (min resources) and limits (max resources) for CPU/memory.
Ports
  • Declare ports that the container exposes (e.g., containerPort: 80).
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
  • Set pod-specific DNS settings (e.g., ClusterFirst).
Restart Policy
  • Control when to restart the pod (e.g., Always, OnFailure).

A pod definition file is great for outlining the spec of a pod & it's containers, but it only allows for a single pod to be defined (can still define multiple containers within that pod).

For defining pod replicas, see HERE

Create pods based on pod definition file:

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

Replication Controller & Replica Sets

In Kubernetes, ReplicaSet and ReplicationController are both mechanisms used to ensure that a specified number of pod replicas are running at any given time. However, they have some differences, and the ReplicaSet has essentially replaced the older ReplicationController.


ReplicaSet

ReplicaSet is a more modern Kubernetes resource that also ensures a specified number of pod replicas are running, similar to the ReplicationController. The key improvement is that a ReplicaSet supports set-based selectors, allowing for more complex filtering when managing pods. ReplicaSets are typically used in conjunction with Deployments, which add features like rolling updates and rollback capabilities. ReplicaSets have largely replaced ReplicationControllers in modern Kubernetes setups.


Replication Controller

Replication Controller uses apiVersion: v1.

apiVersion: v1 #v1 API version defined
kind: ReplicationController

metadata: 
  name: app-rc
  labels:
    app: webapp
    
spec: #Begin rc specification
  replicas: 3 # Number of pod replicas
  selector:
    app: webapp
  template:
    metadata: 
      name: app-rc
      labels:
        app: webapp
    spec: # The pod spec
      containers: #Pod containers
        - name: nginx #Container name
          image: nginx:latest #Container image
          ports: #Port configuration
            - containerPort: 80 # Expose port 80
replicas: 4