1.mysql持久化存储
[root@pserver78 0415villa]# cat latestmysql.yaml |grep -v '^#'
apiVersion: v1
kind: Service
metadata:
name: villa-mysql01
labels:
app: villa-mysql01
spec:
ports:
- port:
protocol: TCP
targetPort:
selector:
app: villa-mysql01
tier: mysql01
type: ClusterIP
---
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: villa-mysql01
labels:
app: villa-mysql01
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: villa-mysql01
tier: mysql01
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- pserver137
containers:
- image: mysql:5.6
name: vvvvmysql01
env:
- name: MYSQL_ROOT_PASSWORD
value: 'engine'
- name: MYSQL_PASSWORD
value: 'engine' ports:
- containerPort:
name: mysql01-port
volumeMounts:
- name: mysql01-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql01-persistent-storage
persistentVolumeClaim:
claimName: villa-mysql01
2.创建PVC和PV
[root@pserver78 villa]# cat mysqlpvc01.yaml |grep -v '^#'
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: villa-mysql01
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 50Gi
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: villa-mysql01
labels:
app: villa-mysql01
spec:
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
local:
path: "/mnt/disks/villa-mysql01"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- pserver137
3.定义storageclass
[root@pserver78 villa]# kubectl -n villa0415 get storageClass local-storage -o yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"local-storage","namespace":""},"provisioner":"kubernetes.io/no-provisioner","volumeBindingMode":"WaitForFirstConsumer"}
creationTimestamp: --31T00::22Z
name: local-storage
resourceVersion: ""
selfLink: /apis/storage.k8s.io/v1/storageclasses/local-storage
uid: -dca4-11e8-a7fc-020050e80095
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
.官网定义storageclass
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer