-1

我在 gke 上有一个带有 apache、mysql 和 keyrock 的集群,我想用水平 pod autoscaler 扩展它。

对于mysql ,我使用的是statefulset,代码在这里:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  serviceName: mysql
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:5.7.21
          imagePullPolicy: Always
          resources:
            requests:
              memory: 50Mi 
              cpu: 50m
            limits:
                memory: 500Mi 
                cpu: 400m #65  
          ports:
          - containerPort: 3306
            name: mysql
          volumeMounts:
            - name: mysql-storage
              mountPath: /var/lib/mysql
              subPath: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret 
                  key: password
            - name: MYSQL_ROOT_HOST
              valueFrom:
                secretKeyRef:
                  name: mysql-secret 
                  key: host                  
  volumeClaimTemplates:
    - metadata:
        name: mysql-storage
      spec:
        accessModes:
            - ReadWriteOnce
        storageClassName: standard 
        resources:
            requests:
                storage: 5Gi

mysql服务代码:

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql  
spec:
  ports:
  - name: mysql
    port: 3306
  clusterIP: None
  selector:
    app: mysql  


           

问题: hpa扩容mysql数据库时,第二个replica的,不知道怎么同步2个replica!

有任何想法吗?

4

2 回答 2

1

默认情况下,StatefulSet 不会处理复制问题。

You will have to resort to MySQL kubernetes operator that handles application specific logic such as the one you are seeking for.

https://github.com/mysql/mysql-operator

于 2021-09-25T18:53:19.560 回答
0

默认 kubernetes pod 创建,而不是在缩放的 pod 之间同步数据。您可以使用 kubernetes 初始化容器或公共存储或任何脚本来执行此操作

于 2021-09-25T17:39:38.910 回答