Types of containers in a Pod
- In Pod we have three types of containers
- containers: This is where we run our applications and ideally they would be running all the time. Containers in this will all start in parallel
- init containers: These are containers which will be created before the containers only after they finish execution the main containers. They execute in sequence. init containers are supposed to check for pre-reqs Refer Here for official docs
- Consider the following spec
---
apiVersion: v1
kind: Pod
metadata:
name: eight
spec:
containers:
- name: web
image: nginx
resources:
requests:
cpu: 100m
memory: 10M
limits:
cpu: 500m
memory: 128M
initContainers:
- name: cont1
image: alpine
args:
- sleep
- 5s
- name: cont2
image: alpine
args:
- sleep
- 10s
-
Now lets create and watch for pod
-
Refer Here for ephemeral containers
Pod lifecycle
Controllers
- Pod desired state is to ensure container is running
- Controllers manage Pods Refer Here
ReplicaSet
- Refer Here for official docs.
- Replicaset can maintain replicas of Pods.
Example 1: Create a repicaset with 3 nginx containers
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx
labels:
app: nginx
me: controller
type: rs
spec:
minReadySeconds: 5
replicas: 3
selector:
matchLabels:
app: web
env: dev
template:
metadata:
labels:
app: web
env: dev
srv: nginx
spec:
containers:
- name: web
image: nginx

- Now to increase number of replicas we can use
kubectl scale, but it is recommended to change yaml and reexecute kubectl apply -f <filepath>
Like this:
Like Loading...