Skip to content

Instantly share code, notes, and snippets.

@psviderski
Last active September 4, 2025 09:20
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

# Until compose configs implemented: https://github.com/psviderski/uncloud/issues/43
# Manually copy galera1,2,3.cnf to /var/lib/docker/volumes/galera1,2,3-conf/_data/galera.cnf on machines
# Restart the galera1-bootstrap service to pick up the new config
uc deploy --profile bootstrap galera1-bootstrap --recreate

# 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 machine
docker exec -it galera1-li6p 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 if 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
volumes:
- galera1-conf:/etc/mysql/conf.d:ro
- 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
volumes:
- galera1-conf:/etc/mysql/conf.d:ro
- galera1-data:/var/lib/mysql
# Place the service on machine1
x-machines: machine1
galera2:
image: mariadb:12
environment:
MYSQL_ROOT_PASSWORD: secret-password
volumes:
- galera2-conf:/etc/mysql/conf.d:ro
- galera2-data:/var/lib/mysql
# Place the service on machine2
x-machines: machine2
galera3:
image: mariadb:12
environment:
MYSQL_ROOT_PASSWORD: secret-password
volumes:
- galera3-conf:/etc/mysql/conf.d:ro
- galera3-data:/var/lib/mysql
# Place the service on machine3
x-machines: machine3
volumes:
galera1-data:
galera1-conf:
galera2-data:
galera2-conf:
galera3-data:
galera3-conf:
[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