Kubernetes
Ingress Rules
Wildcard Subdomain
Specific Subdomain
Networking

Kubernetes ingress rules How to use wildcard and specific subdomain together

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Understanding Kubernetes Ingress Rules for Wildcard and Specific Subdomain Usage

Kubernetes ingress controllers are a powerful tool for managing external access to services in a cluster. They provide a clean way to expose HTTP and HTTPS routes, and can handle high-level routing and advanced traffic policies. A crucial part of configuring an ingress controller is defining ingress rules that map external requests to the appropriate services within the cluster.

Wildcard and Specific Subdomain Ingress Rules

When dealing with multiple domains or subdomains, the need often arises to use both specific and wildcard subdomains. This capability ensures that both general and specific requests can be correctly routed to their respective services. Let's dive into how you can use both wildcard and specific subdomain rules in Kubernetes ingress.

Technical Explanation

Kubernetes ingress rules can define hostnames with special annotations or paths that allow for broad or specific matches. Host names can be defined using wildcard characters, specifically the asterisk (`*`), which stands in for one or more labels.

Here’s how you can set up ingress rules to handle both specific and wildcard subdomains:

Specific Subdomain

A specific subdomain rule will match requests explicitly for defined hostnames. For instance, if your service should respond only to `app.example.com`, you would define the ingress rule for this exact hostname. Here's an example YAML configuration for a specific subdomain:

  • host: app.example.com
    • path: /
  • host: '*.example.com'
    • path: /
  • host: app.example.com
    • path: /
  • host: '*.example.com'
    • path: /
  • Ingress Controller Configuration: Begin by ensuring that your ingress controller supports wildcard subdomains. Some ingress controllers may require specific annotations or configurations.
  • TLS Configuration: When using TLS, ensure the applicable certificates cover the wildcard or specific subdomains as needed. DNS-validated wildcard certificates can simplify this.
  • Testing: It's pertinent to test both specific and wildcard configurations to ensure that no domain is inadvertently left without proper routing.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.