Pod容器共享Volume
在同一个Pod中多个容器能够共享Pod级别的存储卷Volume,如图:
在下面的例子中,Pod内包含两个容器:tomcat
和busybox
,在Pod级别设置Volume“app-logs”,用于tomcat向其中写日志文件,busybox读取日志文件
配置文件pod-volume-applogs.yaml
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
volumeMounts:
- name: app-logs
mountPath: /usr/local/tomcat/logs
- name: busybox
image: busybox
command: ["sh","-c","tail -f /logs/catalina*.log"]
volumeMounts:
- name: app-logs
mountPath: /logs
volumes:
- name: app-logs
emptyDir: {}
这里设置的Volume名为app-logs,类型为emptyDir,挂载到tomcat容器内/usr/local/tomcat/logs
目录同时挂载到logreader容器内的/logs目录
。
通过kubectl logs命令查看logreader容器的输出内容:
kubectl logs volume-pod -c busybox
这个文件即为tomcat
生成的日志文件/usr/local/tomcat/logs/catalina.<date>.log
的内容,登录tomcat容器进行查看:
kubectl exec -it volume-pod -c tomcat -- ls /usr/local/tomcat/logs
kubectl exec -it volume-pod -c tomcat -- tail /usr/local/tomcat/logs/ctalima.2017-07-30.log