k3d no external ip for a service of load balanacer type

Viewed 4664

i am deploying the hello-world docker container to a k3d - cluster. To get the external IP, a service of the type - load balancer is deployed.

After that i was hoping to call the appication via load balancer. But i don't get the external ip.

k3d create --name="mydemocluster" --workers="2" --publish="80:80"

export KUBECONFIG="$(k3d get-kubeconfig --name='mydemocluster')"

kubectl run kubia --image=hello-world --port=8080 --generator=run/v1
kubectl expose rc kubia --type=LoadBalancer --name kubia-http

export KUBECONFIG="$(k3d get-kubeconfig --name='mydemocluster')"

then kubectl get services: 3d

4 Answers

LoadBalancer type service will get external IP only if you use a managed kubernetes Service provided by cloud providers such as AWS EKS, Azure AKS, Google GCP etc.Tools such as k3d is for local development and if you create a LoadBalancer type service external ip will be pending. Alternative is to use NodePort type service or ingress . Here is the doc on this.

Also you can use kubectl port forward or kubectl proxy to access the pod.

I was following this example

with k3d and there it seems to work fine:

(base) erik@buzzard:~/kubernetes/tutorial> 
kubectl  get services 
NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes              ClusterIP      10.43.0.1       <none>        443/TCP          3d6h
mongodb-service         ClusterIP      10.43.215.113   <none>        27017/TCP        27m
mongo-express-service   LoadBalancer   10.43.77.100    172.20.0.2    8081:30000/TCP   27m

As I understand, k3d is running k3s which is more of a full kubernetes setup than minikube for instance. I can access the service at http://172.20.0.2:8081 without problems.

You'll need a cloud controller manager to act as a service controller to do that. As far as on-prem goes, your best option is likely MetalLB.

That being said, I don't know how that will behave with the underlying docker network in K3d. It's on my list of things to try out. If I find it works well, I'll come back and update this post.

I solved this by changing my manifest from a LoadBalancer type to an Ingress type. K3d doesn't seem to expose external IP's properly to a load balancer type.

Oddly, I did find I was able to get the LoadBalancer type to work if I deployed really quickly. It seemed it had to be after the master node was up and before any agents were up.

Related