Ruben's Blog | ีีธึีขีฅีถีซ ิฒีฌีธีฃีจ
๐ ..Dockerized Mysql Cluster With Swarm ๐๐ณ๐
Docker Swarm is a good choice for smaller and simpler Dockerized MySQL clusters due to its ease of use and compatibility with Docker. On the other hand, Kubernetes offers advanced features and scalability for larger and more complex deployments, but requires a higher level of knowledge and infrastructure. Ultimately, choose the best option based on your application’s specific needs.
In this article, we’ll explore the deployment of a 3-node InnoDB cluster using Docker Swarm. The cluster will consist of three MySQL nodes, each running on a separate server. We’ll take a deep dive into the process of setting up Docker Swarm, configuring the MySQL nodes, and deploying the cluster. By the end of this article, you’ll have a solid understanding of how to use Docker Swarm to deploy a MySQL cluster, and you’ll be ready to tackle similar projects on your own.
๐จ Be careful when using Dockerized databases! ๐จ
๐ฅ Containers can be a fire hazard if not properly secured, leading to potential data loss or breaches.
For our deployment of the 3-node InnoDB cluster using Docker Swarm, we have two main strategies to consider for setting up the necessary directories.
- The first strategy involves configuring NFS on any number of machines and adding one more server for NFS.
- The second strategy involves creating dedicated directories for each server we will use, and forcing Docker to run on the servers we want to make it replicate bare metal deployment.
For our purposes, we’ll be using the second strategy. This approach will allow us to have more control over the deployment, and ensure that each server has its own dedicated directory for the MySQL data. Let’s take a closer look at the steps involved in this approach.
Note about env vars
To distribute environment variables to all containers in a Docker Swarm cluster, you should embed them in the Docker Compose file. This is necessary because environment files are not distributed across all nodes in the cluster.
This is not very elegant but we will get back to this in another post probably.
repo with source codes example
Please pull the repository from here https://github.com/shekspir55/mysql-docker-compose-examples
less talk more work
create directories in the servers
mkdir /mysql-data
docker swarm init
Follow instructions to set up secondary swarm instances.
Add labels to swarm nodes, this is needed to force nodes to run on the swarm nodes we want.
# take ids from the output to input in the commands below
docker node ls
#for master swarm instance
docker node update --label-add type=leader ID-GOES-HERE
#for master secondary instances
docker node update --label-add type=mysql-worker-2 ID-GOES-HERE
#for master secondary instances
docker node update --label-add type=mysql-worker-3 ID-GOES-HERE
docker stack deploy -c ./docker-compose.yml cluster
to debug docker swarm if something goes wrong and node doesn’t start
docker service ls
- to get all services which are suppose to run.
docker service ps --no-trunc ID-OF-CONTAINER-NOT-STARTING
now check mysql-shell logs for results
โญ๏ธ read next: Tips on troubleshooting Docker Image build, Compose and Swarm issues ๐ณ๐ณ๐ณ
references:
Please give me feedback, comment on whatever you think about my blog post, and help me improve. โค๏ธ
Blog Menu
- ๐ผ hire my consultancy
- โน๏ธ about me
- ๐ฐ rss
- ๐ธ a young blog
- ๐ blog
- 2024-11-15
What Would You Do if It Wasn't for Money? ๐ฑ
What is money? For some it’s freedom. Freedom of choice. For me it’s an equivalent of “ability”. It’s like the magic wan...
- 2024-11-12
First, Rewrite๐
I start to see patterns. I start to see how people work. Not sure how deep I see. I don’t want to exploit people. I don’t want to MAKE peo...
- 2024-11-11
It's Not About Sales ๐๐ป
For me it’s always about how can I help people, if I can’t or if my help is insufficient I would not push. I will push to know the reason ...
- 2024-11-09
Push Push Push Breathe ๐ฌ๏ธ
Am I pushing enough? Am I breathing enough? I do :) There is never enough, there is always enough. Having multiple heats it’s hard to find a bal...
- 2024-11-08
Am I Productive? ๐งจ
Do you feel I’m productive? Are you productive? Is productive about fast results? Is productive about the process? I’m not sure anymore, b...
- 2024-11-07
One Week Later โ๏ธ
Last week was awful, I didn’t have time to breathe. This week is not much better. But we have progress. I have about 3k impressions in 2 days on...
- 2024-10-28
Engineering Solution to Every Problem โ๏ธ
As an engineer, I strive to find engineering solutions to every problem surrounding me, engineering doesn’t mean technical in this case. There a...
- 2024-10-27
I'm Going to Invest in Podcasting More ๐ค
Podcasting is discovery It’s listening to so many familiar and different ideas and being able to ask questions, where people can answer you live...
- 2024-10-26
Scooping Motivation ๐ฆ๐ฉ
For me, motivation is being on the edge. I need to feel that what I do is important to do, at that exact moment. (Probably because of my ADHD) There i...
- 2024-10-24
Reflection on My Journey ๐ญ
You can recover your journey from the history of my blog posts if you have been following, though you also probably know that I don’t need peopl...
- See all...
- ๐ links