0% found this document useful (0 votes)
3 views48 pages

Docker PPT 2

Uploaded by

jyyyrq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views48 pages

Docker PPT 2

Uploaded by

jyyyrq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Welcome to

Docker Swarm
Scalability

Let us, for a moment take a step back and discuss why
we want to scale applications.
The main reason is high availability. Why do we want high
availability?
We want it because we want our business to be available
under any load.
The bigger the load, the better (unless you are under
DDoS). It means that our business is booming.
With high availability our users are happy.
Scalability

We all want speed, and many of us simply leave the site


if it takes too long to load.
We want to avoid having outages because every minute
our business is not operational can be translated into a
money loss.
What would you do if an online store is not available?
Probably go to another.
Maybe not the frst time, maybe not the second, but,
sooner or later, you would get fed up and switch it for
another.
Docker Swarm Mode

Docker Engine v1.12 was released in July 2016.


It is the most signifcant version since v1.9.
Back then, we got Docker networking that, fnally, made
containers ready for use in clusters.
With v1.12, Docker is reinventing itself with a whole new
approach to cluster orchestration.
Everything you’ll need to manage your cluster is now
incorporated into Docker Engine.
Docker Swarm Mode
Docker Swarm Mode
Setting Up a Swarm Cluster
Setting Up a Swarm Cluster

As of now we do not have docker-machine environment


, so we will create and confgure three machine manually
for Docker Swarm Cluster.
Setting Up a Swarm Cluster

Do the following on all nodes


]# wget
https://download.docker.com/linux/centos/docker-ce.repo
-O /etc/yum.repos.d/docker-ce.repo
]# yum repolist
]# yum install docker-ce -y
]# systemctl start docker ; systemctl enable docker
]# systemctl status docker
Setting Up a Swarm Cluster

Now enable swarm mode in Docker


Do the following on master Node:

[root@master ~]# docker swarm init --advertise-addr


192.168.191.128
Setting Up a Swarm Cluster

Now Join the Swarm Manager from node1 and node2

Do the following on node1 Node:


[root@node1 ~]# docker swarm join --token SWMTKN-1-
5t3u1sxz1lv38kj4uqqczinilqz40pkhv3verfbp79b3d44cdc-
7mvh1x2hg6x7uq0y5dql6zwls 192.168.191.128:2377
Do the following on node2 Node:
[root@node2 ~]# docker swarm join --token SWMTKN-1-
5t3u1sxz1lv38kj4uqqczinilqz40pkhv3verfbp79b3d44cdc-
7mvh1x2hg6x7uq0y5dql6zwls 192.168.191.128:2377
Setting Up a Swarm Cluster

List the nodes from Swarm Manager

[root@master ~]# docker node ls

We can get a token required for adding additional nodes


to the cluster by executing the following commands:
[root@master ~]# docker swarm join-token -q manager
[root@master ~]# docker swarm join-token -q worker
Setting Up a Swarm Cluster
Deploying Services To The Swarm
Cluster
Deploying Services To The Swarm
Cluster
Deploying Services To The Swarm
Cluster
Let’s start by deploying the mongo container somewhere
within the cluster.

[root@master ~]# docker service create --name go-demo-db


--network go-demo mongo:3.2.10
Deploying Services To The Swarm
Cluster
We can list all the running services.
[root@master ~]# docker service ls

[root@master ~]# docker service inspect go-demo-db

Now that the database is running, we can deploy the go-demo


container.
[root@master ~]# docker service create --name go-demo -e
DB=go-demo-db --network go-demo vfarcic/go-demo:1.0
Deploying Services To The Swarm
Cluster
[root@master ~]# docker service ls
Deploying Services To The Swarm
Cluster
Scaling Services

We should always run at least two instances of any given


service.
That way they can share the load and, if one of them fails,
there will be no downtime.
We can, for example, tell Swarm that we want to run fve
replicas of the go-demo service.
[root@master ~]# docker service scale go-demo=5
Deploying Services To The Swarm
Cluster
Scaling Services

We can confrm that, indeed, fve replicas are running


[root@master ~]# docker service ls
[root@master ~]# docker service ps go-demo
Deploying Services To The Swarm
Cluster
Failover

Fortunately, failover strategies are part of Docker Swarm.


Remember, when we execute a service command, we are not
telling Swarm what to do but the state we desire.
In turn, Swarm will do its best to maintain the specifed state
no matter what happens.
To test a failure scenario, we’ll powerof one of the nodes.

[root@node2 ~]# powerof


[root@master ~]# docker node ls
Failover

[root@master ~]# docker service ls


[root@master ~]# docker service ps go-demo
Docker Secrets With MySQL on
Docker Swarm
In Docker, Docker Secrets are encrypted during transit and at
rest in a Docker Swarm Cluster.
The great thing about Docker Secrets is that you can manage
these secrets from a central place, and the fact that it encrypts
the data and transfers the data securely to the containers that
needs the secrets.
So you authorize which containers needs access to these
secrets.

So instead of setting the MySQL Root Passwords in clear text,


you will create the secrets, then in your docker-compose fle,
you will reference the secret name.
Deploy MySQL with Docker Secrets

We will make the MySQL Service Persistent by setting a NFS


Server on the Manager node, as we will create the volume path
on the host, and then map the host to the container so that the
container can have persistent data.
We will also create secrets for our MySQL Service so that we
dont expose any plaintext passwords in our compose fle.
Deploy MySQL with Docker Secrets

First Confgure NFS Server on master Node:


[root@master ~]# mkdir -p /exports/data/mysql
[root@master ~]# chmod 777 /exports/data/mysql
[root@master ~]# yum install nfs-utils -y
[root@master ~]# echo "/exports/data/mysql
*(rw,sync,no_root_squash)" >> /etc/exports
[root@master ~]# cat /etc/exports
[root@master ~]# systemctl start nfs-server
[root@master ~]# systemctl enable nfs-server
[root@master ~]# systemctl status nfs-server
[root@master ~]# showmount -e
Deploy MySQL with Docker Secrets

Now confgure NFS Mount on all Nodes:


]# mkdir -p /data/mysql
]# mount 192.168.191.128:/exports/data/mysql /data/mysql/
]# df -h /data/mysql/
Deploy MySQL with Docker Secrets

Now Create Docker Compose File:


[root@master ~]# mkdir abc && cd abc
[root@master abc]# vim docker-compose.yml
Deploy MySQL with Docker Secrets
Deploy MySQL with Docker Secrets

Create the Overlay Network:


[root@master abc]# docker network create --driver overlay
appnet
Create the Secrets:
[root@master abc]# openssl rand -base64 12 | docker secret
create db_root_password -
[root@master abc]# openssl rand -base64 12 | docker secret
create db_dba_password -
Deploy MySQL with Docker Secrets

List the Secrets:


[root@master abc]# docker secret ls
Inspect the secret, so that we can see that theres not
value exposed:
[root@master abc]# docker secret inspect db_root_password
Deploy MySQL with Docker Secrets

Deploy the stack:


[root@master abc]# docker stack deploy -c docker-
compose.yml apps

[root@master abc]# docker service ps apps_adminer


[root@master abc]# docker service ps apps_db
Deploy MySQL with Docker Secrets

Connect to MySQL
[root@node2 ~]# docker exec -it $(docker ps -f
name=apps_db -q) ls /run/secrets/
View the actual value of the db_root_password:
[root@node2 ~]# docker exec -it $(docker ps -f
name=apps_db -q) cat /run/secrets/db_root_password
Deploy MySQL with Docker Secrets

Connect to MySQL
[root@node2 ~]# docker exec -it $(docker ps -f
name=apps_db -q) mysql -u root -pn/NYsdJ5KWptJkxs
Create a database for test purpose
mysql> create database suresh ;
mysql> exit;
Deploy MySQL with Docker Secrets

As we have deployed adminer, you can access the Adminer


WebUI on the Host’s IP and the Defned Port.
So Open Web Browser and point to the following URL:
http://192.168.191.130:8080
Deploy MySQL with Docker Secrets
Deploying nginx service to Docker swarm

[root@master ~]# mkdir nginx && cd nginx


[root@master nginx]# cat docker-compose.yml
Deploying nginx service to Docker swarm

[root@master nginx]# docker stack deploy --compose-fle


docker-compose.yml TEST
[root@master nginx]# docker service ls
[root@master nginx]# docker service ps TEST_nginx
Deploying nginx service to Docker swarm

Now open the web browser and access the following URL:
Deploying Wordpress and MySQL to Docker swarm

First Create NFS Exports to store MySQL Database persistent:

[root@master ~]# mkdir -p /exports/data/mysqldatabase


[root@master ~]# chmod 777 /exports/data/mysqldatabase
[root@master ~]# echo "/exports/data/mysqldatabase
*(rw,sync,no_root_squash) " >> /etc/exports
[root@master ~]# exportfs -r
[root@master ~]# showmount -e
Now mount this export to all the nodes:
]# mkdir -p /data/mysqldatabase
]# mount 192.168.191.128:/exports/data/mysqldatabase
/data/mysqldatabase/
]# df -h /data/mysqldatabase/
Deploying Wordpress and MySQL to Docker swarm

Now create a docker-compose.yml fle

[root@master ~]# mkdir wordpress && cd wordpress


[root@master wordpress]# cat docker-compose.yml
Deploying Wordpress and MySQL to Docker swarm

Now deploy wordpress and mysql Stack fle

[root@master wordpress]# docker stack deploy --compose-fle


docker-compose.yml myBlog
[root@master wordpress]# docker service ls

[root@master wordpress]# docker stack ps myBlog


Deploying Wordpress and MySQL to Docker swarm

Now Open Web Browser and access the following URL:

http://192.168.191.128:80
And complete the Installation
Deploying Wordpress and MySQL to Docker swarm
Deploying Wordpress and MySQL to Docker swarm
Deploying Wordpress and MySQL to Docker swarm
Deploying Wordpress and MySQL to Docker swarm

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy