Search code examples
azure-aksnginx-ingress

How to reduce CPU requirements of an AKS application routing ingress (nginx)


I've enabled nginx ingress on azure using az aks approuting enable -g ... -n ...

unfortunately, the deployment requires two pods, each of them requires 500m CPU. I would like to reduce this requirement to 100m.

I've tried kubectl edit deployment nginx but everytime I set 100m, aks would reapply the 500m requirement. Is there any way to change it to 100m?


Solution

  • Reducing the CPU requirements for the NGINX Ingress Controller in AKS, particularly when it is managed by Azure's own tooling such as the Application Gateway Ingress Controller (AGIC), can be challenging. This is because managed services typically enforce configuration settings to ensure stability and performance according to Azure's best practices and operational guidelines.

    When you use az aks approuting enable, you are essentially enabling a managed service. Azure manages the settings and configurations, including scaling and resource allocations, which is why your manual changes via kubectl edit deployment are being reverted.

    One approaches you can consider to reduce the CPU requirements for your NGINX Ingress setup is, instead of using Azure's managed NGINX Ingress, deploy your own NGINX Ingress Controller manually. This way, you have complete control over the deployment's configuration, including resource requests and limits.

    When deploying your own NGINX Ingress Controller, you can specify the resource requests and limits directly in the deployment YAML file.

    Example- You can modify the CPU requests and limits for the containers in the deployment manifest file locally and then apply it using the kubectl apply command.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx-ingress
      template:
        metadata:
          labels:
            app: nginx-ingress
        spec:
          serviceAccountName: nginx-ingress-serviceaccount
          containers:
          - name: nginx-ingress
            image: nginx/nginx-ingress:latest
            args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
            - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
            - --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller
            - --annotations-prefix=nginx.ingress.kubernetes.io
            - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
            resources:
              requests:
                cpu: 100m
              limits:
                cpu: 100m
    
    

    In this example, the CPU requests and limits for the nginx container have been set to 100m. You can modify the manifest file to suit your specific requirements.

    Once you've modified the manifest file, you can apply it using the kubectl apply command:

    kubectl apply -f demo-test.yaml
    
    

    enter image description here

    enter image description here

    Another option is scaing i.e. If the lower CPU limit leads to higher CPU usage, consider implementing HPA to dynamically scale the number of NGINX pods based on the current load.

    References: