如何在 Azure AKS 服务中使用现有的 LoadBalancer?
How-to use existing LoadBalancer in Azure AKS Service?
我使用 Terraform 创建了一个 AKS 集群。我希望集群有一个 LoadBalancer 和一个静态 public IP,并且我希望它们预先存在于我的 Ingress Controller / LoadBalancer 服务定义中,因为我不希望它们是 created/deleted由 Kubernetes 清单动态生成。
所以我还使用 Terraform 创建了一个负载均衡器和一个静态 public IP,在节点资源组和 SKU 基础上,根据 documentation recommendations,并附加了 public IP 到 LB.
然后我创建了一个 LoadBalancer 类型的服务:
---
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
type: LoadBalancer
loadBalancerIP: 8.8.8.8 (the public static IP allocated by Terraform)
selector:
name: my-pods-selector
ports:
- name: my-port
protocol: TCP
port: 1234
targetPort: 1234
然后服务卡在 PENDING 状态,describe
给我这个:
$ kubectl describe svc my-service
[...]
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 5s (x9 over 15m) service-controller Ensuring load balancer
Warning CreatingLoadBalancerFailed 4s (x9 over 15m) service-controller Error creating load balancer (will retry): failed to ensure load balancer for service my-service: timed out waiting for the condition
我无法在 describe
命令输出中找到有关错误的更多信息:
Error creating load balancer (will retry): failed to ensure load balancer for service my-service: timed out waiting for the condition
此外,如果不是预先创建 LoadBalancer 而只是 public IP,则 LoadBalancer 是动态创建的并且一切正常。
问题是:如何使 Azure 成功(我缺少哪个配置参数?)使用预先存在的 LB?
- Kubernetes 版本:1.13.5
I want the cluster to have a LoadBalancer and a static public IP, and
I want those to be pre-existing to my Ingress Controller /
LoadBalancer Service definitions, as I don't want them to be
created/deleted dynamically by Kubernetes manifests.
遗憾的是,您不能将 pre-existing 负载均衡器与静态 public IP 用于 AKS 群集中的服务。你可以看看Github中的同一个issue。如建议所示:
You'd need to let AKS create the load balancer resources in Azure for
your services rather than trying to manually create them ahead of them
and then use them in AKS. Just create the service through the
Kubernetes API, and let the networking plugin create and configure the
appropriate Azure resources.
我建议您可以自己使用静态分配方法创建 public IP。然后使用负载均衡器类型和静态 public IP 创建服务。
使用 --sku 标准创建静态 IP。没有 --sku 标准 IP 使用 SKU Basic 创建。
基本静态 IP 不能用于负载均衡器。
查看 activity 日志,您会看到如下警告:
Standard sku load balancer
/subscriptions/55aa..../resourceGroups/MC_kubernetes-dev-kubernetes-dev-cluster_northeurope/providers/Microsoft.Network/loadBalancers/kubernetes
cannot reference Basic sku publicIP
/subscriptions/55aa..../resourceGroups/MC_kubernetes-dev_kubernetes-dev-cluster_northeurope/providers/Microsoft.Network/publicIPAddresses/kubernetes-dev-public-ip.
STATICIP=$(az network public-ip create --resource-group <MC_your-RG> --name Your-public-ip-name --sku Standard --allocation-method static --query publicIp.ipAddress -o tsv)
现在将此 ip 分配给您的负载均衡器服务
我使用 Terraform 创建了一个 AKS 集群。我希望集群有一个 LoadBalancer 和一个静态 public IP,并且我希望它们预先存在于我的 Ingress Controller / LoadBalancer 服务定义中,因为我不希望它们是 created/deleted由 Kubernetes 清单动态生成。
所以我还使用 Terraform 创建了一个负载均衡器和一个静态 public IP,在节点资源组和 SKU 基础上,根据 documentation recommendations,并附加了 public IP 到 LB.
然后我创建了一个 LoadBalancer 类型的服务:
---
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
type: LoadBalancer
loadBalancerIP: 8.8.8.8 (the public static IP allocated by Terraform)
selector:
name: my-pods-selector
ports:
- name: my-port
protocol: TCP
port: 1234
targetPort: 1234
然后服务卡在 PENDING 状态,describe
给我这个:
$ kubectl describe svc my-service
[...]
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 5s (x9 over 15m) service-controller Ensuring load balancer
Warning CreatingLoadBalancerFailed 4s (x9 over 15m) service-controller Error creating load balancer (will retry): failed to ensure load balancer for service my-service: timed out waiting for the condition
我无法在 describe
命令输出中找到有关错误的更多信息:
Error creating load balancer (will retry): failed to ensure load balancer for service my-service: timed out waiting for the condition
此外,如果不是预先创建 LoadBalancer 而只是 public IP,则 LoadBalancer 是动态创建的并且一切正常。
问题是:如何使 Azure 成功(我缺少哪个配置参数?)使用预先存在的 LB?
- Kubernetes 版本:1.13.5
I want the cluster to have a LoadBalancer and a static public IP, and I want those to be pre-existing to my Ingress Controller / LoadBalancer Service definitions, as I don't want them to be created/deleted dynamically by Kubernetes manifests.
遗憾的是,您不能将 pre-existing 负载均衡器与静态 public IP 用于 AKS 群集中的服务。你可以看看Github中的同一个issue。如建议所示:
You'd need to let AKS create the load balancer resources in Azure for your services rather than trying to manually create them ahead of them and then use them in AKS. Just create the service through the Kubernetes API, and let the networking plugin create and configure the appropriate Azure resources.
我建议您可以自己使用静态分配方法创建 public IP。然后使用负载均衡器类型和静态 public IP 创建服务。
使用 --sku 标准创建静态 IP。没有 --sku 标准 IP 使用 SKU Basic 创建。
基本静态 IP 不能用于负载均衡器。 查看 activity 日志,您会看到如下警告:
Standard sku load balancer /subscriptions/55aa..../resourceGroups/MC_kubernetes-dev-kubernetes-dev-cluster_northeurope/providers/Microsoft.Network/loadBalancers/kubernetes cannot reference Basic sku publicIP /subscriptions/55aa..../resourceGroups/MC_kubernetes-dev_kubernetes-dev-cluster_northeurope/providers/Microsoft.Network/publicIPAddresses/kubernetes-dev-public-ip.
STATICIP=$(az network public-ip create --resource-group <MC_your-RG> --name Your-public-ip-name --sku Standard --allocation-method static --query publicIp.ipAddress -o tsv)
现在将此 ip 分配给您的负载均衡器服务