geeek
November 30, 2019, 1:44pm
1
I am using following labels for trafeik docker-compose. How do I force trafeik to redirect to https for dashboard and any services. It is not changing with scheme.
- "traefik.http.middlewares.https-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.routers.traefiktls.entrypoints=websecure"
- "traefik.http.routers.traefik.rule=Host(`xyx.domain.com`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
- "traefik.http.routers.traefik.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=tom:dasdasd"
ldez
November 30, 2019, 5:00pm
2
geeek
December 1, 2019, 5:21am
3
Thanks for your help. It didn't help, do I have to provide the middleware for traefik and as well as the service. My goal is whenever user have address without https redirect for dashboard and service it regardless of it having www or not.
Here are the labels for trafeik:
labels:
- "traefik.http.routers.traefik.entrypoints=web"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.traefik.middlewares=redirect-to-https"
- "traefik.http.routers.traefik.rule=Host(`xyz.domain.com`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
- "traefik.http.routers.traefik.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=u:test"
Here are labels for service:
- "traefik.http.routers.chat-app.rule=Host(`abc.domain.com`)"
- traefik.http.services.chat-app.loadbalancer.server.port=3001
- "traefik.http.routers.chat-app.entrypoints=web"
- "traefik.http.routers.chat-app.entrypoints=websecure"
- "traefik.http.routers.chat-app.tls.certresolver=myhttpchallenge"
geeek
December 7, 2019, 8:29am
4
still looking for solution
ldez
December 7, 2019, 4:45pm
5
The catchall and the api/dashboard have to use 2 routers:
labels:
- "traefik.http.routers.catchall.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.catchall.entrypoints=web"
- "traefik.http.routers.catchall.middlewares=redirect-to-https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.rule=Host(`xyz.domain.com`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.middlewares=auth"
- "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.middlewares.auth.basicauth.users=u:test"
Also you cannot use one label (traefik.http.routers.chat-app.entrypoints
) several times for the same router, and you have to set only the tls entrypoint:
- "traefik.http.routers.chat-app.rule=Host(`abc.domain.com`)"
- "traefik.http.routers.chat-app.entrypoints=websecure"
- "traefik.http.routers.chat-app.tls.certresolver=myhttpchallenge"
- traefik.http.services.chat-app.loadbalancer.server.port=3001
How can I use the force direct in this case..? I am using K8s , AWS ACM
Here is my traefik-service.yaml file
kind: Service
apiVersion: v1
metadata:
name: {{ template "traefik.fullname" . }}
labels:
{{ include "traefik.labels" . | indent 4 }}
namespace: kube-system
annotations:
{{ if .Values.service.host }}
{{ if not .Values.isLocalEnvironment }}
external-dns.alpha.kubernetes.io/hostname: {{ .Values.service.host }}
{{ end }}
{{ end }}
{{ if .Values.loadbalancer.protocol }}
{{ if not .Values.isLocalEnvironment }}
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: {{ .Values.loadbalancer.protocol }}
{{ end }}
{{ end }}
{{ if .Values.loadbalancer.certificate }}
{{ if not .Values.isLocalEnvironment }}
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: {{ .Values.loadbalancer.certificate }}
{{ end }}
{{ end }}
{{ if .Values.loadbalancer.port }}
{{ if not .Values.isLocalEnvironment }}
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: {{ .Values.loadbalancer.port }}
{{ end }}
{{ end }}
spec:
selector:
app: {{ template "traefik.name" . }}
release: {{ .Release.Name }}
ports:
- protocol: TCP
name: web
port: 80
targetPort: 8000
- protocol: TCP
name: admin
port: 8080
targetPort: 8080
- protocol: TCP
name: websecure
port: 443
targetPort: 4443
type: LoadBalancer```
Here is my values file
service:
host:
loadbalancer:
protocol:
certificate:
port:
isLocalEnvironment: false
useSSL: false
dashboard:
domain: traefik.local
ssl:
defaultCert: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBejUybUFKemF0dHRqN1dnRjZKK1o4U0R5Qy9iSnpYaXZQNjRwbE5HSDBUZjMvY2hQCk5ydnN1aGRuNEVYRkpNU2w4M29MOFpocnl3N25UbXR1RlhTSjVQL2RldVV2d2Q5KzJTdkZuUzY2OFFmZTVjTTcKOFVLbWZiY1FWUVluZTZCcjhZS1hacTNmZWZ2Y3dZZ2x6eDVncXNIeFNPNzk3T01hQVBLb0ViYmZZZGhrYVl1NQo1bTlxWlB6dzdjS1IzUjg5bVF0TElmSzJwV0cvZjZySkJENDZ6bUJJQm8yT29pNGVVQXloOXRwMFdnWjlRRUt5CnhQZU9lL2c2Rk5CNlA1NStmUVZiVVVySk1FZHBGY0pYVjIwSzZJNkVtWStrUnpoc2VzKzh4VUpWQkFPSVhPOFEKcDdEUHZSaThvcGNaVi9tV0wxVkovMFJ5aDlDazlqTDVZMVBhdlFJREFRQUJBb0lCQVFDbXN2RVArdUdPQXRmWQpUamE0VWpYYnExVk5qK2oyeHRrSHE0S05rRE9hSkhORlhPbGxqRHlHS3Jib0YzMDBpWVNwMnl2dDN6Rmx5R0NtCjBaR0JQcUpkc2FlV3ZxQzY3UVcvditxYXkyT2tsbW85VjZZd2tCQjRUbDJadHloS2xrTTFsbUtVT2pWK2oyRHcKTDY0VUFGTWpxRGRoRlN2allYR0dvMCtaY1prb3lKRnZ2MGo3QU9yWXBUd2RiWmMySG0wTEpFNmxOTE9MVUVQKwprc0l1aDNHSWdENXdiaXBidldMUTlicDd0RURNZ01ic2ZaOFJHOUs0cnNHSUszcGpuKzdMek8yeWQ0cXhoV0wwCk5lb1M4VGs1eGRiN3VpS2RjTHF3NTUvWGxVSVZDcUVCVThnWHoranorT0ltMXgwQ3Mx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BakFBCk1Bc0dBMVVkRHdRRUF3SUY0REFkQmdOVkhTVUVGakFVQmdnckJnRUZCUWNEQWdZSUt3WUJCUVVIQXdFd0p3WUQKVlIwUkJDQXdIb0lOZEhKaFpXWnBheTVzYjJOaGJJSU5kSEpoWldacGF5NXNiMk5oYkRBTkJna3Foa2lHOXcwQgpBUXNGQUFPQ0FRRUFHNjA4ei9SaE1DeWxJVHdjTVpaUkxHSDRxRndOSHF0UzRyMkMrVzVSaDVTd3c1R0Q2aWZ6ClZJUC96Q0hodmNLWTRveERmQTZnNzBzSVJQT2FKcURaR2FhbGhoWjMxeC9mQmkvd1FMUUROdVQ4elNtckk4SUgKSWtTWUpYcHhHTE9DaEt1NG9nSHNseVdVb2hXZVhuSytMVWNkVm45Z2VxbXU4SzhZLzVhZFJvZERmNVlMZUdRegp6Nmxmc1BEU3pZcHZqQmVlQ1ltUU01dVpLS2diYlNkZHZlcDUrZUpWY2NTZCt4c1liZFJXZDU5Tmc4V3dxcVF0CjgxdzVneVJDSzFERXg3ODhFTzM1aGJRSkFvN2JiKzlmSWNJODFsNUlRMjdobzNPVU1aWlRZQ2w1U1Z1ZkdBckEKdHV0K2lOTm9Ca05HZjRrTndob1lOS0p6M2ZUU2xBVGMwdz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
enabled: true```
Above is my values file
geeek
January 3, 2020, 10:57am
7
thank you so much. Have a follow up how do I know when to use new label. I have 2 separate services running one with same router works.
Service 1:
- "traefik.http.routers.chat-app.rule=Host(`abc.domain.com`)"
- "traefik.http.routers.chat-app.entrypoints=websecure"
- "traefik.http.routers.chat-app.tls.certresolver=myhttpchallenge"
- traefik.http.services.chat-app.loadbalancer.server.port=3001
Service 2
- "traefik.http.routers.chat-app-group.rule=Host(`xyz.domain.com`)"
- "traefik.http.routers.chat-app-group.entrypoints=websecure"
- "traefik.http.routers.chat-app-group.tls.certresolver=myhttpchallenge"
- traefik.http.services.chat-app-group.loadbalancer.server.port=3002
I couldn't wrap my head around why it is working for case 1 and failing for case 2. Is there a rule of thumb when to use same name within label or just use different for each line.
Thanks!