<p>Good afternoon, I have a question, I am new to Kubernetes and I need to connect to a DB that is outside of my cluster, I could only connect to the DB using the hostNetwork = true, however, this is not recommended, in this case there is a method to communicate with External DB?</p>
<p>I leave you the yaml that I am currently using, my pod contains one container that work with spring boot</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: find-complementary-account-info
  labels:
    app: find-complementary-account-info
spec:
  replicas: 2
  selector:
    matchLabels:
      app: find-complementary-account-info
  template:
    metadata:
      labels:
        app: find-complementary-account-info
    spec:
      hostNetwork: true
      dnsPolicy: Default
      containers:
      - name: find-complementary-account-info
        image:find-complementary-account-info:latest
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            memory: &quot;350Mi&quot;
          requests:
            memory: &quot;300Mi&quot;
        ports:
        - containerPort: 8081
        env:
        - name: URL_CONNECTION_BD
          value: jdbc:oracle:thin:@11.160.9.18:1558/DEFAULTSRV.WORLD
        - name: USERNAME_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: user_pers
        - name: PASSWORD_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: password_pers
              key: password_pers
---
apiVersion: v1
kind: Service
metadata:
  name: find-complementary-account-info
spec:
  type: NodePort
  selector:
    app: find-complementary-account-info
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30020
</code></pre>
<p>Anyone have an idea how to communicate with external DB? This is not a cloud cluster, it is OnPremise</p>

Cesar Justo
<p><code>hostNetwork</code> parameter is used for accessing pods from outside of the Cluster, you don't need that.</p>
<p>Pods from inside the Cluster can communicate externally because they are NATted. If not, something external prevent it, like a firewall or a missing routing.</p>
<p>The quicker way to find that is to ssh to one of your Kubernetes cluster nodes and try</p>
<pre><code>telnet 11.160.9.18 1558
</code></pre>
<p>Anyway that IP address seems a Public one, so you have to check your company firewall imho</p>
