在Kubernetes下部署MysqL容器集群可以使用StatefulSet来管理。下面是一个示例:
apiVersion: v1
kind: ConfigMap
Metadata:
name: MysqL-config
data:
my.cnf: |
[MysqLd]
server-id=1
log-bin=MysqL-bin
binlog_format=row
skip_name_resolve=ON
apiVersion: v1
kind: Service
Metadata:
name: MysqL-service
spec:
selector:
app: MysqL
clusterIP: None
ports:
- port: 3306
apiVersion: apps/v1
kind: StatefulSet
Metadata:
name: MysqL
spec:
serviceName: MysqL-service
replicas: 3
selector:
matchLabels:
app: MysqL
template:
Metadata:
labels:
app: MysqL
spec:
containers:
- name: MysqL
image: MysqL:latest
env:
- name: MysqL_ROOT_PASSWORD
value: "password"
ports:
- containerPort: 3306
volumeMounts:
- name: MysqL-persistent-storage
mountPath: /var/lib/MysqL
volumes:
- name: MysqL-persistent-storage
persistentVolumeClaim:
claimName: MysqL-pvc
volumeClaimTemplates:
- Metadata:
name: MysqL-pvc
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
- 创建以上的配置文件
kubectl apply -f MysqL-configmap.yaml
,kubectl apply -f MysqL-service.yaml
,kubectl apply -f MysqL-statefulset.yaml
。
这样就创建了一个包含3个MysqL容器的集群。每个MysqL容器都有一个持久化存储卷,用于存储数据。MysqL容器使用配置文件中定义的配置来启动和运行。
注意:在部署集群之前,需要确保已经创建了一个Persistent Volume和Persistent Volume Claim,用于持久化存储。