Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Kubernetes Ingress Rules: Complete Guide with Examples

Hereโ€™s a comprehensive, practical, and easy-to-follow tutorial on all main types of Kubernetes Ingress rulesโ€”with detailed explanations, diagrams, and YAML examples for each. This guide is aimed at both beginners and advanced users and covers every core ingress rule type youโ€™ll encounter, including real-world use cases.


๐Ÿš€ Kubernetes Ingress Rules: Complete Guide with Examples


Table of Contents

  1. What is Kubernetes Ingress?
  2. Types of Ingress Rules
    • Host-based Routing
    • Path-based Routing
    • Combined Host & Path Routing
    • Default Backend (Catch-all)
    • TLS/SSL Rules
    • Advanced (Rewrite/Redirect, Auth, Rate Limiting)
  3. Examples and Use Cases
  4. Visual Summary
  5. FAQ & Tips

1. What is Kubernetes Ingress?

  • Ingress is a Kubernetes resource that manages external access to your cluster services, typically HTTP/HTTPS.
  • With Ingress, you can expose multiple apps under different domains/paths using a single load balancer or IP.
  • An Ingress Controller (like NGINX, AWS ALB, Traefik, etc.) implements the routing specified in your Ingress resource.

2. Types of Ingress Rules

A. Host-based Routing (Name-based Routing)

What it is:
Route traffic to different services based on the requested domain name (host).

Use Case:
You have multiple apps, each with its own subdomain or domain (e.g., app1.example.com, app2.example.com).

Example YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: host-based-ingress
spec:
  rules:
    - host: app1.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app1
                port:
                  number: 80
    - host: app2.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app2
                port:
                  number: 80

Diagram:

(app1.example.com) --> [Ingress] --> [app1 Service]
(app2.example.com) --> [Ingress] --> [app2 Service]
Code language: CSS (css)

B. Path-based Routing (URL Path Routing)

What it is:
Route traffic to different services based on the URL path.

Use Case:
Expose multiple apps under different paths of the same domain (e.g., /api, /shop).

Example YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: path-based-ingress
spec:
  rules:
    - host: www.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80
          - path: /shop
            pathType: Prefix
            backend:
              service:
                name: shop-service
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web-service
                port:
                  number: 80

Diagram:

(www.example.com/api)  --> [Ingress] --> [api-service]
(www.example.com/shop) --> [Ingress] --> [shop-service]
(www.example.com/)     --> [Ingress] --> [web-service]

C. Combined Host and Path-based Routing

What it is:
Use both host and path to route traffic for fine-grained control.

Use Case:
Same domain serves different apps under different paths, and you have more than one domain.

Example YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: combined-ingress
spec:
  rules:
    - host: admin.example.com
      http:
        paths:
          - path: /dashboard
            pathType: Prefix
            backend:
              service:
                name: admin-dashboard
                port:
                  number: 80
    - host: shop.example.com
      http:
        paths:
          - path: /cart
            pathType: Prefix
            backend:
              service:
                name: cart-service
                port:
                  number: 80

Diagram:

(admin.example.com/dashboard) --> [Ingress] --> [admin-dashboard]
(shop.example.com/cart)       --> [Ingress] --> [cart-service]

D. Default Backend (Catch-all Rule)

What it is:
A default backend serves any request that doesnโ€™t match the host/path rules above (often a 404 or static site).

Use Case:
Handle “not found” errors or serve a default landing page.

How to set:

  • For NGINX, add a path: / rule without host or at the bottom.
  • For AWS ALB Ingress, define a backend with path / and no host, or use a dedicated default backend controller.

Example YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: default-backend-ingress
spec:
  defaultBackend:
    service:
      name: default-backend
      port:
        number: 80
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app-service
                port:
                  number: 80
Code language: PHP (php)

Diagram:

(Any unmatched domain/path) --> [Ingress] --> [default-backend]
Code language: JavaScript (javascript)

Note: The exact method depends on your Ingress controller version.


E. TLS/SSL Rules

What it is:
Specify which hosts should use HTTPS and which certificate to use for encryption.

Use Case:
Serve your app securely over HTTPS.

NGINX Example:

spec:
  tls:
    - hosts:
        - www.example.com
      secretName: my-tls-secret
  rules:
    - host: www.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web-service
                port:
                  number: 80
  • my-tls-secret is a Kubernetes TLS secret with your certificate and private key.

AWS ALB Example:

metadata:
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:REGION:ACCOUNT:certificate/XXXX
  • The annotation links your ACM certificate to the ALB for HTTPS.

Diagram:

(Browser --HTTPS--> ALB) --HTTP--> [Service]
Code language: CSS (css)

F. Advanced Rules

1. Rewrite/Redirect Rules

  • Modify the URL path before passing to backend, or redirect to another location.
  • Often set using annotations (varies by controller).

2. Authentication Rules

  • Protect paths with Basic Auth, OAuth2, or custom headers.
  • Usually via annotations or external Auth service.

3. Rate Limiting / WAF

  • Control request rates or apply security policies.
  • Usually via annotations/integration with external tools.

3. Examples and Use Cases Table

Rule TypeUse Case ExampleYAML LocationExample Controller Features
Host-basedSubdomains for separate appsrules.hostAll controllers
Path-basedSingle domain, multiple apps (microservices)rules.http.pathsAll controllers
Host + PathMulti-tenant or region-based routingBothAll controllers
Default BackendCatch-all for 404 or static pagedefaultBackendAll controllers
TLS/SSLEnable HTTPS with certs for securitytls / annotationNGINX/ALB/Traefik (cert or ACM annotation)
Rewrite/RedirectSEO, cleaner URLs, app migrationannotationsNGINX, Traefik
AuthenticationProtect admin panels, APIs, dashboardsannotationsNGINX, Traefik, Kong, custom plugins
Rate Limiting/WAFThrottle abusive users, block attacksannotationsNGINX, Kong, ALB WAF

4. Visual Summary

        +-------------------------+
        |  Ingress Controller     |
        +-------------------------+
         |           |           |
     Host1      Host2+Path     Default
      |             |             |
  [ServiceA]   [ServiceB]    [Default Svc]
Code language: PHP (php)

5. FAQ & Tips

Q: Can I use all rule types in one Ingress?
A: Yes! You can combine host, path, TLS, and advanced rules as needed.

Q: What about gRPC?
A: Use the right annotation (e.g., alb.ingress.kubernetes.io/backend-protocol-version: GRPC for AWS) and make sure your ingress controller supports gRPC routing.

Q: What happens if rules overlap?
A: The most specific rule (exact match > prefix match > default) wins.

Q: Can I redirect HTTP to HTTPS?
A: Yes, with annotations or controller config. For ALB, use alb.ingress.kubernetes.io/ssl-redirect: '443'.


6. Full Example: Real-World Multi-rule Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: complex-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-northeast-1:123456789012:certificate/abcd1234
    alb.ingress.kubernetes.io/ssl-redirect: '443'
    alb.ingress.kubernetes.io/backend-protocol-version: GRPC
spec:
  tls:
    - hosts:
        - www.example.com
      secretName: my-tls-secret         # For NGINX/Traefik; ignored by ALB
  rules:
    - host: www.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80
          - path: /shop
            pathType: Prefix
            backend:
              service:
                name: shop-service
                port:
                  number: 80
    - host: admin.example.com
      http:
        paths:
          - path: /dashboard
            pathType: Prefix
            backend:
              service:
                name: admin-dashboard
                port:
                  number: 80
    # Default backend or more hosts/paths as needed

Conclusion

  • Host-based: Route by domain.
  • Path-based: Route by URL path.
  • Combined: Mix host/path for precise routing.
  • Default backend: Catch all requests not matched.
  • TLS: Secure HTTPS by mapping domain(s) to certificate(s).
  • Advanced: Use controller features for rewrites, redirects, auth, WAF, etc.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Hereโ€™s a clear and professional explanation of the three related concepts you asked about โ€” all of which are critical parts of secure software development, especially in…

Read More

Top 10 AI Code Review Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI code review tools have become essential for developers aiming to enhance code quality, streamline workflows, and accelerate software delivery. These tools leverage advanced…

Read More

Top 10 Expense Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction Expense management tools are critical for businesses of all sizes in 2026 as they help streamline financial processes, improve budgeting, ensure compliance, and enhance financial visibility….

Read More

Top 10 Web Application Firewall (WAF) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In the rapidly evolving landscape of cybersecurity, Web Application Firewalls (WAFs) have become a critical component in defending web applications from malicious attacks such as SQL…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x