在Kubernetes中部署MySQL集群可以使用StatefulSet和PersistentVolume。以下是一个简单的步骤:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: mysql
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
volumeClaimTemplates:
- metadata:
name: mysql-persistent-storage
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
kubectl apply -f mysql-pvc.yaml
kubectl apply -f mysql-statefulset.yaml
以上步骤将会在Kubernetes中部署一个具有3个MySQL实例的集群,并且每个实例都有1Gi的PersistentVolume用于存储数据。在实际生产环境中,还需要考虑数据的备份和恢复、监控和故障恢复等相关问题。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: mysql中order by的作用是什么