# Deploy the NGINX Ingress Controller

To deploy the **NGINX Ingress Controller** in an **Azure Kubernetes Service (AKS)** cluster using the **Helm chart** with Pulumi and retrieve the **LoadBalancer IP** of the ingress controller, you can follow these steps. I'll also mention some optimizations that can be useful for production environments, such as ensuring resource limits and using stable versions of Helm charts.

**Write Pulumi Code to Deploy NGINX Ingress Controller**

The code will deploys the NGINX Ingress Controller using the official **Helm chart**.

```typescript
import * as k8s from "@pulumi/kubernetes";
import { config } from "../config";

export const nginxIngressController = (k8sProvider) => {
//   // Deploy the NGINX Ingress Controller
  const nginxIngressController = new k8s.helm.v4.Chart("nginx-ingress-controller", {
    chart: "nginx-ingress-controller",
    namespace: config.ingressNamespace,
    version: "11.4.1", // Pin the Helm chart version for production stability
    repositoryOpts: {
        repo: "https://charts.bitnami.com/bitnami"
    },
    values: {
        controller: {
            service: {
                type: "LoadBalancer",
            }
        },
        resources: {
            limits: {
                cpu: "500m",
                memory: "512Mi", // Set resource limits for production optimization
            },
            requests: {
                cpu: "250m",
                memory: "256Mi",
            },
        }
    }
  }, { provider: k8sProvider });

  return nginxIngressController.resources;

}

```

#### Explanation of the Code:

* We deploy the NGINX Ingress Controller using the **Helm chart** from Bitnami package for NGINX Ingress Controller
* We specify the **`service.type`** as `LoadBalancer` so that Azure will provision a public IP address for the ingress controller.
* **Resource Limits**: In production environments, it is essential to define **resource limits** for CPU and memory to ensure that the ingress controller doesn't consume excessive resources and cause issues in the cluster.
* **Versioning**: It's a best practice to pin the Helm chart to a specific version (e.g., 1`.11.2`) to avoid unexpected behavior due to future updates. This ensures stability in production environments.

From the index.ts file, you will modify the code to deploy Nginx Ingress Controller to the AKS cluster:

```typescript
...
import { nginxIngressController } from "./resources/nginxingresscontroller";
...

import { config } from "./config";

// Create an Azure Resource Group
const resourceGroup = new resources.ResourceGroup("resourceGroup", {
    resourceGroupName: "pulumi-aks-rg",
    location: config.location
});

...

// Install the NGINX Ingress Controller and expose it as a LoadBalancer service so that it has an external IP address.
const ingressController = nginxIngressController(provider);
..

export const resourceGroupName = resourceGroup.name;
```

Now, you can deploy your AKS cluster and the NGINX ingress controller with Pulumi:

```
pulumi up
```

### Verify NGINX Ingress Controller

Once the deployment is finished, you can verify that the NGINX ingress controller has been successfully deployed and is up and running:

```bash
$kubectl get services -n ingress-nginx
NAME                                       TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)                      AGE
nginx-ingress-controller                   LoadBalancer   10.0.226.2    104.43.76.238   80:30806/TCP,443:30820/TCP   87m
nginx-ingress-controller-default-backend   ClusterIP      10.0.26.148   <none>          80/TCP                       87m
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hahoangv.gitbook.io/azure-kubernetes-service/hands-on-provisioning-and-configuring-an-aks-cluster-on-azure-with-pulumi/deploy-ingress-controller-and-configure-ssl-tls/deploy-the-nginx-ingress-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
