> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/databases/mariadb/api/v1-api/connect-mariadb-kubernetes.md).

# Connect from Kubernetes

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

## Prerequisites

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 `10.1.1.0/24`.
* A database connected to `LAN 3` with the following IP address: `10.1.1.5/24`.
* A Kubernetes cluster with the following `id`: `xyz-my-cluster`.
* [`ionosctl`](https://github.com/ionos-cloud/ionosctl)

## 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:

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

{% hint style="info" %}
**Note:** It may take a while for the node pool to be ready.
{% endhint %}

2. 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.

```bash
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: connectivity-test
  labels:
    role: connectivity-test
spec:
  containers:
  - name: connectivity-test
    image: mysql
    stdin: true
    tty: true
    command:
      - "/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:

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

{% hint style="success" %}
**Result:** The database starts accepting connections.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/databases/mariadb/api/v1-api/connect-mariadb-kubernetes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
