k8s之init容器
警告
本文最后更新于 2020-05-30 17:09,文中内容可能已过时。
init容器初始化不成功,主容器不会执行
1.举例
创建pod
apiVersion: v1
kind: Pod
metadata:
name: blog
labels:
app: blog
spec:
initContainers:
- name: init-conf
image: busybox
command:
- wget
- -O
- /work-dir/index.html
- "https://soulchild.cn"
volumeMounts:
- name: work-dir
mountPath: /work-dir/
containers:
- name: blog
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: work-dir
mountPath: /usr/share/nginx/html/
volumes:
- name: work-dir
emptyDir: {}
创建svc
apiVersion: v1
kind: Service
metadata:
name: blog
spec:
selector:
app: blog
type: NodePort
ports:
- nodePort: 30002
port: 80
targetPort: 80
创建后可以访问master或node的IP+30002
请我喝杯水
微信号
微信打赏