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 10.1.1.0/24.

  • A database connected to LAN 3 with IP 10.1.1.5/24.

  • 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
metadata:
  name: connectivity-test
  labels:
    role: connectivity-test
spec:
  containers:
  - name: postgres
    image: postgres
    stdin: true
    tty: true
    command:
      - "/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 10.1.1.5
10.1.1.5:5432 - 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

Revision created

commented latest release