ERROR 1045 (28000): Access denied for user 'root'@'1.0.0.7' (using password: YES) mysql in kubernetes

11/20/2021

I am running MySQL 8 on Kubernetes by using deployment, service and secret files which are given below. but getting access denied error. I tried all the StackOverflow solutions but did not work for me.

Note:- I am using service type as load balancer which is having external IP.

Please help me to solve this issue, if anyone has a solution context

My Kubernetes files are:-

apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  type: LoadBalancer
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
  namespace: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:8.0
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
apiVersion: v1
kind: Secret
metadata:
  name: mysql-pass
  namespace: mysql
type: kubernetes.io/basic-auth
stringData:
  password: cGFzc3dvcmQK

output:-

mysql -u root -ppassword -P 3306 -h 1.2.3.4
ERROR 1045 (28000): Access denied for user 'root'@'1.0.0.7' (using password: YES)
-- gaurav agnihotri
docker
kubernetes
mysql

1 Answer

11/20/2021
mysql -u root -pcGFzc3dvcmQK  -P 3306 -h 1.2.3.4

use your secret passowrd please

-- Abhishek Porwal
Source: StackOverflow