Learn how to deploy Traefik v2.0 in docker swarm cluster to act as a reverse proxy and load balancer for micro-services. Also to get automatic SSL certificates for our micro-services using Letsencrypt certificate authority.
#Traefik
#Traefikv2.0
#TraefikDocker
#DockerTraefik
Full blog post here: https://rb.gy/ayr4f9
Useful referral links
=========================================
Digital ocean - https://m.do.co/c/4fc5bb284d41
Rasberry Pi - https://uk.pi-supply.com/?ref=cjv78_u...
Create beautiful social media graphics - https://www.canva.com/join/wqj-rnt-rtx
Learn more about Traefik using below links
=========================================
https://containo.us/traefik/
https://docs.traefik.io/
Please find videos below for Docker Swarm Setup and GlusterFS Install below.
Setup Docker Swarm Cluster - • Setup Docker Swarm Cluster on Ubuntu 20.04...
Install GlusterFS in Docker Swarm - • Install GlusterFS as Replicated Storage Vo...
Blog post for docker swarm cluster - https://rb.gy/lbcj6e
=========================================
Please find the full list of commands below.
=========================================
Before deploying Traefik in our docker swarm cluster, let’s set up an encrypted password to access Traefik monitoring dashboard securely.
I use htpasswd utility to create the encrypted password. Install the utility on master node, which is included in the apache2-utils package:
sudo apt-get install apache2-utils
Now generate the password with htpasswd. Replace secure_password with the password you’d like to use for the Traefik admin user (replace admin as well if you want to other user name)
htpasswd -nb admin secure_password ----echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g
Note down the password, we need to enter it in traefik configuration
Let’s create a Docker network for our Traefik proxy to share with other stack or containers.
This network is necessary so that we can use it with applications that are run using Docker Compose. Let’s call this network as proxy.
docker network create -d overlay proxy
When the Traefik stack starts, we will add it to the proxy network. Then we can add additional stacks or containers to this network later for Traefik to serve the stacks to outside world.
Now on-wards everything executed on master node.
cd /opt
sudo mkdir -p proxy
cd proxy
sudo touch acme.json
sudo touch proxy.yml (you can use any name, i just named it as proxy)
Lock down the permissions on acme.json so that only the owner of the file has read and write permission
sudo chmod 600 acme.json
sudo nano proxy.yml
Paste below code on it
=========================================
version: "3.7"
services:
proxy:
image: traefik:latest
command:
"--api=true"
"--api.dashboard=true"
"--metrics=true"
"--metrics.prometheus.buckets=0.1,0.3,1.2,5.0"
"--providers.docker=true"
"--providers.docker.exposedbydefault=false"
"--providers.docker.swarmMode=true"
"--providers.docker.network=http"
"--entrypoints.web.address=:80"
"--entrypoints.websecure.address=:443"
"--certificatesresolvers.default.acme.email=enter your email address here"
"--certificatesresolvers.default.acme.storage=/acme.json"
"--certificatesresolvers.default.acme.tlschallenge=true"
ports:
80:80
443:443
deploy:
placement:
constraints:
node.role == manager
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
labels:
Dashboard
"traefik.enable=true"
"traefik.docker.network=proxy"
"traefik.http.routers.traefik.rule=Host(`traefik.example.com`)"
"traefik.http.routers.traefik.service=api@internal"
"traefik.http.routers.traefik.tls.certresolver=default"
"traefik.http.routers.traefik.entrypoints=websecure"
"traefik.http.routers.traefik.middlewares=authtraefik"
"traefik.http.middlewares.authtraefik.basicauth.users=admin:$$apr1$$OUjjMhuM$$3Xqh01T0fmf0XHY1ymxcR."
"traefik.http.services.traefik.loadbalancer.server.port=8080"
global redirect to https
"traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
"traefik.http.routers.http-catchall.entrypoints=web"
"traefik.http.routers.http-catchall.middlewares=redirect-to-https"
middleware redirect
"traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
volumes:
/var/run/docker.sock:/var/run/docker.sock
./acme.json:/etc/traefik/acme.json
networks:
proxy
networks:
proxy:
external: true
=========================================
Remember to leave a comment or like on this video and subscribe if you want to see more!
=========================================