<p>Currently, I'm exposing a k8s service using network load balancer. It creates a network load balancer and sets the target group as instance based and everything works fine. As we know
port in the nodes is always in the range of 30000 - 32767.</p>
<p>There is a difference in the different target groups. Instance based target group is used to preserve the clientIP, where in IP based doesn't preserve the client IP.</p>
<p>Now there is a problem with the security group, I want to restrict the node ports only be accessible by the CIDR of load balancer. Since it is an instance based target group, inbound IP is always the client IP. So it is difficult to restrict the access only for certain IP's.</p>
<p>So my plan is to switch the target group to &quot;IP&quot; based, so that I can restrict the access to only for CIDR of load balancer.</p>
<p>Is there any other way to create the NLB load balancer with the IP based target type? Could you please help me with some suggestions?</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-router
  annotations:
    service.beta.kubernetes.io/do-loadbalancer-protocol: &quot;http&quot;
    service.beta.kubernetes.io/do-loadbalancer-healthcheck-path: &quot;/healthz&quot;
    service.beta.kubernetes.io/aws-load-balancer-type: &quot;nlb&quot;
    service.beta.kubernetes.io/aws-target-type: ip
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: [tes]

    # service.beta.kubernetes.io/healthcheck-path: /healthz
spec:
  selector:
    app: nginx-router
  externalTrafficPolicy: Local
  ports:
    - port: 80
      targetPort: 80
      protocol : TCP
      name : http
    - port : 443
      targetPort: 443
      protocol : TCP
      name : https

  type: LoadBalancer
</code></pre>

<p>I ask myself if you really need to solve this through the Network Load Balancer or if a solution in Kubernetes would be preferable.</p>
<p>The easiest way to remove a NodePort from the cluster is to actually not define any Services in Kubernetes of the type NodePort. If some already exist you can easily change them to type ClusterIP and the NodePort should be removed.</p>
<p>Since you wish to prevent any access to NodePorts you can consider using a ResourceQuota to prevent the creation any services of type NodePort at all. This way the cluster is telling the user that his services won't work instead of just preventing the traffic from reaching the application and most likely resulting in a hard to understand timeout if you don't know the specifics of the load balancer configuration. (See here for reference: <a href="https://kubernetes.io/docs/concepts/policy/resource-quotas/#object-count-quota" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/policy/resource-quotas/#object-count-quota</a>)</p>
