<p>I wanted to deploy Strapi CMS to Kubernetes. On my local machine, I am trying to do this with Minikube. The structure of the project is MySQL in a different container outside of the cluster. I want to access the MySQL database from inside the cluster via this IP <code>172.17.0.2:3306</code></p>
<p>The Database is outside of the cluster and lives in a docker container. But the Strapi project lives in a cluster of Kubernetes.</p>
<p>This is my deployment YAML file for doing the Kubernetes stuff:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: cg-api
spec:
  selector:
    matchLabels:
      app: cg-api
  replicas: 2
  template:
    metadata:
      labels:
        app: cg-api
    spec:
      containers:
        - name: cg-api
          image: alirezahd/cg-api
          env:
            - name: DATABASE_HOST
              value: &quot;172.17.0.2&quot;
            - name: DATABASE_PORT
              value: &quot;3306&quot;
          ports:
            - containerPort: 1337

</code></pre>

<p>First of all you should expose MySQL port 3306 to outside of a container.
Assume host, on which Docker runs MySQL container, has 192.168.0.100 IP address. Then you can <strong>telnet 192.168.0.100:3306</strong> to be sure port is exposed and available.</p>
<p>Here is an example from <a href="https://docs.docker.com/engine/reference/commandline/run/" rel="nofollow noreferrer">Dockers documentation</a> :</p>
<pre><code>docker run -p 192.168.0.100:3306:3306/tcp mysql-container-name bash
</code></pre>
<p>This binds port 3306 of the container to TCP port 3306 on 192.168.0.100 of the host machine.</p>
<p>Then you CMS can connect to it within minikube.</p>
<p>Try to deploy <strong>dnsutils</strong> under minikube. It provides network tools like nslookup, telnet etc. It very helps to resolve network issues within minikube. You can connect to it <code>sudo kubernetes exec -it dnsutils -n default -- bash</code>.</p>
