<p>I try to make simple Kubernetes Pods and Services with using minikube dashboard. First, I generate Kubernetes mysql Service with the following yaml.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: blog-db
  labels:
    app: blog-mysql
spec:
  containers:
  - name: blog-mysql
    image: mysql:latest
    env:
      - name: MYSQL_ROOT_PASSWORD
        value: password
      - name: MYSQL_PASSWORD
        value: password
      - name: MYSQL_DATABASE
        value: test
    ports:
      - containerPort: 3306

---
apiVersion: v1
kind: Service
metadata:
  name: blog-db-svc
spec:
  selector:
    app: blog-mysql
  ports:
  - name: mysql
    port: 3306
    protocol: TCP
    targetPort: 3306
  externalIPs:
  - 10.96.10.10
</code></pre>

<p>The mysql service is generated successfully. But my front-end application docker image is built with Spring Boot, so I have to assign the correct mysql connection url into application.properties file like below,</p>

<pre><code># ==============================================================
# = MySQL DataSource properties
# ==============================================================
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://10.96.10.10:3306/test?characterEncoding=utf8&amp;serverTimezone=Asia/Seoul
spring.datasource.username = root
spring.datasource.password = password
</code></pre>

<p>I type the ip address, 10.96.10.10 of the external ip of service resource into spring boot application.properties file. But the connection is not successful. I checked the mysql service properties with the kubectl cli command,</p>

<pre><code>&gt; kubectl get svc
NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
blog-db-svc   ClusterIP   10.104.29.31   10.96.10.10   3306/TCP   30m
kubernetes    ClusterIP   10.96.0.1      &lt;none&gt;        443/TCP    2d
</code></pre>

<p>And I insert every ip addresses into application.properties of my docker container. But every effort of mysql connection is failed. How can the correct external ip be set on kubernetes service resource for mysql connection?</p>

Joseph Hwang
<p>If both the mysql and spring boot app running inside the kubernetes cluster then you don't use external IP to connect to mysql from spring boot app.<strong>External IP is for accessing something running inside kubernetes from outside kubernetes</strong>. You can use <code>servicename:port</code> i.e <code>blog-db-svc:3306</code> to refer to mysql from spring boot app if they are both running in same namespace.
If mysql and spring boot app are in different namespace then you can create a local service in the spring boot app namespace to refer to mysql service located in different namespace.</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: service-y
  namespace: namespace-a
spec:
  type: ExternalName
  externalName: service-x.namespace-b.svc.cluster.local
  ports:
  - port: 3306
</code></pre>

<p>Here is a <a href="https://www.callicoder.com/deploy-spring-mysql-react-nginx-kubernetes-persistent-volume-secret/" rel="nofollow noreferrer">guide</a> on how to use mysql with spring boot in minikube.</p>
