# Ingress

External Services are a way to access applications in K8s from outside&#x20;

{% hint style="success" %}
In production a better alternative is Ingress!&#x20;
{% endhint %}

Not a Service type, but acts as the entry point for your cluster I

**More intelligent and flexible:** Let's US consolidate your routing rules into a single resource as it can expose multiple services under the same IP address

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2F44MNQ3Z6668uteamtneP%2Fimage.png?alt=media\&token=5ba3602c-f22c-4bb3-a2f2-720b453f7fae)

#### <mark style="color:red;">**Configure multiple sub-domains or domains:**</mark>

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2F4FdC0VYpmQOfV7gU9OUs%2Fimage.png?alt=media\&token=d7165c9f-2f22-426b-a270-efc971af78d6)

#### <mark style="color:orange;">Configure multiple paths for same host:</mark>

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FHUgk0Hlkh9aVIvoEbyb5%2Fimage.png?alt=media\&token=f75022cf-6e0a-4ae2-a44f-6ae80c0a6487)

#### <mark style="color:orange;">Configure TLS Certificate - https\://</mark>

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2Fg1z8adXeKNdAZtYscxbp%2Fimage.png?alt=media\&token=2206dcb6-cc3d-4ad6-8561-9976791fb4b7)

### Kubernetes Ingress vs LoadBalancer vs NodePort

These options all do the same thing. They let you expose a service to external network requests. They let you send a request from outside the Kubernetes cluster to a service inside the cluster.

#### NodePort

![nodeport in kubernetes](https://matthewpalmer.net/kubernetes-app-developer/articles/nodeport.png)

`NodePort` is a configuration setting you declare in a service’s YAML. Set the service spec’s `type` to `NodePort`. Then, Kubernetes will allocate a specific port on each Node to that service, and any request to your cluster on that port gets forwarded to the service.

This is cool and easy, it’s just not super robust. You don’t know what port your service is going to be allocated, and the port might get re-allocated at some point.

#### LoadBalancer

![loadbalancer in kubernetes](https://matthewpalmer.net/kubernetes-app-developer/articles/loadbalancer.png)

We can set a service to be of type `LoadBalancer` the same way we’d set `NodePort`— specify the `type` property in the service’s YAML. There needs to be some external load balancer functionality in the cluster, typically implemented by a cloud provider.

This is typically heavily dependent on the cloud provider—GKE creates a Network Load Balancer with an IP address that you can use to access our service.

Every time we want to expose a service to the outside world, we have to create a new LoadBalancer and get an IP address.

#### Ingress

![ingress in kubernetes](https://matthewpalmer.net/kubernetes-app-developer/articles/ingress.png)

`NodePort` and `LoadBalancer` let us expose a service by specifying that value in the service’s `type`. Ingress, on the other hand, is a completely independent resource to our service. We declare, create and destroy it separately to our services.

This makes it decoupled and isolated from the services we want to expose. It also helps us to consolidate routing rules into one place.

The one downside is that we need to configure an Ingress Controller for our cluster. But that’s pretty easy—in this example, we’ll use the Nginx Ingress Controller.

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2F0NS0e1qzppbCJWyHhACe%2Fimage.png?alt=media\&token=1f0f5240-5a21-48fb-9f9f-bc5e9c1a188a)

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FErniXCxh6h4BLLUb5ffV%2Fimage.png?alt=media\&token=16f50aab-8d34-4ecb-a588-631972b1bfcf)
