1、創(chuàng)建ConfigMap:
創(chuàng)建一個名為mysql-config的ConfigMap,用于存儲MySQL配置文件
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
data:
my.cnf: |
[mysqld]
skip-host-cache
skip-name-resolve
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
2蒿偎、創(chuàng)建PersistentVolume (PV) 和 PersistentVolumeClaim (PVC):
創(chuàng)建PV和PVC來提供持久化存儲胰坟。
mysql-pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
3没卸、 創(chuàng)建MySQL Pod:
使用ConfigMap和PVC來創(chuàng)建MySQL Pod。
mysql.yaml
apiVersion: v1
kind: Pod
metadata:
name: mysql
spec:
containers:
- name: mysql
image: mysql:8.0
env:
- name: MYSQL_ROOT_PASSWORD
value: "handhand123"
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-config-volume
mountPath: /etc/mysql/conf.d
- name: mysql-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-config-volume
configMap:
name: mysql-config
items:
- key: my.cnf
path: my.cnf
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
kubectl apply -f mysql-config.yaml
kubectl apply -f mysql-pvc.yaml
kubectl apply -f mysql.yaml
秘鑰也可以用秘鑰替換(上面配置是直接寫死的) kubectl create secret generic mysql-secret --from-literal=password=你的密碼