kubernetes的volume中没有直接挂载文件的配置,需要使用subPath来实现文件的挂载。
pod使用subPath挂载文件
如下:将宿主机目录/home/busybox/busybox.conf挂载到容器到/home目录
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: busybox-deploy
spec:
replicas: 1
template:
metadata:
labels:
deploy: busybox
spec:
containers:
- name: busybox
image: hub.docker.com/google_containers/busybox:latest
command:
- sleep
- "3600"
volumeMounts:
- mountPath: /home/busybox.conf
name: conf
subPath: busybox.conf
volumes:
- name: conf
hostPath:
path: /home/busybox/