Skip to content

NIC Fails to Resolve Named Ports with nginx.org/use-cluster-ip Annotation #4970

@j1m-ryan

Description

@j1m-ryan

Describe the bug

@btsuhako encountered a bug with the current implementation of the nginx.org/use-cluster-ip annotation. It does not currently account for named ports.

To Reproduce

  1. Adjust the example in examples/ingress-resources/complete-example changing the field inside port from number: 80 to name: http
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cafe-ingress
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - cafe.example.com
    secretName: cafe-secret
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea
        pathType: Prefix
        backend:
          service:
            name: tea-svc
            port:
              name: http 
      - path: /coffee
        pathType: Prefix
        backend:
          service:
            name: coffee-svc
            port:
              name: http
  1. Apply this example with kaf ./examples/ingress-resources/complete-example/
  2. minikube tunnel
  3. Observer that you can curl -k https://cafe.example.com/tea and curl -k https://cafe.example.com/coffee
  4. Now add the use-cluster-ip annotation as follows.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    nginx.org/use-cluster-ip: "True"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - cafe.example.com
    secretName: cafe-secret
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea
        pathType: Prefix
        backend:
          service:
            name: tea-svc
            port:
              name: http 
      - path: /coffee
        pathType: Prefix
        backend:
          service:
            name: coffee-svc
            port:
              name: http
  1. kaf ./examples/ingress-resources/complete-example/
  2. Observe the following error in the config
I0123 17:23:46.869185       1 event.go:364] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"cafe-ingress", UID:"ac9ee504-ef49-4e2c-8cac-458da477078f", APIVersion:"networking.k8s.io/v1", ResourceVersion:"2009", FieldPath:""}): type: 'Warning' reason: 'AddedOrUpdatedWithError' Configuration for default/cafe-ingress was added or updated ; but was not applied: error reloading NGINX for default/cafe-ingress: nginx reload failed: command /usr/sbin/nginx -s reload -e stderr stdout: ""
stderr: "2024/01/23 17:23:46 [emerg] 77#77: invalid port in upstream \"coffee-svc.default.svc.cluster.local:0\" in /etc/nginx/conf.d/default-cafe-ingress.conf:4\n"

Expected behavior
NIC handles the two mutually exclusive ways of defining a Port for the use-cluster-ip annotation. Number, or Name

Your environment

  • Version of the Ingress Controller: 3.4.2-snapshot
  • Version of Kubernetes: 1.28
  • Kubernetes platform (e.g. Mini-kube or GCP): minikube
  • Using NGINX or NGINX Plus: NGINX

Additional context
Add any other context about the problem here. Any log files you want to share.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalAn issue that proposes a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions