Connect from Kubernetes

This guide shows you how to connect to a database from your managed Kubernetes cluster.

We assume the following prerequisites:

  • A datacenter with id xyz-my-datacenter.

  • A private LAN with id 3 using the network

  • A database connected to LAN 3 with IP

  • A Kubernetes cluster with id xyz-my-cluster.

In this guide we use DHCP to assign IPs to node pools. Therefore, it is important that the database is in the same subnet that is used by the DHCP server.

To enable connectivity, you must connect the node pools to the private LAN in which the database is exposed:

ionosctl k8s nodepool create --cluster-id xyz-my-cluster --datacenter-id xyz-my-datacenter --lan-ids 3 --dhcp=true --name=my_nodepool

Wait for the node pool to become available. To test the connectivity let's create a pod that contains the Postgres tool pg_isready. If you have multiple node pools make sure to schedule the pod only the node pools that are attached to the additional LAN.

# pod.yaml
apiVersion: v1
kind: Pod
  name: connectivity-test
    role: connectivity-test
  - name: postgres
    image: postgres
    stdin: true
    tty: true
      - "/bin/bash"

Let's create the pod...

kubectl apply -f pod.yaml

... and attach to it.

kubectl attach -it connectivity-test
If you don't see a command prompt, try pressing enter.
root@connectivity-test:/# pg_isready -h - accepting connections

If everything works, we should see that the database is accepting connections. If you see connection issues, make sure that the node is properly connected to the LAN. To debug the node start a debugging container ...

kubectl debug node/$(kubectl get po connectivity-test -o jsonpath="{.spec.nodeName}") -it --image=busybox

... and follow the network troubleshooting guide.

Last updated