Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EKS : could not find any suitable subnets for creating the ELB

I am trying to expose a service to the outside world using the loadBalancer type service.

For that, i have followed this doc

https://aws.amazon.com/premiumsupport/knowledge-center/eks-kubernetes-services-cluster/

My loadbalancer.yaml looks like this

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

But the load balancer is not creating as expected I am getting the following error

Warning  SyncLoadBalancerFailed  8s (x3 over 23s)  service-controller  Error syncing load balancer: failed to ensure load balancer: could not find any suitable subnets for creating the ELB

Seems like its because of some issues in the subnet tags to solve,but i have the required tags in my subnets

kubernetes.io/cluster/<cluster-name>. owned  
kubernetes.io/role/elb   1

But still, I am getting the error could not find any suitable subnets for creating the ELB

like image 540
shellakkshellu Avatar asked Jun 19 '20 11:06

shellakkshellu


2 Answers

By default AWS EKS only attaches load balancers to public subnets. In order to launch it in a private subnet you need to not only label your subnets (which it looks like you did) but also annotate your load balancer-

service.beta.kubernetes.io/aws-load-balancer-internal: "true"

You can find more information here.

like image 198
Robert Hafner Avatar answered Oct 20 '22 04:10

Robert Hafner


For people that may reach this question, I have faced the same error, but the problem was really simple.

The tag with key kubernetes.io/cluster/<cluster-name> had the wrong cluster name as the automation that deployed it was wrong.

like image 25
froblesmartin Avatar answered Oct 20 '22 05:10

froblesmartin