Search code examples
kubernetestraefik-ingress

How to remove nodePort Kubernetes - Traefik ingress controller


Following this tutorial:

https://medium.com/kubernetes-tutorials/deploying-traefik-as-ingress-controller-for-your-kubernetes-cluster-b03a0672ae0c

I am able to access the site by visiting www.domain.com:nodePort

Is it possible to omit nodePort part? Could you provide example?


Solution

  • Is it possible to omit nodePort part?

    Yes and No.

    • Not directly. Kubernetes always exposes external services even LoadBalancer type of services on a node port.
    • Yes. If you front it with a load balancer. Either your own that forwards port 80 and/or 443 to your NodePort or a LoadBalancer type of service which essentially sets up an external load balancer that forwards traffic to your NodePort.

    Could you provide an example?

    The NodePort service to expose your ingress is basically the same, you just need to setup your own external load balancer. (i.e AWS ELB/ALB/NLB, GCP load balancer, Azure load balancer, F5, etc, etc)

    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: NodePort
    

    The LoadBalancer type is just a change on the type of service:

    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 
    

    In the case above, Kubernetes will automatically manage the load balancer in the provider.