k8s mysql volume_k8s volume

volume是k8s数据卷,常见的数据卷有4种类型,即EmptyDir,HostDir,NFS,Secret

EmptyDir

EmptyDir是一个空目录,他的生命周期和所属的 Pod 是完全一致的,

可能读者会奇怪,那还要他做什么?EmptyDir的用处是,可以在同一 Pod 内的不同容器之间共享工作过程中产生的文件。

一旦这个pod离开了这个宿主机,EmptyDirr中的数据就会被永久删除

[root@k8s-master demon2]# cat test-emptypath.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

name: test-emptypath

role: master

name: test-emptypath

spec:

containers:

- name: test-emptypath

image: registry:5000/back_demon:1.0

volumeMounts:

- name: log-storage

mountPath: /home/laizy/test/

command:

- /run.sh

volumes:

- name: log-storage

emptyDir: {}

HostDir

HostDir属性的volume使得对应的容器能够访问当前宿主机上的指定目录。

[root@k8s-master demon2]# cat test-hostpath.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

name: test-hostpath

role: master

name: test-hostpath

spec:

containers:

- name: test-hostpath

image: registry:5000/back_demon:1.0

volumeMounts:

- name: ssl-certs

mountPath: /home/laizy/test/cert

readOnly: true

command:

- /run.sh

volumes:

- name: ssl-certs

hostPath:

path: /etc/ssl/certs

NFS

支持网络存储

[root@k8s-master demon2]# cat test-nfspath.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

name: test-nfspath

role: master

name: test-nfspath

spec:

containers:

- name: test-nfspath

image: registry:5000/back_demon:1.0

volumeMounts:

- name: nfs-storage

mountPath: /home/laizy/test/

command:

- /run.sh

volumes:

- name: nfs-storage

nfs:

server: 192.168.20.47

path: "/data/disk1"

Secret

Secret:Kubemetes提供了Secret来处理敏感数据

[root@k8s-master demon2]# cat secret.yaml

apiVersion: v1

kind: Secret

metadata:

name: mysecret

type: Opaque

data:

username: emhlbnl1

password: eWFvZGlkaWFv

[root@k8s-master demon2]# cat test-secret.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

name: test-secret

role: master

name: test-secret

spec:

containers:

- name: test-secret

image: registry:5000/back_demon:1.0

volumeMounts:

- name: secret

mountPath: /home/laizy/secret

readOnly: true

command:

- /run.sh

volumes:

- name: secret

secret:

secretName: mysecret

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值