Home > database >  How to change Nginx Ingress port number?
How to change Nginx Ingress port number?

Time:04-27

I have a K8S service (app-filestash-testing) running like following:

NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)     AGE
app-filestash-testing   ClusterIP   10.111.128.18   <none>        10000/TCP   18h
kubernetes              ClusterIP   10.96.0.1       <none>        443/TCP     20h

I used the following yaml file to create an Ingress trying reach this service:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-filestash-testing
spec:
  rules:
  - host: www.masternode.com
    http:
      paths:
      - backend:
          serviceName: app-filestash-testing
          servicePort: 10000

In the /etc/hosts file, I made this change (I used the worker node public IP):

127.0.0.1 localhost
xx.xxx.xxx.xxx www.masternode.com

However, when I checked the Ingress, I saw that the Ingress port is 80.

NAME                    CLASS   HOSTS                ADDRESS   PORTS   AGE
app-filestash-testing   nginx   www.masternode.com             80      14h

Currently the service is running and listening on port 10000, but the Ingress port is 80.

I am just wondering is there any method/ setting to change the port number of Ingress to 10000? How to reach this service through Ingress? Is is possible to set the port number in /etc/hosts file?

Thanks.

CodePudding user response:

From: https://kubernetes.io/docs/concepts/services-networking/ingress/#what-is-ingress

An Ingress does not expose arbitrary ports or protocols. Exposing services other than HTTP and HTTPS to the internet typically uses a service of type Service.Type=NodePort or Service.Type=LoadBalancer.

NodePort might be what you are looking for. More information and options are documented here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

CodePudding user response:

In a regular ingress you can't set a specific port, by which the ingress will be reachable.
In some specific circumstances it could theoretically be possible, through adding specific annotations, but I don't believe there is such a thing for nginx-ingress.

It is however entirely possible to have a ingress class that is accessible over a different port.
I'm not familiar enough with nginx-ingress to say how to do it there, but if you were to use ingress-nginx instead, there are settings that change these ports.
Through installing this ingress class with helm for example, you can supply the values controller.service.ports.http which defaults to 80, and/or controller.service.ports.https which defaults to 443.
Very likely there is a way to do this for nginx-ingress as well. You have to consider however if the added complexity is really worth it, when you only want to change the port.

  • Related