1

I was following the Run a Single-Instance Stateful Application tutorial of Kubernetes (I changed the MySQL docker image's tag to 8), and it seems the server is running correctly: enter image description here

But when I try to connect the server as the tutorial suggesting:

kubectl run -it --rm --image=mysql:8 --restart=Never mysql-client -- mysql -h mysql -ppassword

I get the following error:

ERROR 1045 (28000): Access denied for user 'root'@'10.1.0.99' (using password: YES) pod "mysql-client" deleted


I already looked at those questions:

But changing the mountPath or port didn't work.

1 Answer 1

1

Default behavior of root account can only be connected to from inside the container. Here's an updated version of the example that allows you to connect from remote:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:8.0.26
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: password
        - name: MYSQL_ROOT_HOST
          value: "%"
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        emptyDir: {}
        # Following the original example, comment the emptyDir and uncomment the following if you have StorageClass installed.
        # persistentVolumeClaim:
        #  claimName: mysql-pv-claim

No change to the client connect except for the image tag:

kubectl run -it --rm --image=mysql:8.0.26 --restart=Never mysql-client -- mysql -h mysql -ppassword

Test with show databases;:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately, I still get the same error: ERROR 1045 (28000): Access denied for user 'root'@'10.1.0.111' (using password: YES) pod "mysql-client" deleted pod default/mysql-client terminated (Error). Maybe something to do with the PersistentVolumes? I'm not sure I correctly understood this requirement: You need to either have a dynamic PersistentVolume provisioner with a default StorageClass, or statically provision PersistentVolumes yourself to satisfy the PersistentVolumeClaims used here.
The updated answer allows you to switch storage.
The updated answer is working thank you! But can you please explain what the value "%" for the host means? And maybe refer me to how to install a StorageClass?
It means all hosts are allowed to connect, the value can be in CIDR format, too. You can start here and setup the StorageClass that suit your infra.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.