> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/devops/orchestration/kubernetes/6.-k8s-ingress.md).

# 6. K8s Ingress

### Routing Rules

Forward Request to internal service&#x20;

<figure><img src="/files/ERRw2w3OX7IAiiqIQ7MO" alt=""><figcaption></figcaption></figure>

### Host

* must be valid domain address
* map domain name to node's ip address, which is the entrypoint

***

### Configuration in Cluster

* We need an implementation for ingress which is an ingress controler
* It is a pod which runs on a node inside the cluster which should be installed
* Many third party implementations are present but one of K8 is **K8s Nginx Ingress Controller**
* Environment should be considered on which cluster is running
  * AWS, Google Cloud, etc [Docs](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/)
    * One common reccommended practice for clouds is&#x20;
      \*

      ```
      <figure><img src="/files/84RyWa0FLAwPEUaAIbgQ" alt=""><figcaption></figcaption></figure>
      ```
  * On BareMetal Environment [Docs](https://kubernetes.github.io/ingress-nginx/deploy/baremetal/)
    * Manually configure entry point and load balancer
    * Many solutions but one commonly used is proxy server&#x20;
      \*

      ```
      <figure><img src="/files/pCeUOUhyz30gLRDaq28i" alt=""><figcaption></figcaption></figure>
      ```

***

### Ingress Controller on Minikube

It automatically starts K8 Nginx implementation of Ingress Controller

```
minikube addons enable ingress
```

To verify

```
kubectl get pod -n kube-system
```

***

### Config Methods

#### Method 1

```yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: dashboard-ingress
spec:
  rules:
  # Method 1
  - host: dashboard.com
    http:
      paths:
      - path: /analytics
        backend:
          serviceName: analytics-dashboard
          servicePort: 80
      - path: /shopping
        backend:
          serviceName: shopping-dashboard
          servicePort: 8080
```

#### Method 2

```yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: dashboard-ingress
spec:
  rules:
  # Method 2
    - host: analytics.myapp.com
      http:
        paths:
          backend:
            serviceName: analytics-service
            servicePort: 3000
    - host: shopping.myapp.com
      http:
        paths:
          backend:
            serviceName: shopping-service
            servicePort: 8080
```

***

### Configuring TLS Certificate

1. Data keys need to be **tls.crt** and **tls.key**
2. Values are file content NOT file paths/locations
3. Secret components must be in same namespace as the ingress component.&#x20;

<figure><img src="/files/Z7IsCWlxZDLVsXq54OA5" alt=""><figcaption></figcaption></figure>
