<p>I'd like to create a nginx ingress controller with AWS internal NLB, the requirement is fix the IP address of NLB endpoint, for example, currently the NLB dns of Nginx ingress service is abc.elb.eu-central-1.amazonaws.com which is resolved to ip address 192.168.1.10, if I delete and re-create nginx ingress controller, I want the NLB DNS must be the same as before.
Having a look in kubernetes service annotation, I did not see any way to re-use existing NLB, however, I find out the annotation service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses in <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/guide/service/annotations/" rel="nofollow noreferrer">link</a>, as far as I understand that it allow me to set ip address for NLB, but it not work as my expectation, everytime I re-created nginx controller, the ip address is difference, Below is K8s service yaml file.</p>
<pre><code># Source: ingress-nginx/templates/controller-service.yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-internal: &quot;true&quot;
    service.beta.kubernetes.io/aws-load-balancer-type: &quot;nlb&quot;
    service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses: &quot;10.136.103.251&quot;
    service.beta.kubernetes.io/aws-load-balancer-subnets: &quot;subnet-00df069133b22&quot;
  labels:
    helm.sh/chart: ingress-nginx-3.23.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.44.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
</code></pre>
<p>I know this requirement is werid, is it possible to do that?</p>

Tien Dung Tran
<p>If your Kubernetes cluster runs on a VPC with more than one subnet (which is probably the case), you must provide a private ip address for each subnet.</p>
<p>I installed the <a href="https://docs.aws.amazon.com/eks/latest/userguide/aws-load-balancer-controller.html" rel="nofollow noreferrer">AWS Load balancer controller</a> with the helm chart, then i installed the nginx ingress controller with this helm chart :</p>
<pre><code>helm install nginx-ingress ingress-nginx/ingress-nginx --namespace nginx-ingress -f internal-ingress-values.yaml
</code></pre>
<p>Here the content of internal-ingress-values.yaml</p>
<pre><code>controller:
  ingressClass: nginx
  service:
    enableHttp: false
    enableHttps: true
    annotations:
      service.beta.kubernetes.io/aws-load-balancer-type: external
      service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
      service.beta.kubernetes.io/aws-load-balancer-scheme: internal
      service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses: 10.136.103.251, 10.136.104.251
      service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-00a1a7f9949aa0ba1, subnet-12ea9f1df24aa332c
  ingressClassResource:
    enabled: true
    default: true
</code></pre>
<p>According to the <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/guide/service/annotations/#subnets" rel="nofollow noreferrer">documentation</a> the <strong>service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses</strong> annotation <em>length/order must match subnets</em></p>
<p>So, you must provide IP addresses and subnet in the same order (don't mismatch).
If you take my example above, you must make sure that :</p>
<ul>
<li>10.136.103.251 is included in subnet-00a1a7f9949aa0ba1</li>
<li>10.136.104.251 is included in subnet-12ea9f1df24aa332c</li>
</ul>
<p>It's a good idea to tag your subnets according to the <a href="https://aws.amazon.com/fr/premiumsupport/knowledge-center/eks-vpc-subnet-discovery/" rel="nofollow noreferrer">documentation</a> :</p>
<p>Key: kubernetes.io/cluster/my-cluster-name
Value: shared</p>
<p>Key: kubernetes.io/role/internal-elb
Value: 1</p>
<p>I tested this K8S on 1.20 and it works for my project.
Don't provide &quot;ingressClassResource&quot; if you're on K8S &lt;= 1.17.</p>
