<p>I am running some internal services and also some customer facing services in one K8s cluster. The internal ones should only be accessible from some specific ips and the customer facing services should be accessible worldwide.</p>

<p>So I created my Ingresses and an nginx Ingress Controller and some K8s LoadBalancer Services with the proper ip filters. </p>

<p>Now I see those Firewall rules in GCP are created behind the scenes. But they are conflicting and the "customer facing" firewall rules overrule the "internal" ones. And so everything of my K8s Cluster is visible worldwide. </p>

<p>The usecase sounds not that exotic to me - do you have an idea how to get some parts of a K8s cluster protected by firewall rules and some accessible everywhere?</p>

<p>As surprising as it is, the L7 (http/https) load balancer in GCP created by a Kubernetes Ingress object <strong>has no IP whitelisting capabilities</strong> by default, so what you described is working as intended. You can filter on your end using the <code>X-Forwarded-For</code> header (see Target Proxies under <a href="https://cloud.google.com/compute/docs/load-balancing/http/" rel="nofollow noreferrer">Setting Up HTTP(S) Load Balancing</a>).</p>

<p>Whitelisting will be available trough <a href="https://cloud.google.com/armor/docs/security-policy-concepts" rel="nofollow noreferrer">Cloud Armour</a>, which is in private beta at the moment.</p>

<p>To make this situation slightly more complicated: the L4 (tcp/ssl) load balancer in GCP created by a Kubernetes LoadBalancer object (so, not an Ingress) does have IP filtering capability. You simply set <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service" rel="nofollow noreferrer"><code>.spec.loadBalancerSourceRanges</code></a> on the Service for that. Of course, a Service will not give you url/host based routing, but you can achieve that by deploying an ingress controller like <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">nginx-ingress</a>. If you go this route you can still create Ingresses for your internal services you just need to annotate them so the new ingress controller picks them up. This is a fairly standard solution, and is actually cheaper than creating L7s for each of your internal services (you will only have to pay for 1 forwarding rule for all of your internal services).</p>

<p>(By "internal services" above I meant services you need to be able to access from outside of the itself cluster but only from specific IPs, say a VPN, office, etc. For services you only need to access from inside the cluster you should use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer"><code>type: ClusterIP</code></a>)</p>
