配置文件mysql.yaml
---
apiVersion: v1
kind: Service
metadata:
name: mysql-01
spec:
ports:
- port: 3306
selector:
app: mysql-01
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-01
labels:
app: mysql-01
spec:
selector:
matchLabels:
app: mysql-01
template:
metadata:
labels:
app: mysql-01
spec:
containers:
- name: mysql-01
image: mysql:5.6
resources:
limits:
memory: "512Mi"
cpu: "1500m"
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: Nosleeping996
volumeMounts:
- name: mysql-01-persistent-storage
mountPath: /var/lib/mysql
- name: mysql-01-conf
mountPath: /etc/mysql
volumes:
- name: mysql-01-persistent-storage
persistentVolumeClaim:
claimName: mysql-01-pvc
- name: mysql-01-conf
configMap:
name: my.cnf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: my.cnf
data:
my.cnf: |
[mysqld]
#skip-name-resolve
port = 3306
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake=1
default-storage-engine=INNODB
max_allowed_packet = 500M
explicit_defaults_for_timestamp=1
long_query_time = 10
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-01-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
应用部署
kubectl apply -f mysql.yaml
测试链接
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql-01 -pNosleeping996