Debian 10 - Set Up MariaDB Database For Kubernetes
Below are the steps I used to set up a database server for my Kubernetes cluster.
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
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
First published: 23rd June 2021