> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Configurar o ingress

> Exponha os serviços do Midaz por ingress do Kubernetes: defina hostnames, secrets TLS e annotations do controller para NGINX, ALB ou Traefik.

<Warning>
  As orientações de CRM e Fees marcadas como legado nesta página valem apenas para um release legado existente. O Midaz v4 faz deploy do Ledger unificado e serve CRM e Fees em `/v2`.
</Warning>

O repositório Helm mantém uma carga de trabalho `crm.enabled` e o chart `plugin-fees-helm` para releases de aplicação mais antigos. Essas são superfícies de compatibilidade legadas, não o modelo de deploy do Midaz v4.

Use `ledger.ingress` no Midaz v4. Os exemplos de ingress de CRM mantidos valem apenas para a carga de trabalho de compatibilidade legada `crm.enabled`.

Para usar ingress, você precisa de um [ingress controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/) rodando no seu cluster (por exemplo, **NGINX**, **AWS ALB** ou **Traefik**) e de entradas de DNS apontando para ele.

<Tip>
  Você pode habilitar o ingress por serviço no seu arquivo values.yaml e configurar hostnames, secrets TLS e quaisquer annotations específicas do controller.
</Tip>

<Note>
  **Integração com cert-manager:** se você usa o cert-manager para TLS automático, adicione a annotation `cert-manager.io/cluster-issuer: <issuer-name>` e defina `tls.secretName`. O cert-manager provisiona o certificado automaticamente.
</Note>

## Ingress controller NGINX

***

Para usar o **NGINX Ingress Controller**, configure o `values.yaml` assim:

```yaml expandable theme={null}
ingress:
  enabled: true
  className: "nginx"
  # The `annotations` field is used to add custom metadata to the Nginx resource.
  # Annotations are key-value pairs that can be used to attach arbitrary non-identifying metadata to objects.
  # These annotations can be used by various tools and libraries to augment the behavior of the Nginx resource.
  # See more https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md
  annotations: {}
  hosts:
    - host: midaz.example.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - secretName: midaz-tls  # Ensure this secret exists or is managed by cert-manager
      hosts:
        - midaz.example.com
```

<Tip>
  Consulte a documentação oficial do ingress-nginx para uma referência completa das annotations do Nginx.
</Tip>

## AWS ALB (balanceador de carga de aplicação)

***

Para o **AWS ALB Ingress Controller**, configure o `values.yaml` assim:

```yaml expandable theme={null}
ingress:
  enabled: true
  className: "alb"
  annotations:
    alb.ingress.kubernetes.io/scheme: internal  # Use "internet-facing" for public ALB
    alb.ingress.kubernetes.io/target-type: ip   # Use "instance" if targeting EC2 instances
    alb.ingress.kubernetes.io/group.name: "midaz"  # Group ALB resources under this name
    alb.ingress.kubernetes.io/healthcheck-path: "/health"  # Health check path
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'  # Listen on HTTP and HTTPS
  hosts:
    - host: midaz.example.com
      paths:
        - path: /
          pathType: Prefix
  tls: []  # TLS is managed by the ALB using ACM certificates
```

## Ingress controller Traefik

***

Para o **Traefik**, configure o `values.yaml` assim:

```yaml expandable theme={null}
ingress:
  enabled: true
  className: "traefik"
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: "web, websecure"  # Entrypoints defined in Traefik
    traefik.ingress.kubernetes.io/router.tls: "true"  # Enable TLS for this route
  hosts:
    - host: midaz.example.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - secretName: midaz-tls  # Ensure this secret exists and contains the TLS certificate
      hosts:
        - midaz.example.com
```

## Exemplo com vários serviços

***

Para expor a API do Ledger e o CRM com hostnames diferentes:

```yaml theme={null}
ledger:
  ingress:
    enabled: true
    className: "nginx"
    hosts:
      - host: api.midaz.example.com
        paths:
          - path: /
            pathType: Prefix
    tls:
      - secretName: midaz-api-tls
        hosts:
          - api.midaz.example.com

crm:
  ingress:
    enabled: true
    className: "nginx"
    hosts:
      - host: crm.midaz.example.com
        paths:
          - path: /
            pathType: Prefix
    tls:
      - secretName: midaz-crm-tls
        hosts:
          - crm.midaz.example.com
```
