`
sillycat
  • 浏览: 2486795 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Traefik 2020(1)Introduction and Installation

阅读更多
Traefik 2020(1)Introduction and Installation

Support ACME(Let’s Encrypt), Support WebSocket and HTTP/2
 
Providers - Docker, Kubernetes, File
Entrypoints -
Routers - host, path, headers, SSL
Services
Middlewares - authentication, rate limiting, headers

Different release is here https://github.com/containous/traefik/releases

Try this quick starter
https://www.katacoda.com/courses/traefik/deploy-load-balancer

Check version
>docker-compose --version
docker-compose version 1.21.2, build a133471

Another quick starter here
https://docs.traefik.cn/#quickstart

Current release is https://github.com/containous/traefik/releases/tag/v2.1.6
> wget https://github.com/containous/traefik/releases/download/v2.1.6/traefik_v2.1.6_linux_amd64.tar.gz
> tar zxvf traefik_v2.1.6_linux_amd64.tar.gz
> mkdir traefik-2.1.6
> mv traefik traefik-2.1.6/
> mv traefik-2.1.6 ~/tool/
> sudo ln -s /home/carl/tool/traefik-2.1.6 /opt/traefik-2.1.6
> sudo ln -s /opt/traefik-2.1.6 /opt/traefik

Check version
> ./traefik version
Version:      2.1.6
Codename:     cantal
Go version:   go1.13.8
Built:        2020-02-28T17:40:18Z
OS/Arch:      linux/amd64

Sample configuration
https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml

> wget https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml
> cp traefik.sample.toml traefik.toml

Just the default content
> cat traefik.toml
################################################################
#
# Configuration sample for Traefik v2.
#
# For Traefik v1: https://github.com/containous/traefik/blob/v1.7/traefik.sample.toml
#
################################################################
################################################################
# Global configuration
################################################################
[global]
  checkNewVersion = true
  sendAnonymousUsage = true
################################################################
# Entrypoints configuration
################################################################
# Entrypoints definition
#
# Optional
# Default:
[entryPoints]
  [entryPoints.web]
    address = ":80"
  [entryPoints.websecure]
    address = ":443"
################################################################
# Traefik logs configuration
################################################################
# Traefik logs
# Enabled by default and log to stdout
#
# Optional
#
[log]
  # Log level
  #
  # Optional
  # Default: "ERROR"
  #
  # level = "DEBUG"
  # Sets the filepath for the traefik log. If not specified, stdout will be used.
  # Intermediate directories are created if necessary.
  #
  # Optional
  # Default: os.Stdout
  #
  # filePath = "log/traefik.log"
  # Format is either "json" or "common".
  #
  # Optional
  # Default: "common"
  #
  # format = "json"
################################################################
# Access logs configuration
################################################################
# Enable access logs
# By default it will write to stdout and produce logs in the textual
# Common Log Format (CLF), extended with additional fields.
#
# Optional
#
# [accessLog]
  # Sets the file path for the access log. If not specified, stdout will be used.
  # Intermediate directories are created if necessary.
  #
  # Optional
  # Default: os.Stdout
  #
  # filePath = "/path/to/log/log.txt"
  # Format is either "json" or "common".
  #
  # Optional
  # Default: "common"
  #
  # format = "json"
################################################################
# API and dashboard configuration
################################################################
# Enable API and dashboard
[api]
  # Enable the API in insecure mode
  #
  # Optional
  # Default: true
  #
  # insecure = false
  # Enabled Dashboard
  #
  # Optional
  # Default: true
  #
  # dashboard = false
################################################################
# Ping configuration
################################################################
# Enable ping
[ping]
  # Name of the related entry point
  #
  # Optional
  # Default: "traefik"
  #
  # entryPoint = "traefik"
################################################################
# Docker configuration backend
################################################################
# Enable Docker configuration backend
[providers.docker]
  # Docker server endpoint. Can be a tcp or a unix socket endpoint.
  #
  # Required
  # Default: "unix:///var/run/docker.sock"
  #
  # endpoint = "tcp://10.10.10.10:2375"
  # Default host rule.
  #
  # Optional
  # Default: "Host(`{{ normalize .Name }}`)"
  #
  # defaultRule = "Host(`{{ normalize .Name }}.docker.localhost`)"
  # Expose containers by default in traefik
  #
  # Optional
  # Default: true
  #
  # exposedByDefault = false

Start the command
> ./traefik -c traefik.toml
Need the sudo to use port 80
> sudo ./traefik -c traefik.toml

Visit the page http://rancher-home:8080/, not working as plan.

Try the Docker small image way
> docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik

Feel the documents are too old.

Need to try this one
https://docs.traefik.io/getting-started/quick-start/

Prepare the docker-compose.yml file
> cat docker-compose.yml
version: '3'
services:
  reverse-proxy:
    image: traefik:v2.2
    command: --api.insecure=true --providers.docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Start the proxy
> docker-compose up -d reverse-proxy

Check running
> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
01941cec6a8b        traefik:v2.2        "/entrypoint.sh --ap…"   30 seconds ago      Up 28 seconds       0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp   traefik_reverse-proxy_1

Rawdata from API
http://localhost:8080/api/rawdata

Visit the UI
http://localhost:8080/#/

Add one container to the compose file
> cat docker-compose.yml
version: '3'
services:
  reverse-proxy:
    image: traefik:v2.2
    command: --api.insecure=true --providers.docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: containous/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"

Start the new API
> docker-compose up -d whoami

Verify that
> curl -H Host:whoami.docker.localhost http://127.0.0.1
Hostname: 6f10bb7464ba
IP: 127.0.0.1
IP: 172.18.0.3
RemoteAddr: 172.18.0.2:36600
GET / HTTP/1.1
Host: whoami.docker.localhost
User-Agent: curl/7.61.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.18.0.1
X-Forwarded-Host: whoami.docker.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 01941cec6a8b
X-Real-Ip: 172.18.0.1

Add to the hosts
> cat /etc/hosts
127.0.0.1     whoami.docker.localhost

Visit this URL
http://whoami.docker.localhost/

Scala up more instances
> docker-compose up -d --scale whoami=2


References:
https://docs.traefik.io/getting-started/install-traefik/
https://www.jianshu.com/p/32aed362ac6c
https://docs.traefik.cn/
https://www.katacoda.com/courses/traefik/deploy-load-balancer
https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml
https://docs.traefik.io/getting-started/configuration-overview/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics