<p>Hiii!!!</p>
<p>i have deployed to Kubernetes keyrock, apache and mysql..</p>
<p>After i used the hpa and my stateful database scaled up, i can't login to my simple site..
This is my sql code:</p>
<pre><code>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 #50
              cpu: 50m
            limits:
                memory: 500Mi #220?
                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 # MARK P
                  key: password
            - name: MYSQL_ROOT_HOST
              valueFrom:
                secretKeyRef:
                  name: mysql-secret # MARK P
                  key: host                  
  volumeClaimTemplates:
    - metadata:
        name: mysql-storage
      spec:
        accessModes:
            - ReadWriteOnce
        storageClassName: standard #?manual
        resources:
            requests:
                storage: 5Gi
</code></pre>
<p>And it's headless service:</p>
<pre><code># Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql  #x-app  #
spec:
  ports:
  - name: mysql
    port: 3306
  clusterIP: None
  selector:
    app: mysql  #x-app


       
</code></pre>
<p>Anyone can help me?</p>
<p>I'm using gke.. Keyrock and apache are deployments and mysql is statefulset..</p>
<p>Thank you!!</p>

<p>You can't just scale up a Standalone database. Using HPA for stateless application works but not for stateful applications like a database.</p>
<p>Increasing replica of your StaetefulSet will just create another pod with a new MySQL instance. This new replica isn't aware of the data in your old replica.  Basically, you now have completely two different databases. That's why you can't login after scaling up. When your request get routed to the new replica, this instance does not have the user info that you created in the old replica.</p>
<p>In this case, you should deploy your database in clustered mode. Then, you can take advantage of horizontal scaling.</p>
<p>I recommend to use a database operator like <a href="https://github.com/mysql/mysql-operator" rel="nofollow noreferrer">mysql/mysql-operator</a>, <a href="https://github.com/presslabs/mysql-operator" rel="nofollow noreferrer">presslabs/mysql-operator</a>, or <a href="https://kubedb.com/" rel="nofollow noreferrer">KubeDB</a> to manage your database in Kubernetes. Out of these operators, KubeDB has autoscaling feature. I am not sure that other operators provide this feature.</p>
<p><strong>Disclosure:</strong> I am one of the developer of KubeDB operator.</p>
