2019独角兽企业重金招聘Python工程师标准>>>
1、创建pv
# cat pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:name: task-pv-volumelabels:type: local
spec:capacity:storage: 3GiaccessModes:- ReadWriteOncehostPath:path: "/tmp/data"
2、创建pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: db-mysql-0
spec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi
3、创建svc
apiVersion: v1
kind: Service
metadata:name: mysql-servicelabels:app: mysql
spec:ports:- port: 80name: my-portclusterIP: Noneselector:app: mysql
4、创建ss
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:name: mysqlnamespace: default
spec:serviceName: "mysql-service"replicas: 2template:metadata:labels:app: mysqlspec:terminationGracePeriodSeconds: 10containers:- name: mysqlimage: mysql:5.7.14ports:- containerPort: 3306name: my-portenv:- name: MYSQL_ROOT_PASSWORDvalueFrom:secretKeyRef:name: mysql-configkey: MYSQL_ROOT_PASSWORDvolumeMounts:- name: dbmountPath: /var/lib/mysqlvolumeClaimTemplates:- metadata:name: dbspec:accessModes: [ "ReadWriteOnce" ]resources:requests:storage: 1Gi
查看结果:
发现
需要再创建一个pv供pvc绑定,这种静态创建pv的方法很麻烦。
二、动态创建pv storage class