<p>I was following the <a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="nofollow noreferrer">Run a Single-Instance Stateful Application</a> tutorial of Kubernetes (I changed the MySQL docker image's tag to 8), and it seems the server is running correctly:
<a href="https://i.stack.imgur.com/NztJs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NztJs.png" alt="enter image description here" /></a></p>
<p>But when I try to connect the server as the tutorial suggesting:</p>
<pre><code>kubectl run -it --rm --image=mysql:8 --restart=Never mysql-client -- mysql -h mysql -ppassword
</code></pre>
<p>I get the following error:</p>
<blockquote>
<p>ERROR 1045 (28000): Access denied for user 'root'@'10.1.0.99' (using password: YES)
pod &quot;mysql-client&quot; deleted</p>
</blockquote>
<hr />
<p>I already looked at those questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/65460113/cant-access-mysql-root-or-user-after-kubernetes-deployment">Can't access mysql root or user after kubernetes deployment</a></li>
<li><a href="https://stackoverflow.com/questions/64205150/access-mysql-kubernetes-deployment-in-mysql-workbench">Access MySQL Kubernetes Deployment in MySQL Workbench</a></li>
</ul>
<p>But changing the <code>mountPath</code> or <code>port</code> didn't work.</p>

<p>Default behavior of <code>root</code> 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:</p>
<pre><code>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: &quot;%&quot;
        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
</code></pre>
<p>No change to the client connect except for the image tag:</p>
<p><code>kubectl run -it --rm --image=mysql:8.0.26 --restart=Never mysql-client -- mysql -h mysql -ppassword</code></p>
<p>Test with <code>show databases;</code>:</p>
<pre><code>mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
</code></pre>
