NSX ALB 可以充当 Tanzu Kubernetes Grid 部署中 Kubernetes 集群的外部负载均衡器提供程序。
要为所有集群配置 NSX ALB 负载均衡器实施,请执行以下操作:
创建管理集群配置 YAML 文件,并在该文件中添加以下字段:
AVI_ENABLE: true
AVI_CONTROLLER: <avi controller IP address or FQDN>
AVI_USERNAME: <avi admin username>
AVI_PASSWORD: <avi admin password>
AVI_CA_DATA_B64: <base64 encoded certificate>
AVI_CLOUD_NAME: <cloud you configured to deploy virtual services>
AVI_SERVICE_ENGINE_GROUP: <SEG you configured to host virtual services>
AVI_DATA_NETWORK: <VIP Network you want to use for your load balancer external IP>
AVI_DATA_NETWORK_CIDR: <above VIP Network's CIDR>
#### only for NSX-T cloud ####
AVI_NSXT_T1LR: <NSX-T Tier 1 path used for NSX Advanced Loader Balancer backend network>
有关创建管理集群配置文件的详细信息,请参见创建管理集群配置文件。
使用 tanzu management-cluster create
命令创建管理集群。
NSX ALB 现在配置为管理集群以及此管理集群创建的所有工作负载集群的负载均衡器。
或者,您可以在 Tanzu Kubernetes Grid 中配置 NSX ALB 的某些高级负载均衡功能。
要将 NSX ALB 配置为仅特定工作负载集群上的负载均衡器,请执行以下操作:
创建管理集群配置 YAML 文件,并在该文件中添加以下字段:
AVI_ENABLE: true
AVI_LABELS: '{"enable-nsx-alb":"true"}'
AVI_CONTROLLER: <avi controller IP address or FQDN>
AVI_USERNAME: <avi admin username>
AVI_PASSWORD: <avi admin password>
AVI_CA_DATA_B64: <base64 encoded certificate>
AVI_CLOUD_NAME: <cloud you configured to deploy virtual services>
AVI_SERVICE_ENGINE_GROUP: <SEG you configured to host virtual services>
AVI_DATA_NETWORK: <VIP Network you want to use for your load balancer external IP>
AVI_DATA_NETWORK_CIDR: <above VIP Network's CIDR>
#### only for NSX-T cloud ####
AVI_NSXT_T1LR: <NSX-T Tier 1 path used for NSX Advanced Loader Balancer backend network>
有关创建管理集群配置文件的详细信息,请参见创建管理集群配置文件。
使用 tanzu management-cluster create
命令创建管理集群。
在工作负载集群配置 YAML 文件中,添加以下字段:
AVI_LABELS: '{"enable-nsx-alb":"true"}'
使用 tanzu cluster create
命令创建工作负载集群。
NSX ALB 现在仅配置为具有相应 AVI_LABELS
值的工作负载集群的负载均衡器。
此功能利用在集群中部署的 Avi Kubernetes Operator (AKO) 应用程序。有关信息,请参见具有首选 IP 的负载均衡器类型服务。
确保您指定的 IP 地址是在 AVI 控制器中配置的 IP 池中的未分配地址。
要为 NSX ALB 提供的负载均衡器服务配置外部静态 IP 地址,请在服务配置文件的负载均衡器类型的 loadbalancerIP
字段中添加外部 IP 地址,如以下示例中所示:
apiVersion: v1
kind: Service
metadata:
name: corgi-test
spec:
type: LoadBalancer
selector:
corgi: test
ports:
- nodePort: 30008
port: 80
targetPort: 80
loadBalancerIP: 1.1.1.1
与 NSX ALB 集成的 Tanzu Kubernetes Grid 部署支持网关 API v1alpha1。此功能利用在集群中部署的 AKO 应用程序。有关网关 API 支持的详细信息,请参见网关和网关类。
要为 NSX ALB 提供的负载均衡器服务配置 v1alpha1 API 网关,请在 AKODeploymentConfig
对象中将标记 spec.extraConfigs.servicesAPI
设置为 true
。以下是一个示例。
apiVersion: ako.vmware.com/v1alpha1
kind: AviInfraSetting
metadata:
name: sample-infrasetting
spec:
seGroup:
name: Default-Group
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: GatewayClass
metadata:
name: sample-gateway-class
spec:
controller: ako.vmware.com/avi-lb
parametersRef:
group: ako.vmware.com
kind: AviInfraSetting
name: sample-infrasetting
---
kind: Gateway
apiVersion: networking.x-k8s.io/v1alpha1
metadata:
name: sample-gateway
spec:
gatewayClassName: sample-gateway-class
listeners:
- protocol: TCP
port: 80
routes:
selector:
matchLabels:
ako.vmware.com/gateway-namespace: default
ako.vmware.com/gateway-name: sample-gateway
group: v1
kind: Service
- protocol: TCP
port: 81
routes:
selector:
matchLabels:
ako.vmware.com/gateway-namespace: default
ako.vmware.com/gateway-name: sample-gateway
group: v1
kind: Service
---
apiVersion: v1
kind: Service
metadata:
name: coffee-svc
labels:
app: coffee
ako.vmware.com/gateway-name: sample-gateway
ako.vmware.com/gateway-namespace: default
spec:
ports:
- port: 81
targetPort: 80
protocol: TCP
selector:
app: coffee
type: NodePort # <== service type should be aligned with AKODeploymentConfig.spec.extraConfigs.ingress.serviceType, NodePort is the default value.
---
apiVersion: v1
kind: Service
metadata:
name: tea-svc
labels:
app: tea
ako.vmware.com/gateway-name: sample-gateway
ako.vmware.com/gateway-namespace: default
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: tea
type: NodePort # <== service type should be aligned with AKODeploymentConfig.spec.extraConfigs.ingress.serviceType, NodePort is the default value.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-coffee
spec:
selector:
matchLabels:
app: coffee
replicas: 1
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: nginx
image: harbor-repo.vmware.com/dockerhub-proxy-cache/library/nginx
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-tea
spec:
selector:
matchLabels:
app: tea
replicas: 1
template:
metadata:
labels:
app: tea
spec:
containers:
- name: nginx
image: harbor-repo.vmware.com/dockerhub-proxy-cache/library/nginx
ports:
- containerPort: 80
Tanzu Kubernetes Grid 支持可通过 AKO 使用的所有 NSX ALB 功能。要使用功能,请在 AKODeploymentConfig.spec.extraConfigs.<FEATURE-KNOB>
对象中设置相应的值。有关详细信息,请参见《Avi Kubernetes Operator 部署指南》。
如果在 Tanzu Kubernetes Grid 部署中启用了 NSX ALB,NSX ALB 作为负载均衡器服务提供程序,则会在管理集群中自动启用。