<p>I have deployed in the IBM Cloud a MySQL Database and a Spring Boot Application with Kubernetes. MySQL database has a deployment and a service but it should not accessible in the outside that's way i gave him a cluster ip. But the Spring application is load balancing, because it should be visible from clients. My MySQL data source didn't work which i write in my spring data source. In local case i write there just localhost, but in the Cloud this doesn't work ? Has anybody a idea how that works ?</p>

<pre><code>Deployment file: 
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: db
  enviroment: test 
spec:
  selector:
    matchLabels:
      app: mysql
      enviroment: test
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
        enviroment: test
    spec:
      containers:
      - image: de.icr.io/test/mysql:5.7
        name: db
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: ************
        - name: MYSQL_USER
          value: ********
        - name: MYSQL_PASSWORD
          value: ***********
        - name: MYSQL_DATABASE
          value: *******
        ports:
        - containerPort: 3306
          name: db
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql   
      volumes:
         - name: mypvc
           persistentVolumeClaim:
           claimName: mysql-pv-claim
</code></pre>

<p>That is my services: </p>

<pre><code>apiVersion: v1
kind: Service 
metadata:
  name: mysqlservices 
spec:
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    app: mysql   
    enviroment: test
</code></pre>

<p>I know you will not need my perssistens volume claime but i send it.</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypvc
  labels:
   billingType: "monthly"
   region: eu-de
   zone: Frankfurt
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
  storageClassName: ibmc-file-bronze
</code></pre>

<p>And at last the Spring Boot datasource i don't know what i will write in the url for the connection. </p>

<pre><code> &lt;bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        primary="true"&gt;
        &lt;property name="driverClassName"
            value="com.mysql.jdbc.Driver" /&gt;
        &lt;property name="url"
            value="jdbc:mysql://db/nlfb?useSSL=false" /&gt;

        &lt;property name="username" value="*****" /&gt;
        &lt;property name="password" value="******" /&gt;
    &lt;/bean&gt;
</code></pre>

<p>kind regards and thanks for your help.</p>

Cosss
<p>You have to use the service name of Kubernetes Deployments. Which is releated to the particular deployment i.e. if you r servicename is db and it is placed on namespace dev then you have to write <code> dev.db</code></p>
