5

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

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
nusmanov
  • 451
  • 4
  • 15

4 Answers4

6

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.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
2

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.

  • 1
    Hi. Thanks for your (late) answer. Could you add the `k3d`-command you've run to create the cluster? Sounds like you mapped the `NodePort` of this service with it. See https://k3d.io/usage/guides/exposing_services/#2-via-nodeport Please add the necessary parts of the example you linked here. As an answer should be self-contained. – Dominik May 14 '21 at 18:44
  • That example seems to use minikube. So I am not sure how relevant this is here. – tcurdt Feb 10 '22 at 23:09
1

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.

jvanbrackel
  • 89
  • 1
  • 3
0

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.

senorsmile
  • 740
  • 8
  • 19