Connect from Kubernetes

This topic describes connecting to MariaDB from your managed Kubernetes cluster.


Ensure that the following are available before connecting to the database:

  • A datacenter with the following id: xyz-my-datacenter.

  • A private LAN with id 3 using the network

  • A database connected to LAN 3 with the following IP address:

  • A Kubernetes cluster with the following id: xyz-my-cluster.

Connect to the database from the cluster

In this example, we use DHCP to assign IP addresses to node pools. Therefore, the database must be in the same subnet as the DHCP server.

To enable connectivity, follow these steps:

  1. Connect node pools to the private LAN, which is connected to the database:

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

Note: It may take a while for the node pool to be ready.

  1. Create a pod to test the connectivity. Schedule the pod exclusively for the node pools connected to the additional LAN if you have several node pools.

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

Alternatively, you can also use the following commands:

  1. Create the pod: kubectl apply -f pod.yaml

  2. Attach the pod and test connectivity:

kubectl attach -it connectivity-test
mysql -u <USERNAME> -p -h <DNS_NAME> --execute \"SHOW DATABASES;\"

Result: The database starts accepting connections.

Last updated