针对那些在amazon-eks上运行时遇到此错误的用户,提供一个解决方案。
首先运行以下命令:
kubectl describe svc <service-name>
然后查看下面示例输出中的events
字段:
Name: some-service
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"some-service","namespace":"default"},"spec":{"ports":[{"port":80,...
Selector: app=some
Type: LoadBalancer
IP: 10.100.91.19
Port: <unset> 80/TCP
TargetPort: 5000/TCP
NodePort: <unset> 31022/TCP
Endpoints: <none>
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 68s service-controller Ensuring load balancer
Warning SyncLoadBalancerFailed 67s service-controller Error syncing load balancer: failed to ensure load balancer: could not find any suitable subnets for creating the ELB
查看错误信息:
Failed to ensure load balancer: could not find any suitable subnets for creating the ELB
在我的情况下,创建ELB时未提供合适的子网原因如下:
1: EKS集群部署在错误的子网组上-内部子网而不是公共面向子网。
(*) 默认情况下,如果没有提供
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
注释,则类型为
LoadBalancer
的服务将创建面向公众的负载均衡器。
2: 子网未按
此处提到的要求标记。
使用以下标记标记VPC:
Key: kubernetes.io/cluster/yourEKSClusterName
Value: shared
使用以下内容标记公共子网:
Key: kubernetes.io/role/elb
Value: 1