Skip to content

Instantly share code, notes, and snippets.

@psviderski
Last active April 15, 2026 09:32
Show Gist options
  • Select an option

  • Save psviderski/db7f2ba13d5f203edcefb5096c0968a7 to your computer and use it in GitHub Desktop.

Select an option

Save psviderski/db7f2ba13d5f203edcefb5096c0968a7 to your computer and use it in GitHub Desktop.
MariaDB Galera cluster PoC deployment using Uncloud

MariaDB Galera Cluster PoC with Uncloud

Install Uncloud CLI locally firts: https://uncloud.run/docs/getting-started/install-cli

# Create a 3-machine Uncloud cluster
uc machine init -n machine1 root@server1
uc machine add -n machine2 root@server2
uc machine add -n machine3 root@server3

# Deploy the first bootstrap node
uc deploy --profile bootstrap galera1-bootstrap

# Deploy galera2 and galera3 services and wait for them to form the cluster
uc deploy galera2 galera3

# Remove the bootstrap node (using --wsrep-new-cluster) and replace it with a normal one
uc rm galera1-bootstrap
# Deploy all services, including the missing galera1
uc deploy

# Test on any node, e.g. galera1
uc exec galera1 mariadb -u root -psecret-password -e "
SELECT * FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME IN ('wsrep_cluster_size', 'wsrep_cluster_status', 'wsrep_ready', 'wsrep_connected')
ORDER BY VARIABLE_NAME;"
+----------------------+----------------+
| VARIABLE_NAME        | VARIABLE_VALUE |
+----------------------+----------------+
| WSREP_CLUSTER_SIZE   | 3              |
| WSREP_CLUSTER_STATUS | Primary        |
| WSREP_CONNECTED      | ON             |
| WSREP_READY          | ON             |
+----------------------+----------------+

Now, your Uncloud services are able to communicate with the Galera Cluster via any of its nodes by using galera1:3306, galera2:3306, or galera3:3306 addresses. You can also deploy a Galera Load Balancer or HAProxy in front of the nodes to provide a single endpoint to the cluster.

services:
galera1-bootstrap:
image: mariadb:12
# This service is used only to bootstrap the cluster.
command: --wsrep-new-cluster
environment:
MYSQL_ROOT_PASSWORD: secret-password
configs:
- source: galera1-conf
target: /etc/mysql/conf.d/galera.cnf
volumes:
- galera1-data:/var/lib/mysql
# Place the service on machine1
x-machines: machine1
profiles:
- bootstrap
galera1:
image: mariadb:12
environment:
MYSQL_ROOT_PASSWORD: secret-password
configs:
- source: galera1-conf
target: /etc/mysql/conf.d/galera.cnf
volumes:
- galera1-data:/var/lib/mysql
# Place the service on machine1
x-machines: machine1
galera2:
image: mariadb:12
environment:
MYSQL_ROOT_PASSWORD: secret-password
configs:
- source: galera2-conf
target: /etc/mysql/conf.d/galera.cnf
volumes:
- galera2-data:/var/lib/mysql
# Place the service on machine2
x-machines: machine2
galera3:
image: mariadb:12
environment:
MYSQL_ROOT_PASSWORD: secret-password
configs:
- source: galera3-conf
target: /etc/mysql/conf.d/galera.cnf
volumes:
- galera3-data:/var/lib/mysql
# Place the service on machine3
x-machines: machine3
configs:
galera1-conf:
file: ./galera1.cnf
galera2-conf:
file: ./galera2.cnf
galera3-conf:
file: ./galera3.cnf
volumes:
galera1-data:
galera2-data:
galera3-data:
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Cluster Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_galera_cluster"
wsrep_cluster_address="gcomm://galera1-bootstrap,galera1,galera2,galera3"
wsrep_node_address="galera1"
wsrep_node_name="galera1"
# SST Configuration
wsrep_sst_method=mariabackup
wsrep_sst_auth=root:secret-password
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Cluster Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_galera_cluster"
wsrep_cluster_address="gcomm://galera1,galera2,galera3"
wsrep_node_address="galera2"
wsrep_node_name="galera2"
# SST Configuration
wsrep_sst_method=mariabackup
wsrep_sst_auth=root:secret-password
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Cluster Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_galera_cluster"
wsrep_cluster_address="gcomm://galera1,galera2,galera3"
wsrep_node_address="galera3"
wsrep_node_name="galera3"
# SST Configuration
wsrep_sst_method=mariabackup
wsrep_sst_auth=root:secret-password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment