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 me
- βΉοΈ about me
- π° rss
- πΈ a young blog
- π blog
- 2024-10-19
The Meaning π¬οΈ
I wrote about this again, but investing time in meaningful connections is crucial. It’s not just spending; it’s a real investment. You can...
- 2024-10-18
Complexity in Multi-model Architectures π
I can move from cities and even to countries with a single backpack and or a single hanger with a couple of clothes, be able to attend the event, and ...
- 2024-10-18
Buying Problems π
I must always remember that buying into any relationship, be that business, employment, or personal once, you are always buying problems first. It&rsq...
- 2024-10-16
Every Company Is Different π€¦π»ββοΈ
Doing the podcasts I talk to different friends from tech and other industries. There are so many approaches, and so many different opinions, there is ...
- 2024-10-15
Lazy Art π¨
Art is something you do more not less, but what if you generate NFTS, is it lazy art? You do more but with code. Are you making more art? If you creat...
- 2024-10-14
Tribute to Mothers Part 3? π€±π»
Again I’m alone, this is hard. Though I don’t consider myself a passive father, being 2 parents is a bit much, and it’s hard as much...
- 2024-10-13
Weekends βοΈ
Yesterday, I spent the day picking pears and sleeping. Today, I spent the day caring for the baby and trying to rest; I can’t rest with a small ...
- 2024-10-12
I Fell Out of the Internet for Today π
My phone is broken and My current phone is a Banana Nokia. I spent half of the day sleeping and another half picking pears from the ground and cooking...
- 2024-10-11
Life Lessons π
My phone broke down so I couldn’t post shorts on YouTube, today I spent time running Android on my laptop. Well, Weydroid ran with a plain Andro...
- 2024-10-10
Podcasting Is Fun πͺ
But it’s hard work.:) You need to try to engage with the person you are doing a podcast with! It’s good but hard. Tomorrow I don’t h...
- See all...
- π links