Using MariaDB Kubernetes Operator

With MariaDB Kubernetes Operator installed and running with a particular topology for a replication cluster, ColumnStore, or standalone server, you can connect to the running instances and interact with them through the mysql client or your application.

Services Discovery

In order to connect to MariaDB Platform when it's running on Kubernetes, you need to first find the pod and domain name to target, both accessible through the kubectl utility. To find the pod to target, use kubectl with the get pods command.

$ kubectl get pods

NAME                                     READY   STATUS    RESTARTS   AGE
platform-tx-mdb-ms-0                    2/2     Running   0          7m13s
platform-tx-mdb-ms-1                    2/2     Running   0          5m30s
platform-tx-mdb-ms-2                    2/2     Running   0          4m26s
platform-tx-mdb-mxs-7cbcbdc6f5-6chtk    2/2     Running   0          7m12s
platform-tx-mdb-mxs-7cbcbdc6f5-8fqcw    2/2     Running   0          7m12s
platform-tx-mdb-state-f67db4bd6-b94zd   1/1     Running   0          7m12s

MariaDB Kubernetes Operator uses the release environment name as a prefix in naming containers and pods. Select the pod with prefix of the cluster you want and 0 for the first pod in that cluster. Here, given that it is a MariaDB Replication cluster named platform-tx, connect to the platform-tx-mdb-ms-0 pod.

Kubernetes uses an internal DNS to identify containers within the cluster. Rather than searching for IP addresses you can use the cluster domain name, which you may find useful when providing hostnames for authentication.

$ kubectl get svc -l entrypoint.mariadb

NAME                      TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)             AGE
platform-tx-mariadb       ClusterIP   None         <none>        4006/TCP,4008/TCP   30m

The specific port to use in connecting to the cluster varies depending on whether MariaDB MaxScale is used in your topologies.

  • 4006 for the MaxScale ReadWrite Listener
  • 4008 for the MaxScale ReadOnly Listener
  • 3306 for MariaDB Server and MariaDB ColumnStore User Modules

Testing Connectivity

Once you have the IP address and port number, you can test that MariaDB is running using kubectl and the mysql client to connect to the running cluster.

$ kubectl exec \
  -it platform-tx-mdb-ms-0 \
  -- mysql -uadmin -p5LVTpbGE2cGFtw69 \
  -P4006 -h platform-tx-mariadb 

The username and password should correspond to the server.users.admin.username and server.users.admin.password Kubernetes parameters.

Note: Applications deployed in the same namespace in Kubernetes can also access the cluster using the hostname <release-name>-mariadb.

Common Operations

Listing Clusters

MariaDB Kubernetes Operator includes a Custom Resource Definition (CRD), which provides some additional commands over what's available through the Helm Chart. Using the CRD you can use kubectl retrieve information on the running MariaDB clusters on Kubernetes.

$ kubectl get mariadb

NAME          AGE
platform-tx   9h

Listing Services

Kubernetes groups pods into logical units called services. Using kubectl, you can list the services available in your cluster.

$ kubectl get services

NAME                        TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)             AGE
kubernetes                  ClusterIP   10.96.0.1    <none>        443/TCP             34d
platform-tx-mariadb         ClusterIP   None         <none>        4006/TCP,4008/TCP   21d
platform-tx-mdb-clust       ClusterIP   None         <none>        3306/TCP            21d
platform-tx-mdb-state       ClusterIP   None         <none>        80/TCP              21d

Scaling Clusters at Runtime

Certain MariaDB Kubernetes Operator topologies allow you to scale the cluster up or down at runtime. This means you can add pods to the cluster to accommodate an increased read demand, then later remove them when the traffic goes back down. Kubernetes handles the database provisioning while MariaDB MaxScale balances the load between the pods.

To determine the name of the pods you add, use kubectl:

$ kubectl get pods

NAME                                    READY   STATUS    RESTARTS   AGE
platform-tx-mdb-ms-0                    2/2     Running   0          7m13s
platform-tx-mdb-ms-1                    2/2     Running   0          5m30s
platform-tx-mdb-ms-2                    2/2     Running   0          4m26s
platform-tx-mdb-mxs-7cbcbdc6f5-6chtk    2/2     Running   0          7m12s
platform-tx-mdb-mxs-7cbcbdc6f5-8fqcw    2/2     Running   0          7m12s
platform-tx-mdb-state-f67db4bd6-b94zd   1/1     Running   0          7m12s

Here, we have MariaDB Platform configured for replication with three pods running MariaDB Server and two running MaxScale. The replica name for the pods running MariaDB Servers is platform-tx-mdb-ms. Use this name when scaling the cluster for reads.

$ kubectl scale sts platform-tx-mdb-ms --replicas 5

Using the --replicas option you can define the number of replicas you want the cluster to run. Previously, it was running three replicas of platform-tx-mdb-ms. The above command changes this count to five. You can then use kubectl to check that the new replicas are available:

$ kubectl get pods

NAME                                    READY   STATUS    RESTARTS   AGE
platform-tx-mdb-ms-0                    2/2     Running   0          152m
platform-tx-mdb-ms-1                    2/2     Running   0          151m
platform-tx-mdb-ms-2                    2/2     Running   0          150m
platform-tx-mdb-ms-3                    2/2     Running   0          20m
platform-tx-mdb-ms-4                    2/2     Running   0          19m
platform-tx-mdb-mxs-7cbcbdc6f5-6chtk    2/2     Running   0          152m
platform-tx-mdb-mxs-7cbcbdc6f5-8fqcw    2/2     Running   0          152m
platform-tx-mdb-state-f67db4bd6-b94zd   1/1     Running   0          152m

As you can see, there are now five replicas of the pods running MariaDB Servers.

Note: Currently, the MariaDB ColumnStore topology does not allow runtime scaling.

Removing Clusters

In cases where you want to remove a cluster from your Kubernetes deployment, you can do so using kubectl.

$ kubectl delete platform-tx

This deletes the cluster by name from Kubernetes, but does not remove the name. In cases where you would like to reuse the cluster name, issue with the --purge option.

$ kubectl delete platform-tx --purge

Comments

Comments loading...