# Ingress

Imagine your Kubernetes cluster as a bustling city. Each service within it is like a different neighborhood, each with its own unique function. But how do people (or rather, network requests) find their way to the right neighborhood? That's where Ingress comes in.

**What is Ingress?**

Ingress is like a traffic cop, directing incoming traffic to the right destination. It's a Kubernetes resource that exposes HTTP and HTTPS services outside the cluster. Think of it as a bridge between the internet and your internal services.

![Kubernetes Ingress Controllers: How to choose the right one: Part 1 | by  Eric Liu | ITNEXT](https://miro.medium.com/v2/resize:fit:1400/1*SQo8z4twffMy0fdJfhvEcw.png align="left")

**How Does Ingress Work?**

1. **Define Rules:** You create Ingress resources to specify how traffic should be routed. For instance, you might define a rule that says, "If a request comes in for `/products`, send it to the 'product-service' service."
    
2. **Set Up an Ingress Controller:** An Ingress controller is a piece of software that interprets these rules and directs traffic accordingly. Popular Ingress controllers include Nginx Ingress Controller and Traefik.
    
3. **Secure Your Services:** You can use Ingress to secure your services with TLS/SSL certificates. This ensures that communication between the client and your service is encrypted.
    

**Real-World Example: Exposing a Web Application**

Imagine you have a web application running inside a Kubernetes cluster. You want to make it accessible to the public internet. Here's how you can use Ingress:

**1\. Create an Ingress Resource:**

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target:    /$1
spec:
  rules:
  - host: san.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-web-app
            port:
              number: 8080
```

**2\. Configure a Domain Name:** Set up a DNS record for `san.com` to point to your Kubernetes cluster's IP address.

**3\. Add TLS Certificate:**

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target:    /$1
spec:
  tls:
  - hosts:
      - san.com
    secretName: my-app-cert
  rules:
  - host: san.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-web-app
            port:
              number: 8080
```

Now, when users visit `san.com`, their requests will be routed to your web application within the cluster.

**Key Benefits of Using Ingress:**

* **Simplified Service Exposure:** Easily expose services to the outside world.
    
* **Centralized Traffic Management:** Manage traffic routing and load balancing in one place.
    
* **Enhanced Security:** Secure your services with TLS/SSL and other security measures.
    
* **Scalability:** Handle increasing traffic loads with ease.
    

By understanding Ingress and leveraging its power, we can effectively expose your Kubernetes services to the world while maintaining security and control.
