k8s mysql pv,关于k8spv和pvc

关于pv和pvc 详细介绍 点这里

主要说明静态pvc如何关联到pv

创建应该PV:

apiVersion: v1

kind: PersistentVolume

metadata:

name: mysql-nfs

spec:

capacity:

storage: 50Gi

accessModes:

- ReadWriteMany

nfs:

server: 192.168.7.206

path: "/opt/dbdata"

创建应该PVC

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

name: mysql-nfs

spec:

accessModes:

- ReadWriteMany

resources:

requests:

storage: 50Gi

以上创建之后的pvc会自动去匹配满足accessModes,storage 条件的pv,如果有多个相同绑定到其中一个

2、指定pvc绑定到指定的pv

apiVersion: v1

kind: PersistentVolume

metadata:

name: mysql-nfs

pv: mysql-nfs

spec:

capacity:

storage: 50Gi

accessModes:

- ReadWriteMany

storageClassName: slow

nfs:

server: 192.168.7.206

path: "/opt/dbdata"

---

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

namespaces: dev

name: mysql-nfs

spec:

accessModes:

- ReadWriteMany

storageClassName: slow

resources:

requests:

storage: 50Gi

selector:

matchLabels:

pv: mysql-nfs

配置:storageClassName: slow。此配置用于绑定PVC和PV。这表明这个PVC希望使用storageClassName=slow的PV。接下来是accessModes =ReadWriteMany。这表明这个PV希望使用storageClassName=slow,并且accessModes =ReadWriteManye的PV。在上述条件都满足后,PVC还可以指定PV必须满足的Label,如matchLabels:pv: mysql-nfs。这表明此PVC希望使用storageClassName=slow,accessModes =

ReadWriteMany 并且拥有Label:

pv: mysql-nfs 的PV。最后是storage: 50Gi。这表明此PVC希望使用50G的Volume资源。

完整的部署mysql单点yaml文件

cat mysql/mysql-deploy.yaml

apiVersion: v1

kind: PersistentVolume

metadata:

name: mysql-nfs

spec:

capacity:

storage: 50Gi

accessModes:

- ReadWriteMany

nfs:

server: 192.168.7.206

path: "/opt/dbdata"

---

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

name: mysql-nfs

spec:

accessModes:

- ReadWriteMany

resources:

requests:

storage: 50Gi

---

apiVersion: v1

kind: Service

metadata:

name: dev-mysql

labels:

app: dev-mysql

spec:

type: NodePort

ports:

- port: 3306

targetPort: 3306

protocol: TCP

nodePort: 32066

selector:

app: dev-mysql

tier: mysql

---

apiVersion: extensions/v1beta1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1

kind: Deployment

metadata:

name: dev-mysql

labels:

app: dev-mysql

spec:

selector:

matchLabels:

app: dev-mysql

tier: mysql

strategy:

type: Recreate

template:

metadata:

labels:

app: dev-mysql

tier: mysql

spec:

containers:

- image: 192.168.19.111/baseimages/mysql:5.6

name: mysql

env:

- name: MYSQL_ROOT_PASSWORD

value: P12345678

livenessProbe:

tcpSocket:

port: 3306

ports:

- containerPort: 3306

name: mysql

volumeMounts:

- name: tz-config

mountPath: /etc/localtime

- name: mysql-persistent-storage

mountPath: /var/lib/mysql

volumes:

- name: mysql-persistent-storage

persistentVolumeClaim:

claimName: mysql-nfs

- name: tz-config

hostPath:

path: /usr/share/zoneinfo/Asia/Shanghai

claimName: mysql-nfs对应pvc名称

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值