Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Docker PPT 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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 first 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 significant version since v1.9.
Back then, we got Docker networking that, finally, 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 configure 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 five replicas of the
go-demo service.
[root@master ~]# docker service scale go-demo=5
Deploying Services To The Swarm Cluster

Scaling Services

We can confirm that, indeed, five 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 specified state no matter
what happens.
To test a failure scenario, we’ll poweroff one of the nodes.

[root@node2 ~]# poweroff


[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 file, 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 file.
Deploy MySQL with Docker Secrets

First Configure 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 configure 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 Defined 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-file 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 file

[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 file

[root@master wordpress]# docker stack deploy --compose-file 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