<p>I'm <a href="https://www.oreilly.com/library/view/kubernetes-up-and/9781492046523/?afsrc=1" rel="nofollow noreferrer">following theses instructions</a> (page 181) to create a persistent volume &amp; claim, a mysql replica set &amp; service. I specify mysql v5.6 in the yaml file for the replica set.</p>
<p>After viewing the log for the pod, it looks like it is successful. So then I</p>
<pre><code>kubectl run -it --rm --image=mysql --restart=Never mysql-client -- bash
mysql -h mysql -p 3306 -u root
</code></pre>
<p>It prompts me for the password and then I get this error:</p>
<pre><code>ERROR 1130 (HY000): Host '10.1.0.17' is not allowed to connect to this MySQL server
</code></pre>
<p>Apparently MySQL has a feature where it does not allow remote connections by default and I have to change the configuration files and I don't know how to do that inside a yaml file. Below is my YAML. How do I change it to allow remote connections?</p>
<p>Thanks</p>
<p>Siegfried</p>
<pre><code>cat &lt;&lt;END-OF-FILE | kubectl apply -f -
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: mysql
  # labels so that we can bind a Service to this Pod
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: tododata
        image: mysql:5.6
        resources:
          requests:
            cpu: 1
            memory: 2Gi
        env:
        # Environment variables are not a best practice for security,
        # but we're using them here for brevity in the example.
        # See Chapter 11 for better options.
        - name: MYSQL_ROOT_PASSWORD
          value: some-password-here
        livenessProbe:
          tcpSocket:
            port: 3306
        ports:
        - containerPort: 3306
        volumeMounts:
          - name: tododata
            # /var/lib/mysql is where MySQL stores its databases
            mountPath: &quot;/var/lib/mysql&quot;
      volumes:
      - name: tododata
        persistentVolumeClaim:
          claimName: tododata
END-OF-FILE
</code></pre>
<p><strong>Sat Oct 24 2020 3PM EDT Update: Try Bitnami MySQL</strong></p>
<p>I like Ben's idea of <a href="https://bitnami.com/stack/mysql/helm" rel="nofollow noreferrer">using bitnami mysql</a> because then I don't have to create my own custom docker image. However, when using bitnami and trying to connect to they mysql server I get</p>
<pre><code>ERROR 2003 (HY000): Can't connect to MySQL server on 'my-release-mysql.default.svc.cluster.local' (111)
</code></pre>
<p>This happens after I successfully get a bash shell with this command:</p>
<pre><code>kubectl run my-release-mysql-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.22-debian-10-r0 --namespace default --command -- bash
</code></pre>
<p>Then, as per the instructions, I do this and get the HY000 error above.</p>
<pre><code>mysql -h my-release-mysql.default.svc.cluster.local -uroot -p
</code></pre>
<p><em><strong>Wed Nov 04 2020 Update:</strong></em></p>
<p>Thanks Ben.. Yes -- I had already tried that on Oct 24 (approx) and when I do a <code>k describe pod</code> I get <code>mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/opt/bitnami/mysql/tmp/mysql.sock' (2)' Check that mysqld is running and that the socket: '/opt/bitnami/mysql/tmp/mysql.sock' exists!</code>.</p>
<p>Of course, when I run the mysql client as described in the nicely generated instructions, the client cannot connect because mysqld has died.</p>
<p>This is after having deleted the pvcs and stss  and doing <code>helm delete my-release</code> prior to reinstalling via helm.</p>
<p>Unfortunately, when I tried this the first time (a couple of weeks ago) I did not set the root password and used the default generated password and I think it is still trying to use that.</p>
<p>This did work on azure kubernetes after having created a fresh azure kubernetes cluster.  How can I reset my kubernetes cluster in my docker for desktop windows? I tried google searching and no luck so far.</p>
<p>Thanks
Siegfried</p>

<p>After a lot of help from the bitnami folks, I learned that my spinning disks on my 4 year old notebook computer are kinda slow (now why this is a problem with Bitnami MySQL and not Bitnami PostreSQL is a mystery).</p>
<p>This works for me:</p>
<pre><code>helm install my-mysql bitnami/mysql \
  --set image.debug=true \
  --set primary.persistence.enabled=false,secondary.persistence.enabled=false \
  --set primary.readinessProbe.enabled=false,primary.livenessProbe.enabled=false \
  --set secondary.readinessProbe.enabled=false,secondary.livenessProbe.enabled=false
</code></pre>
<p>This turns off the peristent volumes so the data is lost when the pod dies.</p>
<p>Yes this is useful for me for development purposes and no one should be using Docker For Desktop/Kubernetes for production anyway... I just need to populate a tiny database and test my queries and if I need to repopulate database every time I reboot, well, that is not a big problem.</p>
<p>So maybe I need to get a new notebook computer? The price of notebook computers with 4TB of spinning disk space has gone up in the last couple of years.... And I cannot find any SSD drives of that size so even if I purchased a new replacement with spinning disks I might have the same problem? Hmm....</p>
<p>Thanks everyone for your help!</p>
<p>Siegfried</p>
