kubernetes volume
创建一个Deployment,volume类型使用hostPath,将宿主机的/data/logs目录挂载到容器中的/data/logs下,
在容器中/data/logs/目录下的文件,会直接写入宿主机的/data/logs/目录下。
宿主机的/data/logs目录如果不存在,容器在创建时会创建。
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
template:
metadata:
labels:
run: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: /data/logs/
name: logdir
#subPath: logs
volumes:
- name: logdir
hostPath:
path: /data/logs/