0

I deployed a StatefulSet on Kubernetes (K3S actually). I used the following manifest:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
  namespace: dev
  labels:
    app: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  serviceName: database-svc
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: mysql-db
          image: mysql:8.0.30-debian
          ports:
            - name: tcp
              protocol: TCP
              containerPort: 3306
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: ROOT_PASSWORD
          volumeMounts:
            - name: mysql-data
              mountPath: /var/lib/mysql
  volumeClaimTemplates:
    - metadata:
        name: mysql-data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi

The other referenced resources exist (Service and Secret) and the pod is created correctly. But then I try to run the command kubectl exec -n dev -it mysql-0 -- mysql -u root -p, I insert the correct password and I get the error

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
command terminated with exit code 1

If I try to sh into the container and echo the MYSQL_ROOT_PASSWORD variable I get the password that I inserted without success.

What am I missing? How should I connect to the pod from command line?

Essay97
  • 648
  • 1
  • 9
  • 24
  • have you ever tried to log in with another user? I have a guess, but it's not quite right either, because you' re already using "localhost" to log in. – Schecher_1 Nov 29 '22 at 21:14
  • If you haven't already, take a look at this (https://stackoverflow.com/a/11216911/17158472) – Schecher_1 Nov 29 '22 at 21:19
  • I did not find the question you linked, thanks. I tried to deploy the StatefulSet with the other global variables suggested by the mysql docker image documentation in order to create another user and I still cannot log in, but I managed to create a standalone docker container with that same image and I can log in – Essay97 Nov 29 '22 at 21:54
  • Anyway, if you can think about a way I can delete the "anonymous" user when I do not have access to the database let me know – Essay97 Nov 29 '22 at 21:55
  • Wait, you can't log in? Then how do you know the password is correct? Maybe your password is not exactly what it should be. Whatever, but you can't log in via MySqlWorkbench or the shell? – Schecher_1 Nov 30 '22 at 13:06
  • Actually, I think I messed up with the volumes: if mysql container finds a database in /var/lib/mysql the new configuration does not apply. I probably deployed the StatefulSet and then deleted, but the PersistentVolume (as expected) did not got deleted. Deleting the PV and recreating did the trick – Essay97 Dec 01 '22 at 21:26
  • has the problem now been "solved"? – Schecher_1 Dec 01 '22 at 22:38
  • 1
    Yes it has been solved! – Essay97 Dec 02 '22 at 23:06

0 Answers0