Skip to main content

Traefik Install and configuration - Part 1

Introduction

In this tutorial we are going to install and configure Traefik Proxy. As quoted on their website "Traefik is a leading modern reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components and configures itself automatically and dynamically." All our applications will be front-ended by traefik.

Objective

The core objective for this tutorial is to:
  1. Configure an A record in our DNS server (pfsesne firewall) to point to our traefik proxy
  2. Configure and install Traefik in docker
  3. Configure and install two http based applications (homer and heimdall) in docker that will be accessed via traefik

Topology



The above image represents our topology. Our pfsense firewall is connected directly to the Internet and is NAT'ing all traffic from the internal network to the outside world. We have a single LAN segment (192.168.11.0/24) defined on pfsense and we have the following two PC's connected directly to the firewall:
  • Windows PC - This PC is used to install and configure traefik and for testing
  • Ubuntu server - This PC runs docker and will host traefik and our applications
Following is what we are trying to achieve:
  • From the windows PC we will open a browser and navigate to http://homer.home.local and http://heimdall.home.local
  • Since pfsense is our DNS server, the URL's will resolve to the ubuntu server's IP address and traefik will pick up the request as we will expose port 80 on the container
  • Traefik will then route the request to the appropriate container 
  • If all goes well we should see the homer and heimdall pages load on our Windows PC browser

Assumptions

  1. A DNS server that can be configured with an A record to point to a traefik proxy. We will be using the pfsense firewall
  2. An installation of docker and docker-compose. We will be running docker on Ubuntu 20.04.3

DNS Configuration

The goal is to access our application using freindly URL names as opposed to IP's and port numbers. In order to do so we need to identify a domain name. We are going to choose home.local as our domain name. This domain is used internally within our network and will not exist on the Internet. We need our DNS server to resolve *.home.local to our Ubuntu server. So homer.home.local and heimdall.home.local will both resolve to our Ubuntu server IP address 192.168.11.2.

In pfsense navigate to:
  1. Services --> DNS Resolver --> General Settings
  2. Enable DNS Resolver
  3. Scroll down and Display Customer Options and past the following config
 server:
 local-zone: "home.local" redirect
 local-data: "home.local 3600 IN A 192.168.11.2"
The windows PC and ubuntu server are configured to use pfsense (192.168.11.1) as the DNS server. If we ping home.local it should resolve to our Ubuntu server and ping successfully
 ping home.local
 PING home.local (192.168.11.2) 56(84) bytes of data.
 64 bytes from pserver (192.168.11.2): icmp_seq=1 ttl=64 time=0.032 ms
 64 bytes from pserver (192.168.11.2): icmp_seq=2 ttl=64 time=0.089 ms
 64 bytes from pserver (192.168.11.2): icmp_seq=3 ttl=64 time=0.109 ms

Configure and Install Traefik

Create a directory to store the docker files and traefik config files 

 mkdir traefik
 cd traefik

Create a docker-compose.yml file using an editor of your choice

 vim docker-compose.yml
Paste the following config in docker-compose.yml
version: "3.3"
services:
  traefik:
    container_name: traefik
    image: traefik:2.3 # Download traefik v2.3
    restart: always # Restart the container if stops
    ports:
      - 80:80 # Expose port 80 on the host machine
    volumes:
      - ./static_config.yml:/etc/traefik/traefik.yml # Traefik's static config file 
      - /var/run/docker.sock:/var/run/docker.sock # Allow Traefik access to docker API's to dynamically learn applications
    labels:
      # Traefil uses lables to learn about containers and dynamically configures itself. Expose the traefik dashboard on port 80
      - traefik.http.routers.traefik-http.rule=Host(`dashboard.home.local`)
      - traefik.http.routers.traefik-http.entrypoints=web
      - traefik.http.routers.traefik-http.service=api@internal
    # Use the customer network web that is defined below
    networks:
      - web      
networks:
  web:

Create a traefik static file using an editor of your choice

 vim static_config.yml
Paste the following config in static_config.yml
 log:
  level: DEBUG # Enable logging
api:
  dashboard: true # Enable the traefik dashboard 
entryPoints:
  web:
    address: ":80" # Define the name called web and expose port 80
providers:
  docker: {} # Tells traefik to monitor docker for changes and autoconfigure

Start Traefik

docker-compose up -d
The aforementioned command will pull the traefik image and start the container. The traefik dashboard should be reachable via http://dashboard.home.local as seen below

Configure and Install Homer

Create a folder called homer your home path
 mkdir homer
 cd homer

Create a docker-compose.yml file using an editor of your choice

 vim docker-compose.yml
Paste the following config in docker-compose.yml
version: "3.5"

services:
  homer:
    image: b4bz/homer
    container_name: homer
    volumes:
      - ./assets/:/www/assets
    ports:
      - 8080:8080
    restart: unless-stopped
    labels: # auto-detects port 80 in next line
      traefik.http.routers.homer.rule: Host(`homer.home.local`)
    networks:
      - traefik_web
networks:
  traefik_web:
    external: true

Start Homer

docker-compose up -d
The aforementioned command will pull the homer image and start the container. Since traefik is monitoring docker labels, it will process the label defined in line 13 and automatically configure itself and route to homer. The traefik container does not need to be restarted and that is the power of Traefik. The homer dashboard should be reachable via http://homer.home.local as seen below

Configure and Install Heimdall

Create a folder called homer your home path
 mkdir heimdall
 cd heimdall

Create a docker-compose.yml file using an editor of your choice

 vim docker-compose.yml
Paste the following config in docker-compose.yml
version: "2.1"
services:
  heimdall:
    image: lscr.io/linuxserver/heimdall
    container_name: heimdall
    volumes:
      - ./config:/config
    ports:
      - 8081:80
    restart: unless-stopped
    labels: # auto-detects port 80 in next line
      traefik.http.routers.heimdall.rule: Host(`heimdall.home.local`)
    networks:
      - traefik_web
networks:
  traefik_web:
    external: true

Start Heimdall

docker-compose up -d
The aforementioned command will pull the heimdall image and start the container. The heimdall dashboard should be reachable via http://heimdall.home.local as seen below

Conclusion

We installed the traefik reverse proxy and setup a DNS server to direct all requests to a domain (home.local) to the reverse proxy. We also installed two applications (homer and heimdall) that are accessible via the reverse proxy. Everything was installed in docker and traefik can automatically learn about the application to self-configure itself to route traffic to the appropriate application. In the next part we will configure traefik to route traffic to an external application (non-docker application), enable HTTPS and secure HTTP applications with HTTPS

References

Comments

  1. Graton Casino & Hotel - MapYRO
    Welcome to Graton Casino & Hotel, an off-Strip 광주 출장샵 Las Vegas Strip, 광명 출장마사지 located in Las Vegas at 3355 South Las Vegas Boulevard. It's the ideal place to explore  아산 출장샵 Rating: 2.3 · 포항 출장마사지 ‎27 votes 시흥 출장마사지

    ReplyDelete
  2. Casino Bonus codes and free spins no deposit 2021 - The
    Get exclusive casino bonus where can you buy air jordan 18 retro varsity red codes bestest air jordan 18 retro red and free spins show air jordan 18 retro yellow suede no deposit 2021. Compare 2021's Best Casino Bonus Codes & get the Best buy air jordan 18 retro yellow Free Spins No get air jordan 18 retro yellow suede Deposit Bonus 2021

    ReplyDelete

Post a Comment

Popular posts from this blog

Part 1- Install Django using Virtualenv, Apache and MySQL on Ubuntu Server 14.10

Introduction I have been using Microsoft Excel to do my Personal Budget. Excel is extremely powerful and has fulfilled my needs. But I always wanted to build a web application which is accessible via a browser and in order to do so we need the following: An admin interface (website) to plug in my expenses A database to store all the entries Code to parse the database and calculate the expenses per month A public interface (website) to display expense charts After browsing the web I stumbled across Django. Django (as copied from the project page) is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. It focuses on automating as much as possible and adhering to the DRY principle. In the first part of this tutorial we will walk through the installation of Django using Virtualenv. In the following series we will build our Personal Budget application using Django. What is virtualenv and why use it? Virtualenv (as copied from th

Run your Meteor App on a Production Ubuntu 16.04 Server with Nginx

Introduction Meteor enables developers to create apps and quickly test them on a development webserver. Once you have created your app the big question is how to run it on a production server. In this tutorial we will demostrate how to run your Meteor app on Ubuntu 16.04 using Nginx Credits and Acknowledgements This entire post is based off this Digital Ocean article. The article was modified for issues we encountered and adapted for Ubuntu 16.04. The entire credit goes to Daniel Speichert Objective In this tutorial we will: Install and Configure Nginx with HTTPS enabled Install MongoDB Install NodeJS Bundle your Meteor App Create a startup script to automatically start your app on reboot Assumptions We assumue the following: You already have a fresh install of Ubuntu 16.04 Server SSH enabled on your fresh install You have root privelages on your server You have a different server where you can insall meteor and budle your app

Installing Zurmo on Ubuntu Sever 14.10

Introduction Zurmo is an Open Source Customer Relationship Management (CRM) application that is mobile, social, and gamified. It can be used to: Create and Track Project progress Create Customer Accounts Tasks - Associate Tasks to Accounts and/or Projects Customize fields of Tasks, Accounts etc. Generate Reports etc. Objective The final objective is to install Zurmo 2.8.5 on Ubuntu Server 14.10 Assumptions Fresh Install of Ubuntu Server 14.10 SSH enabled (sudo apt-get install ssh-server) User has sudo or root privileges Step 1: Install the Apache Webserver sudo apt-get install apache2 -y Step 2: Install MySQL Server sudo apt-get install mysql-server -y Step 3: Install PHP5 sudo apt-get install php5 -y sudo apt-get install php5-mysql -y sudo apt-get install php5-memcache -y sudo apt-get install php5-curl -y sudo apt-get install php-apc -y sudo apt-get install php-soap -y sudo apt-get install php5-imap -