Google Kubernetes Engine How to define one Ingress for multiple namespaces?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Google Kubernetes Engine (GKE) enables users to deploy, manage, and scale containerized applications using Kubernetes. One of the key features of GKE is its robust capabilities for managing network traffic, especially through the Ingress resource. By default, Ingress allows you to expose HTTP and HTTPS routes to services within a single namespace. However, in more advanced configurations, you may want to expose services across multiple namespaces with a single Ingress resource. This article explores how to achieve this by utilizing annotations, custom resource definitions, and Ingress controllers.
Prerequisites
- A Google Cloud account with permissions to create and manage GKE clusters.
- A GKE cluster with at least one node.
- `kubectl` CLI tool configured to access your GKE cluster.
- Basic understanding of Kubernetes, including services, pods, and namespaces.
Understanding Kubernetes Namespaces
Kubernetes namespaces provide a way to divide cluster resources within a single GKE cluster. This logical separation is useful for isolating resources, enforcing access policies, and organizing different environments such as development, staging, and production. However, the default Ingress configuration in Kubernetes is limited to single namespaces due to security and isolation reasons.
Challenges with Multi-namespace Ingress
The primary challenge of using an Ingress resource across multiple namespaces is maintaining the above-mentioned logical isolation while ensuring the required services can be accessed. This requires proper configuration without breaking namespace isolation principles.
Solutions for Multi-namespace Ingress in GKE
1. Shared Ingress with Annotations
To define a single Ingress resource for multiple namespaces, you can leverage annotations that enable cross-namespace traffic management.
Step-by-step Implementation:
- Deploy Services and Pods: Ensure each namespace has the appropriate pods and services running. For example:
- protocol: TCP
- protocol: TCP
- Create a Shared Ingress: In a shared namespace (commonly `default`), define an Ingress with cross-namespace annotations.
- host: frontend.example.com
- path: /
- host: backend.example.com
- path: /
- Deploy the NGINX ingress controller:
- Define an Ingress resource using service names with namespace qualifiers:
- host: frontend.example.com
- path: /
- host: backend.example.com
- path: /
- Security Policies: Ensure proper NetworkPolicy objects are in place to control traffic between namespaces.
- RBAC Configuration: Properly configure Role-Based Access Control (RBAC) to avoid unauthorized access to resources.
- Monitoring: Use tools like Prometheus and Grafana for monitoring cross-namespace traffic and resource utilization.

