Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Debian 10 - Set Up MariaDB Database For Kubernetes

Below are the steps I used to set up a database server for my Kubernetes cluster.

It's not ideal that it is a single databaase server, and not a database cluster for high availability (HA), but it will do for now. When I have a tutorial explaining how to set up a database cluster for HA, I will link to that, but for now, here is an alternative tutorial if you have to have HA.

Resources

For my setup, I am using a VPS with 1 GB of RAM and 2 vCPUs.

Steps

sudo apt-get install mariadb-server -y

This will install MariaDB 10.3.29 at the time of writing this post.

Log into the database as the root user.

sudo mysql

Create a database for kubernetes to use.

CREATE DATABASE kubernetes;

Create a user for Kubernetes to connect to the database with:

CREATE USER 'kubernetes' IDENTIFIED BY 'strongRandomPasswordHere';

Now give the Kubernetes user full access to the Kubernetes database:

GRANT ALL ON kubernetes.* to kubernetes;

Now you are all done, exit the MariaDB CLI interface:

exit;

Allow Remote Access

By default, MariaDB only allows local connections, and does not listen to the outside world. We need to change this so that our Kubernetes servers can connect. Copy and paste the following commands which will update the server configuration for you so that the database will listen to the outside world by commenting out the bind address.

SEARCH="bind-address            = 127.0.0.1"
REPLACE="#bind-address            = 127.0.0.1"
FILEPATH="/etc/mysql/mariadb.conf.d/50-server.cnf"
sudo sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

Now restart the database service for the changes to take effect:

sudo service mysql restart
Last updated: 23rd June 2021
First published: 23rd June 2021