k8s 共享volumn

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: 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”]

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

scan724

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值