Rancher behind traefik 2.0.0-alpha8

Hello,

someone success to put and use rancher2 behind traefik with only docker label ? I've tried since few days but without any success, if somme have an idea

hey! just a quick question to check whether I got your question right or not :slight_smile:

You're trying to proxy the rancher2 webui behind a traefik? How is your setup in general then?

@SantoDE thx to reply, Yes this what i want.

i update my setting so many times so it's dirty now..

################################################################
#
# 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.web-secure]
    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 = "common"

################################################################
# 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 = "common"

################################################################
# API and dashboard configuration
################################################################

# Enable API and dashboard
[api]

  # Name of the related entry point
  #
  # Optional
  # Default: "traefik"
  #
  # entryPoint = "traefik"

  # 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]
  exposedByDefault = false

#[Providers.file]

# dynamic configuration
#[http.middlewares]
#  [http.middlewares.redirect.redirectscheme]
 #   scheme = "https"
# 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: ""
#
# DefaultRule = "Host(`{{ normalize .Name }}.docker.localhost`)"

# Expose containers by default in traefik
#
# Optional
# Default: true
#
# exposedByDefault = true

[tls.stores]
  [tls.stores.default]

[acme]
  # ...
  [acme.httpChallenge]
    entryPoint = "web"
version: '3'

services:
  reverse-proxy:
    # The official v2.0 Traefik docker image
    image: traefik:v2.0.0-alpha8-alpine
    container_name: traefik
    # Enables the web UI and tells Traefik to listen to docker
    command: --api --providers.docker
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/etc/traefik/traefik.toml

  whoami:
    image: containous/whoami
    labels:
      - traefik.enable=true


  nginx:
    image: nginx:1.17.1-alpine
    labels:
      - traefik.enable=true
      - traefik.http.routers.nginx.rule=Host("nginx.docker.localhost")
      ## declare middle ware
      - traefik.http.routers.nginx.middlewares=nginx-mw
#      - traefik.http.middlewares.nginx-mw.redirectscheme.scheme=https


  rancher2:
    image: rancher/rancher:latest
    container_name: rancher2
    labels:
      - traefik.enable=true
      - traefik.http.routers.rancher2.rule=Host(`rancher2.docker.localhost`)
      - traefik.http.routers.web-secure.tls=true
    expose:
      - 80
      - 443

And what error are you facing exactly? :slight_smile:

@SantoDE i can't access to rancher2 web ui, i've nothing in log rancher2 or traefik 2
and browser says => ERR_CONNECTION_REFUSED

Do you see in the traefik's api rawdata that the service has been picked up alright? can you try with non tls at first?

{
   "routers":{
      "nginx@docker":{
         "service":"nginx_traefik",
         "rule":"Host(\"nginx.docker.localhost\")"
      },
      "rancher2@docker":{
         "service":"rancher2_traefik",
         "rule":"Host(`rancher2.docker.localhost`)"
      },
      "whoami_traefik@docker":{
         "service":"whoami_traefik",
         "rule":"Host(`whoami-traefik`)"
      }
   },
   "services":{
      "nginx_traefik@docker":{
         "loadBalancer":{
            "servers":[
               {
                  "url":"http://172.20.0.3:80"
               }
            ],
            "passHostHeader":true
         },
         "usedBy":[
            "nginx@docker"
         ],
         "serverStatus":{
            "http://172.20.0.3:80":"UP"
         }
      },
      "rancher2_traefik@docker":{
         "loadBalancer":{
            "servers":[
               {
                  "url":"http://172.20.0.5:80"
               }
            ],
            "passHostHeader":true
         },
         "usedBy":[
            "rancher2@docker"
         ],
         "serverStatus":{
            "http://172.20.0.5:80":"UP"
         }
      },
      "whoami_traefik@docker":{
         "loadBalancer":{
            "servers":[
               {
                  "url":"http://172.20.0.2:80"
               }
            ],
            "passHostHeader":true
         },
         "usedBy":[
            "whoami_traefik@docker"
         ],
         "serverStatus":{
            "http://172.20.0.2:80":"UP"
         }
      }
   }
}

Yes a try but rancher2 redirect to 443,
http://172.20.0.5:80 => redirect to https://172.20.0.5 and it work but http://rancher2.docker.localhost redirect to https://rancher2.docker.localhost and doesn't work

And you have set a host, pointing docker.localhost to local?

Yes i've tried but whithout any result, and if nginx.docker.localhost work wihout this entry in /etc/hosts why this is necessary for rancher2.docker.localhost

Ah, I guess I got it.

You're traefik is only binding to Port 80, which is HTTP. If rancher2 itself is redirecting you to HTTPS, of course traefik needs to available for that as well :slight_smile:

@SantoDE
i've got this in my traefik.toml where i can find the correct configuration ? or have you an example ?

Well, usually SSH is running through port 22, therefore you need something like

[entryPoints] 
    [entryPoints.ssh] address = ":22"

i've already this in my toml file and it doesn't work

Sorry, I was messing up threads on the forum :slight_smile: However, it's still valid somehow.

you might have that in your toml to like declare your entrypoint, however, the traefik container is not binding on port 443. There is no port mapping. You need to add something like

  ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api)
      - "8080:8080"
      # The HTTPs Port
      - "443:443"

No problem !!! ok i understand now, traefik must handle the port to dispatch in the right container, now the error change this is 404 page not found

Then something with your host rule is not correct on the rancher2 container.

try something like:

      - traefik.enable=true
      - traefik.http.routers.rancher2.tls=true
      - traefik.http.routers.rancher2.rule=Host(`rancher2.docker.localhost`)