1. Features
The highest priority, starting before other containers, mainly to do some initial configuration, such as downloading configuration files, registration information, certificates, etc.
Two, example
In the initialization container, write init container test to /work_dir/index.html, and mount /work_dir to /usr/share/nginx/html,
Then when you visit the Nginx homepage, the content displayed is init container test
Three, yaml file
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: init-demo
name: init-demo
spec:
replicas: 1
selector:
matchLabels:
app: init-demo
template:
metadata:
labels:
app: init-demo
spec:
initContainers:
- name: init-container
image: busybox
imagePullPolicy: IfNotPresent
command: ["sh"]
args:
[
"-c",
"echo 'init container test' >/work_dir/index.html",
]
volumeMounts:
- name: workdir
mountPath: "/work_dir"
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: web
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
volumes:
- name: workdir
emptyDir: {
}