k8s 共享volumn
apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
restartPolicy: Never
volumes:
- name: shared-data
hostPath:
path: /data
containers: - name: nginx-container
image: nginx
volumeMounts:- name: shared-data
mountPath: /usr/share/nginx/html
- name: shared-data
- name: debian-container
image: debian
volumeMounts:- name: shared-data
mountPath: /pod-data
command: ["/bin/sh"]
args: ["-c", “echo Hello from the debian container > /pod-data/index.html”]
- name: shared-data
debian-container 和 nginx-container 都声明挂载了 shared-data 这个 Volume。
kubectl apply -f share-volum.yaml
[root@dock01 ~]# kubectl get pods two-containers -n default
NAME READY STATUS RESTARTS AGE
two-containers 0/2 ContainerCreating 0 78s
kubectl describe pod two-containers -n default
[root@dock01 ~]# kubectl get pods two-containers -n default
NAME READY STATUS RESTARTS AGE
two-containers 0/2 Completed 0 10m
[root@dock01 ~]# kubectl get pods two-containers -n default
NAME READY STATUS RESTARTS AGE
two-containers 1/2 NotReady 0 13m
[root@dock03 data]# docker ps|grep nginx-container
884b560e06f6 nginx "nginx -g 'daemon of?? 5 minutes ago Up 4 minutes k8s_nginx-container_two-containers_default_b3ff7b7b-69ac-4c57-aad2-c275af80cab1_0
[root@dock03 data]# ls -ltr /data/
total 4
-rw-r–r-- 1 root root 32 Dec 19 06:30 index.html
[root@dock03 data]# cat index.html
Hello from the debian container
看下容器里是否有这个文件?
root@two-containers:/usr/share/nginx/html# cat index.html
Hello from the debian container