title: Access external database from Kubernetes
body: <p>I have a kubernetes (v1.18.6) with 1 service (loadbalancer), 2 pods in a develoment:</p>
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: app-service
  spec:
    selector:
      app: app
    ports:
    - protocol: &quot;TCP&quot;
      port: 6000
      targetPort: 5000
    type: LoadBalancer
  </code></pre>
  <p>A network policy to access Intenert (it is necesary for me):</p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: NetworkPolicy
  metadata:
    name: internet-access
  spec:
    podSelector:
      matchLabels:
        networking/allow-internet-access: &quot;true&quot;
    policyTypes:
    - Ingress
    - Egress
    ingress:
    - {}
  </code></pre>
  <p>Deployment config file</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: app-deployment
  spec:
    progressDeadlineSeconds: 120
    selector:
      matchLabels:
        app: app
    replicas: 2
    template:
      metadata:
        labels:
          app: app
      spec:
        imagePullSecrets:
          - name: myregistrykey
        containers:
        - name: app
          image: app
          imagePullPolicy: Always
          ports:
          - containerPort: 5000
  </code></pre>
  <p>It is working correctly. But now, I want to connect this imagen to an external database (in another network only access by internet). For this proposition I use this service:</p>
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: postgresql
  spec:
    clusterIP: None
    ports:
    - port: 25060
  
  
  ---
  apiVersion: v1
  kind: Endpoints
  metadata:
    name: postgresql
  subsets:
    - addresses:
          - ip: 206............
      ports:
        - port: 25060
          name: postgresql
  </code></pre>
  <p>It is all the services:</p>
  <pre><code>NAME                TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE
  app-service         LoadBalancer   10.245.134.137   206...........   6000:31726/TCP   2d4h
  kubernetes          ClusterIP      10.245.0.1       &lt;none&gt;           443/TCP          3d7h
  postgresql          ClusterIP      None             &lt;none&gt;           25060/TCP        19h
  </code></pre>
  <p>But when I try to connect I receive a timeout error of the database, like can't connect to the database.</p>
  <p>I have an internet connection in the image.</p>
  <p><strong>I find the solution, the problem was the rules of inbound of the database. I must add the IP of Kubernetes.</strong></p>
  <p>Thx.</p>