title: Mysql access denied when it runs in Kubernetes pod
body: <p>I'm setting up a K8s cluster and I started with the database. I used Kustomize for that purpose. I use Kubernetes that comes in with Docker Desktop for Windows 10.</p>
  
  <p>When I run <code>kubectl apply -k ./</code>, the mysql pods are running.
  Then I use <code>kubectl exec -it mysql -- bash</code> to get inside the container.
  Once in there, I try to connect to MySQL service with <code>mysql -u root -p</code> and all I get is</p>
  
  <pre><code>ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  </code></pre>
  
  <p>It doesn't matter if I use <code>secretGenerator</code> in <code>kustomization.yaml</code> or put the root password directly in the deployment definition, I can't log in to mysql.
  I'm using mysql image from docker hub, so nothing fancy.</p>
  
  <p>I also did a test with running the container directly by docker, e.g.</p>
  
  <pre><code>docker run -d --env MYSQL_ROOT_PASSWORD=dummy --name mysql-test -p 3306:3306 mysql:5.6
  </code></pre>
  
  <p>Having container set up like this I can log in to the MySQL database without a problem.</p>
  
  <p>I don't understand why the same image ran in docker behaves differently when ran in Kubernetes.
  Maybe you have any ideas?</p>
  
  <p>My yaml files look like this:</p>
  
  <p>storage.yaml</p>
  
  <pre><code>kind: StorageClass
  apiVersion: storage.k8s.io/v1
  metadata:
    name: local-storage
  provisioner: kubernetes.io/no-provisioner
  volumeBindingMode: WaitForFirstConsumer
  </code></pre>
  
  <p>mysql-persistent-volume.yaml</p>
  
  <pre><code>apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: mysql-pv
  spec:
    storageClassName: local-storage
    persistentVolumeReclaimPolicy: Retain
    capacity:
      storage: 1Gi
    accessModes:
      - ReadWriteOnce
    local:
      path: "/c/kubernetes/mysql-storage/"
    nodeAffinity:
      required:
        nodeSelectorTerms:
          - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
              - docker-desktop
  ---
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: mysql-pv-claim
  spec:
    storageClassName: local-storage
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
  </code></pre>
  
  <p>mysql-deployment.yaml</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: mysql
    labels:
      app: mysql
  spec:
    type: NodePort
    ports:
      - port: 3306
        protocol: TCP
        name: mysql-backend
    selector:
      app: mysql
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: mysql
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: mysql
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: mysql
      spec:
        containers:
          - image: mysql:5.6
            name: mysql
            imagePullPolicy: IfNotPresent
  #          envFrom:
  #          - secretRef:
  #              name: mysql-credentials
            env:
              - name: MYSQL_ROOT_PASSWORD
                value: dummy
            ports:
              - containerPort: 3306
                name: mysql
            volumeMounts:
              - name: mysql-persistent-storage
                mountPath: /var/lib/mysql
        volumes:
          - name: mysql-persistent-storage
            persistentVolumeClaim:
              claimName: mysql-pv-claim
  </code></pre>
  
  <p>kustomization.yaml</p>
  
  <pre><code>resources:
    - storage.yaml
    - mysql-persistent-volume.yaml
    - mysql-deployment.yaml
  generatorOptions:
    disableNameSuffixHash: true
  secretGenerator:
    - name: mysql-credentials
      literals:
        - MYSQL_ROOT_PASSWORD=dummy
  #      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
  </code></pre>