Hammed
Hammed

Reputation: 1557

K8s expose LoadBalancer service giving external-ip 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.

Upvotes: 9

Views: 8308

Answers (2)

Islam Salah
Islam Salah

Reputation: 2146

To Create K8s cluster on AWS using EC2, you need to consider some configuration to make it work as expected. that's why your service is not exposed right with external IP.

you need to get the public IP of the EC2 instance that your cluster used it to deploy Nginx pod on it and then edit Nginx service to add external IP

kubectl edit service nginx 

and that will prompt terminal to add external IP:

type: LoadBalancer
externalIPs:
   - 1.2.3.4

where 1.2.3.4 is the public IP of the EC2 instance. then make sure your security group inbound traffic allowed on your port (31579)

Now you are ready to user k8s service from any browser open: 1.2.3.4:31579

Upvotes: 1

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93163

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:

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.

Upvotes: 7

Related Questions