Kubernetes Handbook

    Key Components of Ingress in Kubernetes

    Introduction#

    Hie devs, Remember how we turned you into an Ingress fan with our last blog, where we explored what is Ingress using a Swiggy-like food delivery app? We saw how Ingress acts like a friendly guide, directing web requests from swiggy.com/restaurants to restaurant services and swiggy.com/instamart to grocery services. Now, it’s time to peek under the hood and uncover the key components of Ingress that make this magic happen: Ingress Resources and Ingress Controller. In this blog, we’ll break down these components with super simple examples, so you’ll understand how they power traffic routing. Get ready to level up your Kubernetes game faster than Swiggy delivers your pizza! 🍕😊

    Quick Recap: What is Ingress?#

    Before we dive in, let’s refresh. Ingress is like the cheerful guide at a Swiggy-like food stall, sending web requests (like swiggy.com/restaurants) to the right API Gateway counter (like restaurant or Instamart services). It keeps everything under one website (swiggy.com), makes the app fast, and keeps your payment info safe with HTTPS. But how does Ingress pull this off? That’s where its two key components—Ingress Resources and Ingress Controllers—come in. Think of them as the guide’s map and megaphone, working together to direct traffic. Let’s meet them!

    Component 1: Ingress Resource – The Traffic Map#

    What is an Ingress Resource?#

    An Ingress Resource is like a map that tells Ingress where to send web requests. It’s a simple file (written in YAML) where you write rules, like “Send swiggy.com/restaurants to the restaurant gateway” or “Send swiggy.com/instamart to the instamart-gateway.” This map lives in your Kubernetes cluster and gives Ingress the instructions it needs to guide users.

    How It Works in a Swiggy-Like App#

    Imagine you’re the guide at our Swiggy-like food stall. Your map (the Ingress Resource) says:

    • If someone visits /restaurants, send them to the restaurant-api-gateway counter.
    • If they visit /instamart, send them to the instamart-api-gateway counter.

    When a user goes to swiggy.com/restaurants, Ingress checks the map and follows its rules to direct the request to the right API Gateway service.

    Example 1: Restaurant Orders

    You visit swiggy.com/restaurants to browse menus. The Ingress Resource has a rule that says, “Route /restaurants to restaurant-api-gateway.” Ingress follows this rule, and you see a list of burger joints. Without the Ingress Resource, Ingress would be clueless about where to send you!

    Example 2: Instamart Groceries

    You hit swiggy.com/instamart to buy snacks. The Ingress Resource says, “Route /instamart to instamart-api-gateway.” Ingress sends your request to the grocery counter, and you get a catalog of chips and sodas. The map makes it all happen!

    A Simple Ingress Resource YAML#

    Here’s what an Ingress Resource might look like for our Swiggy-like app. Don’t worry if it looks like gibberish—we’ll break it down!

    apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: food-app-ingress spec: rules: - host: swiggy.com http: paths: - path: /restaurants pathType: Prefix backend: service: name: restaurant-api-gateway port: number: 80 - path: /instamart pathType: Prefix backend: service: name: instamart-api-gateway port: number: 80

    What’s Happening Here?

    • kind: Ingress: Tells Kubernetes this is an Ingress Resource.
    • metadata.name: Names the resource (e.g., food-app-ingress).
    • spec.rules: Lists the traffic rules.
    • host: swiggy.com: Says these rules apply to swiggy.com.
    • paths: Defines two paths:
      • /restaurants goes to restaurant-api-gateway on port 80.
      • /instamart goes to instamart-api-gateway on port 80.
    • pathType: Prefix: Means the path can match /restaurants or anything starting with it (like /restaurants/pizza).

    This YAML is like writing directions on the guide’s map, telling Ingress exactly where to send users.

    My First YAML Fumble: When I first wrote an Ingress Resource, I forgot to set the pathType, and my app sent all traffic to the wrong service! 😬 It was like giving the guide a map with no street names. Once I fixed it, Ingress worked like a charm, and I felt like a Kubernetes rockstar!

    Component 2: Ingress Controller – The Traffic Megaphone#

    What is an Ingress Controller?#

    An Ingress Controller is like a megaphone that makes the Ingress Resource’s rules come to life. It’s a piece of software running in your Kubernetes cluster that reads the Ingress Resource’s map and shouts, “Hey, send this request to the right counter (service)!” Without the Ingress Controller, the Ingress Resource is just a piece of paper—useless without someone to follow its instructions.

    How It Works in a Swiggy-Like App#

    Think of the Ingress Controller as the guide’s megaphone at our Swiggy-like food stall. It reads the Ingress Resource’s rules and directs traffic accordingly. For example:

    • When you visit swiggy.com/restaurants, the Ingress Controller sees the rule for /restaurants and sends your request to restaurant-api-gateway.
    • For swiggy.com/instamart, it follows the rule for /instamart and sends it to instamart-api-gateway.

    The Ingress Controller also handles cool stuff like load balancing (spreading traffic across workers) and HTTPS (keeping your data safe).

    Example 3: Restaurant Rush

    During a dinner rush, tons of users hit swiggy.com/restaurants. The Ingress Controller reads the Ingress Resource, routes requests to restaurant-api-gateway, and spreads them across multiple restaurant workers to keep the app fast. It’s like the guide shouting, “Restaurant counter, get ready for a crowd!”

    Example 4: Secure Instamart Payments

    You pay for groceries at swiggy.com/instamart. The Ingress Controller ensures the connection is secure (HTTPS) and routes the request to instamart-api-gateway. Your payment info stays safe, and you get your snacks without a hitch.

    There are different types of Ingress Controllers, like different megaphones for our guide. Some popular ones include:

    • NGINX Ingress Controller: A common choice, like a reliable megaphone that’s easy to use.
    • Traefik: A modern option, like a fancy megaphone with extra features.
    • HAProxy: A powerful choice for big apps, like a megaphone for a huge crowd.

    For our Swiggy-like app, any of these could work. You install one Ingress Controller in your cluster, and it handles all your Ingress Resources.

    Quick Note: You need to install an Ingress Controller before your Ingress Resource can work. It’s like giving the guide a megaphone before they can start directing people. Your cloud provider or Kubernetes setup guide will show you how to install one.

    My Controller Confusion: When I first used Ingress, I created an Ingress Resource but forgot to install an Ingress Controller. Nothing worked, and I was so confused! 😅 It was like handing the guide a map but no megaphone. Once I installed the NGINX Ingress Controller, traffic flowed perfectly, and I was back in business!

    How Ingress Resource and Controller Work Together#

    Now that we know the two components, let’s see how they team up in our Swiggy-like app:

    1. You Create the Map: You write an Ingress Resource (like the YAML above) with rules for /restaurants and /instamart.
    2. The Megaphone Reads It: The Ingress Controller reads the Ingress Resource’s rules.
    3. Traffic Gets Directed: When users visit swiggy.com/restaurants, the Ingress Controller follows the rules, sending requests to restaurant-api-gateway. Same for /instamart to instamart-api-gateway.
    4. Everyone’s Happy: Users get their menus or groceries, the app stays fast, and your data is secure.

    Example 5: A Busy Evening

    It’s a rainy evening, and users flood swiggy.com/restaurants and swiggy.com/instamart. The Ingress Resource provides the rules, and the Ingress Controller uses them to route traffic to the right API Gateways. It also balances the load and ensures HTTPS, so the app runs smoothly and safely.

    Why This Matters: The Ingress Resource and Controller are like a perfect duo—the map sets the plan, and the megaphone makes it happen. Together, they make Ingress the ultimate traffic guide.

    When to Use These Components#

    You’ll use the Ingress Resource and Ingress Controller whenever you need Ingress in your app:

    • Web Traffic: For routing web requests (HTTP/HTTPS) to API Gateways.
    • Single Website: To keep everything under one domain like swiggy.com.
    • Busy Apps: To handle lots of users with load balancing.
    • Secure Connections: To protect user data with HTTPS.

    Conclusion#

    In this blog, you mastered the key components of Ingress in Kubernetes with fun, beginner-friendly examples from a Swiggy-like food delivery app. You learned how the Ingress Resource acts like a map to route traffic to /restaurants and /instamart, and how the Ingress Controller makes those rules work like a megaphone. You saw how they team up to make the app easy, fast, and safe, and when to use them.

    What’s Next? In the next blog, we’ll explore Use cases of Ingress in Kubernetes, Stay tuned, and keep rocking your Kubernetes journey!

    Last updated on May 06, 2025