k8s使用StatefulSet部署有状态的mysql
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: test1
spec:
selector:
matchLabels:
app: mysql
serviceName: mysql-service
replicas: 2
template:
metadata:
labels:
app: mysql
spec:
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-pvc
containers: - name: mysql
image: mysql:5.7
env:- name: MYSQL_ROOT_PASSWORD
value: 123456
ports: - containerPort: 3306
volumeMounts: - name: mysql-data
mountPath: /var/lib/mysql
volumeClaimTemplates:-
metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: rook-cephfs-sc
resources:
requests:
storage: 2Gi
-
- name: MYSQL_ROOT_PASSWORD
apiVersion: v1
kind: Service
metadata:
name: mysql-service
namespace: test1
spec:
selector:
app: mysql
ports:
- name: mysql
protocol: TCP
port: 3306
targetPort: 3306
type: ClusterIP
k8s创建StatefulSet状态的mysql