- 創(chuàng)建pvc腻贰,這里使用storageclasses動態(tài)存儲
kubectl get storageclasses --all-namespaces
- 創(chuàng)建mysql-pvc.yaml
cd /usr/local/src/mysql
vim mysql-pvc.yaml
nfs-provisioner為storageclasses名稱
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: nfs-provisioner
應(yīng)用:
kubectl apply -f mysql-pvc.yaml
-
創(chuàng)建好的pvc狀態(tài)為Bound:
kubectl get pvc
4辨绊、創(chuàng)建mysql-config配置文件
cd /usr/local/src/mysql
vim mysql-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
data:
my.cnf: |
[mysqld]
log-bin
#default_authentication_plugin=mysql_native_password
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default_time_zone='+08:00'
max_connections =1000
lowercase-table-names=1
應(yīng)用:
kubectl apply -f mysql-config.yaml
查看狀態(tài):
kubectl get configmaps
5、創(chuàng)建mysql
cd /usr/local/src/mysql
vim mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:8.0
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "handhand123"
volumeMounts:
- name: mysql-config-volume
mountPath: /etc/mysql/conf.d
- name: mysql-storage
mountPath: /var/lib/mysql
ports:
- containerPort: 3306
name: mysql
volumes:
- name: mysql-config-volume
configMap:
name: mysql-config
items:
- key: my.cnf
path: my.cnf
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
應(yīng)用:
kubectl apply -f mysql.yaml
查看狀態(tài):
kubectl get po
進(jìn)入容器:
kubectl exec -it mysql-675bd5859f-vlghc /bin/bash
mysql -uroot -p 密碼默認(rèn)handhand123
查看storageclass掛載目錄:
-
查看storageclass詳情
kubectl describe storageclass nfs-provisioner
-
關(guān)聯(lián)的po
kubectl edit po nfs-client-provisioner-5559df45fb-5kgcm -n kube-system
-
查看對應(yīng)服務(wù)器的nfs路徑下的文件即可