How to configure a kubernetes bare-metal ingress controller to listen to port 80?

Viewed 2157

I have a kubernetes setup with 1 master and 1 slave, hosted on DigitalOcean Droplets. For exposing my services I want to use Ingresses.

As I have a bare metal install, I have to configure my own ingress controller. How do I get it to listen to port 443 or 80 instead of the 30000-32767 range?

For setting up the ingress controller I used this guide: https://kubernetes.github.io/ingress-nginx/deploy/

My controller service looks like this:

apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx

And now obviously, because the NodePort range is 30000-32767, this controller doesn't get mapped to port 80 or 443:

➜ kubectl get services --all-namespaces
NAMESPACE       NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   ingress-nginx          NodePort    10.103.166.230   <none>        80:30907/TCP,443:30653/TCP   21m
2 Answers

I agree with @Matthew L Daniel, if you don't consider to use external load balancer, the best option would be sharing host network interface with ingress-nginx Pod by enabling hostNetwork option in the Pods' spec:

template:
  spec:
    hostNetwork: true

Thus, NGINX Ingress controller can bind ports 80 and 443 directly to Kubernetes nodes, without mapping special proxy ports (30000-32767) to the nested services. Find more information here.

You can’t bind ingress service to port 80. You can run HAProxy on the host and redirect port 80,443 request Ingress service port number.

Related