Skip to content

Instantly share code, notes, and snippets.

@BrainBacon
Created December 7, 2024 13:23
Show Gist options
  • Select an option

  • Save BrainBacon/2722a430cfa754cad2cfc407049e247e to your computer and use it in GitHub Desktop.

Select an option

Save BrainBacon/2722a430cfa754cad2cfc407049e247e to your computer and use it in GitHub Desktop.
Traefik TrueNAS Portainer setup with Cloudflare ACME
services:
traefik:
user: 999:999
image: "traefik:v3.1"
container_name: "traefik"
ports:
- 192.168.X.X:80:80 # Public HTTP Port
- 192.168.X.X:443:443 # Public HTTPS Port
environment:
- "CF_DNS_API_TOKEN=${CF_DNS_API_TOKEN}"
volumes:
- "/mnt/mypool/path/to/traefik/letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock"
configs:
- source: traefik.yml
target: /etc/traefik/traefik.yml
- source: dynamic.yml
target: /etc/traefik/dynamic.yml
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.entrypoints=ssl"
- "traefik.http.routers.api.rule=Host(`traefik.example.com`)"
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.tls=true"
- "traefik.http.routers.api.tls.certresolver=letsencrypt"
networks:
- traefik-proxy
- ix-portainer_default
networks:
traefik-proxy:
external: true
ix-portainer_default:
external: true
configs:
traefik.yml:
content: |
log:
level: DEBUG
api:
dashboard: true
providers:
file:
filename: /etc/traefik/dynamic.yml
watch: true
docker: true
entrypoints:
web:
address: ":80"
ssl:
address: ":443"
certificatesResolvers:
letsencrypt:
acme:
keyType: EC384
email: "[email protected]"
storage: "/letsencrypt/acme.json"
dnsChallenge:
provider: cloudflare
resolvers:
- "1.1.1.1:53"
- "1.0.0.1:53"
delayBeforeCheck: 60
disablePropagationCheck: true
dynamic.yml:
content: |
http:
serversTransports:
skipverify:
insecureSkipVerify: true
middlewares:
httpsonly:
redirectScheme:
scheme: https
permanent: false
routers:
httpsonly:
entryPoints:
- "web"
rule: HostRegexp(`.*`)
middlewares: httpsonly
service: noop@internal
portainer:
entryPoints:
- "ssl"
rule: Host(`portainer.example.com`)
service: portainer
tls:
certResolver: letsencrypt
services:
portainer:
loadBalancer:
serversTransport: skipverify
servers:
- url: "https://portainer:31015"
@BrainBacon
Copy link
Author

BrainBacon commented Dec 7, 2024

  • Change the IP addresses in the Ports configuration to match the address of your TrueNAS server
  • Create a dataset to store traefik letsencrypt data and change /mnt/mypool/path/to/traefik/letsencrypt to match
  • Set up nameservers on Cloudflare
  • Get a Cloudflare API token that can modify your domain's DNS zone
  • Provide the API token as an environment variable called CF_DNS_API_TOKEN
  • Change example.com to match your domain name
  • Change [email protected] to match your email address
  • Create a docker network in Portainer called traefik-proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment