My ingress is not applied to expected controller

Reed Wei 0 Reputation points
2024-07-01T06:20:11.41+00:00

I have two loadbalancer service which has ip address 172.179.18.172 and 20.115.251.240 respectively. Let me name them LB(A) and LB(B).

NAMESPACE     NAME                                           TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE
default       ingress-nginx-controller                       LoadBalancer   10.0.194.0     172.179.18.172   80:32715/TCP,443:31290/TCP   2d2h
default       ingress-nginx-controller-admission             ClusterIP      10.0.110.53    <none>           443/TCP                      25d
kube-system   addon-http-application-routing-nginx-ingress   LoadBalancer   10.0.137.65    20.115.251.240   80:30319/TCP,443:31752/TCP   66d

I want to apply my ingress to LB(A). The configure file is as below:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: default-ingress
  annotations:
    kubernetes.io/ingress.class: nginx-custom
spec:
  ingressClassName: nginx-custom
  rules:
  - http:
      paths:
      - path: /xxx
        pathType: Prefix
        backend:
          service:
            name: xxx-service
            port:
              number: 8080

I set the ingress class name same as the one used for my LB(A) ingress controller, which is "ingress-custom" so it could find the correct controller. I was expecting my service to be available at " 172.179.18.172/xxx" from LB(A). But it gave me 404 page instead. And things get even stranger that the service is working at "20.115.251.240/xxx" from LB(B)

I have checked LB(B)'s controller configure and it has a complete different ingress-class name which is "addon-http-application-routing". It seems that "addon-http-application-routing" is taking over the ingress that should apply to the other ingress controller.

can someone help explain why does this happen.

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,984 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 7,126 Reputation points
    2024-07-01T21:23:29.71+00:00

    Hello Reed Wei,

    Welcome to the Microsoft Q&A and thank you for posting your questions here and for detail information.

    Problem

    I understand that you are having issues with your Ingress not applied to expected controller.

    Solution

    Regarding your question to explain why it happen, after careful analysis I found out that the ingressClassName is NOT correctly configured and the ingress controller associated with LB(A) is NOT properly set up to handle nginx-custom, to route traffic to the intended load balancer.

    To solve this issue, ensure to follow this procedures:

    1. Ensure that the ingress controller for LB(A) is correctly set up with the ingressClassName: nginx-custom.
      1. LB(A) should be configured with the correct --ingress-class=nginx-custom argument. Using bash: kubectl describe deployment ingress-nginx-controller -n default
      2. Look for the arguments section and ensure it includes: args:
        • /nginx-ingress-controller
        • --ingress-class=nginx-custom
      3. Verify that the ingress controller for LB(A) is running and recognizing the nginx-custom class using bash: kubectl logs <nginx-ingress-controller-pod-name> -n default
    2. Verify that the IngressClass resource is correctly defined and points to the appropriate controller.
      1. Create an IngressClass resource if it doesn’t exist in YAML:
              apiVersion: networking.k8s.io/v1
              kind: IngressClass
              metadata:
                name: nginx-custom
              spec:
                controller: k8s.io/ingress-nginx
        
      2. Apply the resource using Bash: kubectl apply -f ingressclass.yaml
      3. Check the details of the existing IngressClass to ensure it is correct using Bash. kubectl get ingressclass kubectl describe ingressclass nginx-custom
    3. Ensure that the deployments for both ingress controllers are correctly configured with the appropriate ingress class names.
      1. Ensure that the ingress controller for LB(A) has the correct annotations and is linked to the nginx-custom ingress class using Bash: kubectl describe deployment ingress-nginx-controller -n default
      2. Verify that the ingress controller for LB(B) has a different ingress class name and does not interfere with LB(A): kubectl describe deployment addon-http-application-routing-nginx-ingress -n kube-system Ensure it has the following or similar in YAML: args: - /nginx-ingress-controller - --ingress-class=addon-http-application-routing
    4. Apply and test your configuration:
      1. Ensure the ingress resource is correctly configured with ingressClassName: nginx-custom.
              apiVersion: networking.k8s.io/v1
              kind: Ingress
              metadata:
                name: default-ingress
                annotations:
                  kubernetes.io/ingress.class: nginx-custom
              spec:
                ingressClassName: nginx-custom
                rules:
                - http:
                    paths:
                    - path: /xxx
                      pathType: Prefix
                      backend:
                        service:
                          name: xxx-service
                          port:
                            number: 8080
        
      2. Apply the ingress resource: kubectl apply -f ingress-resource.yaml
      3. Verify that the service is accessible via LB(A). curl http://172.179.18.172/xxx

    References

    For more reading and detail steps kindly read use the following links:

    Source: NGINX Ingress Controller Arguments. Accessed, 7/1/2024.

    Source: IngressClass API. Accessed, 7/1/2024.

    Source: Kubernetes Deployment. Accessed, 7/1/2024.

    Source: Using Ingress. Accessed, 7/1/2024.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam