I'm trying to redirect an ingress for the service deployed in Azure Kubernetes to https. Whatever I try doesn't work. I tried configuring Ingress and Traefik itself (via ConfigMap) with no effect.
The config for Traefik looks as the following:
---
# Traefik_config.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: traefik-conf
namespace: kube-system
# traefik.toml
data:
traefik.toml: |
defaultEntryPoints = ["http","https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[frontends]
[frontends.frontend2]
backend = "backend1"
passHostHeader = true
# overrides default entry points
entrypoints = ["http", "https"]
[backends]
[backends.backend1]
[backends.backend1.servers.server1]
url = "http://auth.mywebsite.com"
The subject for redirection is containerized IdentityServer API website with no TLS encryption. There are a couple of questions on the matter:
Your configuration for redirecting http to https looks good. If you have followed the official Doc of Traefik to deploy on kubernetes, The Traefik ingress controller service will not have 443. Make sure you have port 443 opened on the Service with service type as LoadBalancer
. Once we open a port in service, Then Azure opens the same port in the Azure load balancer. Service yaml is here.
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service
namespace: kube-system
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- protocol: TCP
port: 80
name: web
- protocol: TCP
port: 8080
name: admin
type: LoadBalancer
If you want to redirect all the http to https in your cluster, You can go for the redirection in the configuration file. If you want to redirect only some of the services, then add annotations in the Ingress to achieve redirection for specific services.
traefik.ingress.kubernetes.io/frontend-entry-points: http,https
traefik.ingress.kubernetes.io/redirect-entry-point: https
After setting up the redirection, Traffic Dashboard reflects that here. You can also set up a permanent rediection using traefik.ingress.kubernetes.io/redirect-permanent: "true