Metallb можно использовать в статических кластерах (bare metal), когда нет возможности воспользоваться балансировщиком от облачного провайдера. Metallb может работать в режимах L2 LoadBalancer или BGP LoadBalancer. | Metallb can be used in Static (bare metal) clusters when there is no option to use cloud load balancers. Metallb can work in L2 LoadBalancer or BGP modes LoadBalancer. |
Пример использования metallb в режиме L2 LoadBalancer | Example of metallb usage in L2 LoadBalancer mode |
Включите модуль: | Enable the 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 |
Подготовьте приложение, которое хотите опубликовать: | Prepare the application to publish: |
shell kubectl create deploy nginx –image=nginx | shell kubectl create deploy nginx –image=nginx |
Создайте ресурс MetalLoadBalancerClass: | Deploy the MetalLoadBalancerClass resource: |
yaml apiVersion: network.deckhouse.io/v1alpha1 kind: MetalLoadBalancerClass metadata: name: ingress spec: addressPool:
| yaml apiVersion: network.deckhouse.io/v1alpha1 kind: MetalLoadBalancerClass metadata: name: ingress spec: addressPool:
|
Создайте ресурс Service с аннотацией и именем MetalLoadBalancerClass: | Deploy standard resource Service with special annotation and MetalLoadBalancerClass name: |
yaml apiVersion: v1 kind: Service metadata: name: nginx-deployment annotations: network.deckhouse.io/l2-load-balancer-external-ips-count: “3” spec: type: LoadBalancer loadBalancerClass: ingress # имя MetalLoadBalancerClass ports:
| yaml apiVersion: v1 kind: Service metadata: name: nginx-deployment annotations: network.deckhouse.io/l2-load-balancer-external-ips-count: “3” spec: type: LoadBalancer loadBalancerClass: ingress # MetalLoadBalancerClass name ports:
|
В результате, созданному сервису с типом | As a result, the created Service with the type |
shell $ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-deployment LoadBalancer 10.222.130.11 192.168.2.100,192.168.2.101,192.168.2.102 80:30544/TCP 11s | shell $ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-deployment LoadBalancer 10.222.130.11 192.168.2.100,192.168.2.101,192.168.2.102 80:30544/TCP 11s |
Полученные EXTERNAL-IP можно прописывать в качестве A-записей для прикладного домена: | The resulting EXTERNAL-IP are ready to use in application DNS-domain: |
shell $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.100:8000 200 $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.101:8000 200 $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.102:8000 200 | shell $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.100:8000 200 $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.101:8000 200 $ curl -s -o /dev/null -w “%{http_code}” 192.168.2.102:8000 200 |
Пример использования metallb в режиме BGP LoadBalancer | Example of metallb usage in BGP LoadBalancer mode |
Включите модуль и настройте все необходимые параметры*: | Enable the module and configure all the necessary parameters*: |
yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: metallb spec: enabled: true settings: addressPools:
| yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: metallb spec: enabled: true settings: addressPools:
|
* — в будущих версиях настройки режима BGP будут задаваться через ресурс MetalLoadBalancerClass. | * — in future versions, BGP mode settings will be set via the MetalLoadBalancerClass resource. |
Настройте BGP-пиринг на сетевом оборудовании. | Configure BGP peering on the network equipment. |
Дополнительные примеры настроек для Service | Additional configuration examples for Service |
Для создания Services с общими IP адресами необходимо добавить к ним аннотацию | To create a Services with shared IP addresses, you need to add the annotation |
yaml apiVersion: v1 kind: Service metadata: name: dns-service-tcp namespace: default annotations: network.deckhouse.io/load-balancer-shared-ip-key: “key-to-share-1.2.3.4” spec: type: LoadBalancer ports:
| yaml apiVersion: v1 kind: Service metadata: name: dns-service-tcp namespace: default annotations: network.deckhouse.io/load-balancer-shared-ip-key: “key-to-share-1.2.3.4” spec: type: LoadBalancer ports:
|
Для создания Service с принудительно выбранным адресом необходимо добавить аннотацию | To create a Service with a forcibly selected address, you need to add the annotation |
yaml apiVersion: v1 kind: Service metadata: name: nginx annotations: network.deckhouse.io/load-balancer-ips: 192.168.217.217 spec: ports:
| yaml apiVersion: v1 kind: Service metadata: name: nginx annotations: network.deckhouse.io/load-balancer-ips: 192.168.217.217 spec: ports:
|
Создание Service и назначение ему IPAddressPools возможно в режиме BGP LoadBalancer через аннотацию | Creating a Service and assigning it IPAddressPools is possible in BGP LoadBalancer mode using the annotation |
yaml apiVersion: v1 kind: Service metadata: name: nginx annotations: metallb.universe.tf/address-pool: production-public-ips spec: ports:
| yaml apiVersion: v1 kind: Service metadata: name: nginx annotations: metallb.universe.tf/address-pool: production-public-ips spec: ports:
|