k8s 运行单实例 mysql
---
apiVersion: v1
kind: Service
metadata:
name: mysqlonlyone
spec:
ports:
- port: 3306
selector:
app: mysqlonlyone
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysqlonlyone
labels:
app: mysqlonlyone
spec:
selector:
matchLabels:
app: mysqlonlyone
template:
metadata:
labels:
app: mysqlonlyone
spec:
containers:
- name: mysqlonlyone
image: mysql:5.6.51
resources:
limits:
memory: "512Mi"
cpu: "1"
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: Nosleeping996
volumeMounts:
- name: mysqlonlyone-persistent-storage
mountPath: /var/lib/mysql
- name: mysqlonlyone-conf
mountPath: /etc/mysql
volumes:
- name: mysqlonlyone-persistent-storage
persistentVolumeClaim:
claimName: mysqlonlyone-pvc
- name: mysqlonlyone-conf
configMap:
name: mysqlonlyone.cfg
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysqlonlyone.cfg
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
手动创建的PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysqlonlyone-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
评论区