# 6. K8s Ingress

### Routing Rules

Forward Request to internal service&#x20;

<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F8KjlYn22etjkr3AoHh01%2Fimage.png?alt=media&#x26;token=d88bab1e-0534-4935-b72e-73262eabb381" 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F9Xw8F6VSeLc1W7lBTA5i%2Fimage.png?alt=media&#x26;token=c940a8c1-d5db-42a2-956d-e23453c481c7" 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FeaEEt2DME3YHVow64P2E%2Fimage.png?alt=media&#x26;token=a077d519-99f2-4a0d-8595-95b91d0e887c" 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="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FoBIlKT7tHpWhN5K3rq0h%2Fimage.png?alt=media&#x26;token=66182901-9b61-4e2b-879d-574098b0e15c" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.nomanaziz.me/devops/orchestration/kubernetes/6.-k8s-ingress.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
