In our on-premise environment, we have a Kubernetes (K8s) infrastructure where multiple microservices are deployed. Since the LoadBalancer service type is not supported in our on-premise setup, we utilize the NodePort service type to expose the microservices externally. The NodePort services open specific ports on all the nodes in the cluster, allowing external traffic to access the microservices.
To manage and route this external traffic efficiently, we have an NGINX API Gateway positioned in front of the NodePort services. The NGINX API Gateway acts as the single entry point for all external HTTP requests. It is configured with specific HTTP routing rules to direct incoming requests to the appropriate NodePort, ensuring that the right microservices handle them.
This architecture allows us to maintain a secure and scalable API management layer while effectively utilizing the existing on-premise infrastructure.
Our goal is to ensure that the NodePort services in our on-premise Kubernetes cluster are only accessible by the NGINX API Gateway. We aim to restrict all external traffic so that any requests not originating from the NGINX API Gateway are denied. This security measure ensures that the microservices behind the NodePort are protected and that only authorized traffic, routed through the API Gateway, can interact with them.
Kubernetes Network Policies are a set of rules used to control the traffic flow between pods within a Kubernetes cluster, as well as between pods and external endpoints. They define how pods communicate with each other and with the outside world, providing a way to enforce security at the network level.
Ingress, Egress, or both types of rules.k8s default network policy said we can allow/deny the network cidr blocks. It seems that it is a solution we are looking for to whitelist the nginx api gateway via k8s.
This diagram illustrates the expected behavior when a network policy is applied to whitelist the CIDR blocks of the NGINX API Gateway while blocking all other traffic. This ensures that all external traffic must route through the NGINX API Gateway before reaching the services.
