k8s init container
initcontainer在应用容器启动之前启动。在initcontainer启动之前创建一个文件,放到卷中。k8s yaml commond命令格式:
- 命令
- "args1"
- "args2"
- ...
apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
containers:
- name: nginx-demo
image: nginx:latest
ports:
- containerPort: 8080
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
initContainers:
- name: install
command:
- touch
- "/work-dir/test.txt"
image: ubuntu:latest
volumeMounts:
- name: workdir
mountPath: "/work-dir"
volumes:
- name: workdir
emptyDir: {}
进入容器可以看到创建的test.txt文件
cd /usr/share/nginx/html
Please call me JiangYouDang!