Getting Real IP to Kubernetes Pods using Traefik and DigitalOcean

3.5k views Asked by At

I am trying to get the real source IP addresses to my Kubernetes pods using traefik. I am using the digital ocean load balancer which has the proxy protocol enabled. I have also configured my K8s service yaml to set the External Traffic policy to local.

Extract from my configmap in K8s for Traefik Ingress. I've redacted my actual IPs but I use my load balancer IP and Kubernetes worked node private IPs

  [entryPoints]
      [entryPoints.http]
        address = ":80"

        compress = true
        [entryPoints.http.redirect]
        entryPoint = "https"
      [entryPoints.https]

        address = ":443"
        compress = true
        [entryPoints.https.tls]
          [[entryPoints.https.tls.certificates]]
          CertFile = "/ssl/client_co.crt"
          KeyFile = "/ssl/tls.key"
        [entryPoints.https.proxyProtocol]
          trustedIPs = ["Load Balancer IP, Kubernetes Worker Node IPs"]


      [entryPoints.https.redirect]
        regex = "^https://(?:www\\.)(.*)"
        replacement = "https://$1"
        permanent = true

This is part of the deployment file service yaml

  kind: Service
    apiVersion: v1
    metadata:
      name: traefik-ingress-service
      annotations:
        service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
      namespace: kube-system
    spec:
      selector:
        k8s-app: traefik-ingress-lb
      ports:
        - protocol: TCP
          port: 80
          name: web
        - protocol: TCP
          port: 443
          name: https
        # - protocol: TCP
        #   port: 8080
          name: admin
      type: LoadBalancer
      externalTrafficPolicy: Local

Any help is always appreciated.

0

There are 0 answers