Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoadBalancer external-ip stuck in pending

I've created a Kubernetes cluster with AWS ec2 instances using kubeadm but when I try to create a service with type LoadBalancer I get an EXTERNAL-IP pending status

NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP         123m
nginx        LoadBalancer   10.107.199.170  <pending>     8080:31579/TCP  45m52s

My create command is

kubectl expose deployment nginx --port 8080 --target-port 80 --type=LoadBalancer

I'm not sure what I'm doing wrong.

What I expect to see is an EXTERNAL-IP address given for the load balancer.

Has anyone had this and successfully solved it, please?

Thanks.

like image 690
Hammed Avatar asked Jul 11 '20 21:07

Hammed


1 Answers

You need to setup the interface between k8s and AWS which is aws-cloud-provider-controller.

apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
nodeRegistration:
  kubeletExtraArgs:
    cloud-provider: aws

More details can be found:

  • https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/
  • https://blog.heptio.com/setting-up-the-kubernetes-aws-cloud-provider-6f0349b512bd
  • https://blog.scottlowe.org/2019/02/18/kubernetes-kubeadm-and-the-aws-cloud-provider/
  • https://itnext.io/kubernetes-part-2-a-cluster-set-up-on-aws-with-aws-cloud-provider-and-aws-loadbalancer-f02c3509f2c2

Once you finish this setup, you will have the luxury to control not only the creation of AWS LB for each k8s service with type LoadBalancer.. But also , you will be able to control many things using annotations.

apiVersion: v1
kind: Service
metadata:
  name: example
  namespace: kube-system
  labels:
    run: example
  annotations:
     service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:xx-xxxx-x:xxxxxxxxx:xxxxxxx/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx #replace this value
     service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
spec:
  type: LoadBalancer
  ports:
  - port: 443
    targetPort: 5556
    protocol: TCP
  selector:
    app: example

Different settings can be applied to a load balancer service in AWS using annotations.

like image 91
Abdennour TOUMI Avatar answered Sep 30 '22 10:09

Abdennour TOUMI