Instruktaż/Tutorial Container-Station Konfiguracja Treafik (reverse-proxy) + OVH (SSL)

3Qn

Ave UBI!
Q's Expert
11 Czerwiec 2016
351
2
100
113
QNAP
TS-x73A
Ethernet
1 GbE
Instalacja Traefik pozwala nam na automatyczną rejestrację sub-domeny dla usługi uruchomionej w środowisku kontenerów w tym przypadku będzie to (Container-Station) oraz dzierżawę certyfikatów .

Na routerze forwardujemy jedynie dwa porty http:80 oraz https:443 nie muśmy pilnować/zapewniać aby serwisy kontenera miały stały adres IP restarty aplikacji i zmiana adresów (serwerów www) nie są już problematyczne.

Na potrzeby przykładu zakładam że posiadasz publiczny stały adres ip, domenę ovh (mojadomena.pl), serwer nas qnap.

1) Instalacja Traefik + statyczny plik z konfiguracją proxy do naszego serwera nas.
1.1) Konfiguracja statycznego proxy do naszego serwera NAS (zakładam że NAS oraz Traefik posiadają stałe adresy ip) plik nas.yaml
YAML:
http:
  routers:
    nas-router:
      rule: "Host(`nas.mojadomena.pl`)"
      service: nas
      tls:
        certresolver: ovh_production
  services:
    nas:
      loadBalancer:
        servers:
          - url: "http://10.85.0.10:8080/"
1.2) Konfiguracja serwera Traefik plik treafik.yaml
YAML:
global:
  checkNewVersion: true
  sendAnonymousUsage: false
  dns: true

entryPoints:
  web:
    address: :80
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
          permanent: true
          priority: 10000
  websecure:
    address: :443
#  torrent:
#    address: :51413/udp

certificatesResolvers:
  ovh_production:
    acme:
      email: imie.nazwisko@gmail.com
      storage: /etc/traefik/acme.json
      dnsChallenge:
        provider: ovh
        delayBeforeCheck: 10
2.) Zawarość pliku docker-compose.yaml samego serwisu Treafik
YAML:
version: "3.8"

name: traefik

networks:
  vlan-dhcp-eth0.20-6d6da6:
    external: true

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    hostname: traefik
    restart: always
    mac_address: a6:25:fb:04:05:9c
    networks:
      - vlan-dhcp-eth0.20-6d6da6
    command:
      - --api.insecure=true
      - --log.level=DEBUG
      - --accesslog=true
      - --accesslog.filePath=/logs/access.log
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.docker.network=default
      # Import configuration form /etc/traefik directory.
      - --providers.file.directory=/etc/traefik/
      - --providers.file.watch=true
      - --entrypoints.web.address=:80
      - --entrypoints.web.http.redirections.entryPoint.to=websecure
      - --entrypoints.web.http.redirections.entryPoint.scheme=https
      - --entrypoints.web.http.redirections.entrypoint.permanent=true
      - --entrypoints.websecure.address=:443
      - --certificatesresolvers.ovh_production.acme.dnschallenge=true
      - --certificatesresolvers.ovh_production.acme.dnschallenge.provider=ovh
      - --certificatesresolvers.ovh_production.acme.dnschallenge.delayBeforeCheck=60
      - --certificatesresolvers.ovh_production.acme.email=imie.nazwisko@gmail.com
      - --certificatesresolvers.ovh_production.acme.storage=/letsencrypt/acme.json
      # Plugins
      # Ldap
      - --experimental.plugins.ldapAuth.modulename=github.com/wiltonsr/ldapAuth
      - --experimental.plugins.ldapAuth.version=v0.1.5
      # GeoBlock
      - --experimental.plugins.geoblock.modulename=github.com/PascalMinder/geoblock
      - --experimental.plugins.geoblock.version=v0.2.7
    environment:
      OVH_ENDPOINT: ovh-eu
      OVH_APPLICATION_KEY: xxxxxxxxxxxxxxxxxxxxxxxx
      OVH_APPLICATION_SECRET: xxxxxxxxxxxxxxxxxxxxxxxx
      OVH_CONSUMER_KEY: xxxxxxxxxxxxxxxxxxxxxxxx
    ports:
      - 80:80
      - 443:443
    volumes:
      - /share/Container/apps/traefik/letsencrypt:/letsencrypt
      - /share/Container/apps/traefik/logs/access.log:/logs/access.log
      - /share/Container/apps/traefik/config:/etc/traefik:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      - "traefik.enable=true"
      # Enable the Traefik dashboard.
      - "traefik.http.services.traefik-service.loadBalancer.server.port=8080"
      - "traefik.http.routers.traefik-router.rule=Host(`traefik.localhost`)"
      - "traefik.http.routers.traefik-router.entryPoints=web"
      - "traefik.http.routers.traefik-router.service=api@internal"
Pluginy: LDAP, GEOBLOCK są opcionalne u mnie służą do zabezpieczenia stron, które nie mają wbudowanej autoryzacji.
Screenshot 2024-03-18 at 16-06-35 Traefik.png


3) Uruchamianie przykładowej serwisu, który zostanie zarejstrowany jako subdomena automatycznie. docker-compose.yaml
YAML:
version: "3.8"

networks:
  vlan-dhcp-eth0.20-6d6da6:
    external: true

services:
  homepage:
    image: ghost:alpine
    container_name: ghost
    networks:
      - vlan-dhcp-eth0.20-6d6da6
    ports:
      - 2368:2368
    restart: unless-stopped
    environment:
      - database__client=sqlite3
      - database__connection__filename=/var/lib/ghost/content/data/ghost.db
    labels:
      - traefik.enable=true
      - traefik.docker.network=vlan-dhcp-eth0.20-6d6da6
      # Routing for HTTP
      - traefik.http.services.ghost.loadbalancer.server.port=2368
      # Routing for HTTPS
      - traefik.http.routers.ghost.rule=Host(`blog.mojadomena.pl`)
      - traefik.http.routers.ghost.entrypoints=websecure
      - traefik.http.routers.ghost.tls=true
      - traefik.http.routers.ghost.tls.certresolver=ovh_production
Screenshot 2024-03-18 at 19-06-47 Traefik.png


No i sama domena ;)
Zrzut ekranu 2024-03-18 190931.png


Oraz predefiniowany wpis dla serwera nas:
Zrzut ekranu 2024-03-18 191255.png


Od tej pory tylko jeden adres sieciowy musi być przypisany na stałe treafik (na razie ;))

* Część konfiguracji jest opcjonalnie jak vlany to moja aktualna fanaberia a sam watek można traktować jako wstęp do kubernetesa.
 

Użytkownicy znaleźli tą stronę używając tych słów:

  1. docker station host
  2. reverse proxy