Compare languages | Модуль ingress-nginx: пример

Пример для AWS (Network Load Balancer)

An example for AWS (Network Load Balancer)

При создании балансировщика используются все доступные зоны в кластере.

When creating a balancer, all zones available in the cluster are used.

В каждой зоне балансировщик получает публичный IP. Если в зоне есть instance с Ingress-контроллером, A-запись с IP-адресом балансировщика из этой зоны автоматически добавляется к доменному имени балансировщика.

In each zone, the balancer receives a public IP. If there is an instance with an Ingress controller in the zone, an A-record with the balancer’s IP address from this zone is automatically added to the balancer’s domain name.

Если в зоне не остается instance с Ingress-контроллером, тогда IP автоматически удаляется из DNS.

When there are no instances with an Ingress controller in the zone, then the IP is automatically removed from the DNS.

В том случае, если в зоне всего один инстанс с Ingress-контроллером, при перезапуске пода IP-адрес балансировщика этой зоны будет временно исключен из DNS.

If there is only one instance with an Ingress controller in a zone, when the pod is restarted, the IP address of the balancer of this zone will be temporarily excluded from DNS.

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer loadBalancer: annotations: service.beta.kubernetes.io/aws-load-balancer-type: “nlb”

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: “nginx” inlet: “LoadBalancer” loadBalancer: annotations: service.beta.kubernetes.io/aws-load-balancer-type: “nlb”

Пример для GCP / Yandex Cloud / Azure

An example for GCP / Yandex Cloud / Azure

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: “nginx” inlet: “LoadBalancer”

В GCP на узлах должна присутствовать аннотация, разрешающая принимать подключения на внешние адреса для сервисов с типом NodePort.

In GCP, nodes must have an annotation enabling them to accept connections to external addresses for the NodePort type services.

Пример для OpenStack

An example for OpenStack

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main-lbwpp spec: inlet: LoadBalancerWithProxyProtocol ingressClass: nginx loadBalancerWithProxyProtocol: annotations: loadbalancer.openstack.org/proxy-protocol: “true” loadbalancer.openstack.org/timeout-member-connect: “2000”

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main-lbwpp spec: inlet: LoadBalancerWithProxyProtocol ingressClass: nginx loadBalancerWithProxyProtocol: annotations: loadbalancer.openstack.org/proxy-protocol: “true” loadbalancer.openstack.org/timeout-member-connect: “2000”

Пример для bare metal

An example for Bare metal

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: HostWithFailover nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: HostWithFailover nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

Пример для bare metal (при использовании внешнего балансировщика, например Cloudflare, Qrator, Nginx+, Citrix ADC, Kemp и др.)

An example for Bare metal (Behind external load balancer, e.g. Cloudflare, Qrator, Nginx+, Citrix ADC, Kemp, etc.)

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: HostPort hostPort: httpPort: 80 httpsPort: 443 behindL7Proxy: true

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: HostPort hostPort: httpPort: 80 httpsPort: 443 behindL7Proxy: true

Пример для bare metal (балансировщик MetalLB в режиме BGP LoadBalancer)

An example for Bare metal (MetalLB BGP LoadBalancer)

Доступно в следующих редакциях: EE, CSE Pro (1.67).

This feature is available in Enterprise Edition only.

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

В случае использования MetalLB его speaker-поды должны быть запущены на тех же узлах, что и поды Ingress–контроллера.

In the case of using MetalLB, its speaker Pods must be run on the same Nodes as the Ingress controller Pods.

Контроллер должен получать реальные IP-адреса клиентов — поэтому его Service создается с параметром externalTrafficPolicy: Local (запрещая межузловой SNAT), и для принятия данного параметра MetalLB speaker анонсирует этот Service только с тех узлов, в которых запущены целевые поды.

The controller must receive real IP addresses of clients — therefore its Service is created with the parameter externalTrafficPolicy: Local (disabling cross–node SNAT), and to accept this parameter the MetalLB speaker announce this Service only from those Nodes where the target Pods are running.

Для этого примера конфигурация модуля metallb должна быть следующей:

For this example metallb module configuration should be like this:

yaml metallb: speaker: nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

yaml metallb: speaker: nodeSelector: node-role.deckhouse.io/frontend: “” tolerations:

  • effect: NoExecute key: dedicated.deckhouse.io value: frontend

Пример для bare metal (балансировщик MetalLB в режиме L2 LoadBalancer)

An example for Bare metal (MetalLB L2 LoadBalancer)

Доступно в следующих редакциях: SE, SE+, EE, CSE Lite (1.67), CSE Pro (1.67).

This feature is available in the following editions: SE, SE+, EE.

  1. Включите модуль metallb:
  1. Enable the metallb module:

yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: metallb spec: enabled: true version: 2

yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: metallb spec: enabled: true version: 2

  1. Создайте ресурс MetalLoadBalancerClass:
  1. Deploy the MetalLoadBalancerClass resource:

yaml apiVersion: network.deckhouse.io/v1alpha1 kind: MetalLoadBalancerClass metadata: name: ingress spec: addressPool:

  • 192.168.2.100-192.168.2.150 isDefault: false nodeSelector: node-role.kubernetes.io/loadbalancer: “” # селектор узлов-балансировщиков type: L2

yaml apiVersion: network.deckhouse.io/v1alpha1 kind: MetalLoadBalancerClass metadata: name: ingress spec: addressPool:

  • 192.168.2.100-192.168.2.150 isDefault: false nodeSelector: node-role.kubernetes.io/loadbalancer: “” # label on load-balancing nodes type: L2
  1. Создайте ресурс IngressNginxController:
  1. Deploy the IngressNginxController resource:

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer loadBalancer: loadBalancerClass: ingress annotations: Количество адресов, которые будут выделены из пула, объявленного в MetalLoadBalancerClass. network.deckhouse.io/l2-load-balancer-external-ips-count: “3” Селектор и tolerations. Поды ingress-controller должны быть размещены на тех же узлах, что и поды MetalLB speaker. nodeSelector: node-role.kubernetes.io/loadbalancer: “” tolerations:

  • effect: NoSchedule key: node-role/loadbalancer operator: Exists

yaml apiVersion: deckhouse.io/v1 kind: IngressNginxController metadata: name: main spec: ingressClass: nginx inlet: LoadBalancer loadBalancer: loadBalancerClass: ingress annotations: The number of addresses that will be allocated from the pool declared in MetalLoadBalancerClass. network.deckhouse.io/l2-load-balancer-external-ips-count: “3” Label selector and tolerations. Ingress-controller pods must be scheduled on same nodes as MetalLB speaker pods. nodeSelector: node-role.kubernetes.io/loadbalancer: “” tolerations:

  • effect: NoSchedule key: node-role/loadbalancer operator: Exists
  1. Платформа создаст сервис с типом LoadBalancer, которому будет присвоено заданное количество адресов:
  1. The platform will create a service with the type LoadBalancer, to which a specified number of addresses will be assigned:

shell $ kubectl -n d8-ingress-nginx get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE main-load-balancer LoadBalancer 10.222.130.11 192.168.2.100,192.168.2.101,192.168.2.102 80:30689/TCP,443:30668/TCP 11s

shell $ kubectl -n d8-ingress-nginx get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE main-load-balancer LoadBalancer 10.222.130.11 192.168.2.100,192.168.2.101,192.168.2.102 80:30689/TCP,443:30668/TCP 11s