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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 Integration Platform as a Service (iPaaS) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In todayโ€™s fast-paced digital world, businesses are leveraging multiple software applications, cloud services, and data sources to streamline operations. However, the challenge lies in integrating these…

Read More

IReviewed Blog’s Post List

truereviewnow.com is a portal for product review and rating. truereviewnow.com is having very in-depth analysis of review and testimony of Mobiles, Laptop, Electronics Gadgets, Airports, Boradbands, Movies…

Read More

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

Introduction In 2026, social media continues to be a cornerstone of digital marketing strategies, shaping how businesses connect with their audiences. With millions of users interacting on…

Read More

Top 10 Drone Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, drones are not only revolutionizing industries like agriculture, logistics, filmmaking, and construction, but also the way we collect and process data. Drone software is…

Read More

Top 10 AI Survey Automation Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI Survey Automation Tools are transforming the way businesses, researchers, and organizations gather and analyze feedback. Traditional survey platforms often relied on static questions…

Read More

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

Introduction In 2026, AI animation tools are revolutionizing how creators, businesses, and educators bring stories to life, making animation accessible to all skill levels. These tools leverage…

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