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-12-29
Then the Journey Is Not About Winning ποΈ
Winning is the target, but the journey is never about winning. You cannot be sure the path is correct. Even with guidance, there is a chance it’...
- 2024-12-28
Free Consultancy ππ»
Nobody buys it. When I provide it everyone is happy. Why? Maybe people don’t understand the offer, which is completely understandable. What I of...
- 2024-12-28
The Algorithm of the Dressings π₯¬βπ₯ββοΈπ°π₯
Martun said he read many books about healthy food and didn’t become healthy. I agree, that reading and doing is very different. But I think that...
- 2024-12-25
Powered.community Meetup π€π»
Well, it happened. The food was sushi, and people came with friends, some just checking in. I was so glad to see so many people I know and don’t...
- 2024-12-23
5 Books to Read Before 2025 to Transform Your Life ποΈ
People are not computers, though we share traits such as short and long-term memory or processing power. You cannot install a “software” o...
- 2024-12-21
Ikigai π₯
Opportunities come and go, but sometimes there is THAT opportunity. It makes my heart sing, puts me in sync with what I live for, and creates purpose ...
- 2024-12-19
Piece Is Pressure
We are not in a hot war right now, but it’s always over the corner. Many countries are in hot wars at this moment, what do they tell us? What wo...
- 2024-12-17
I Met My Mentor π¦
My mentor probably doesn’t know she is my mentor. And I understood some things. I did a lot of analysis. She told me about the start stop and co...
- 2024-12-17
I'm Still Learning π
I find myself suggesting the right solutions, right for me. And when I see that the pattern doesn’t match, I get sad. It’s hard to acknowl...
- 2024-12-13
Rushing the Process Doesn't Help βοΈ
I’ve started too late, because of that I have more knowledge from the field. I have been learning these past 4 years, but starting something by ...
- See all...
- π links