digitalocean kubernetes loadbalancer

12/31/2018

I have deployed my app on the limited available Kubernetes cluster on DigitalOcean. I have a spring boot app with a service exposed on port 31744 for external using nodeport service config.

I created a Loadbalancer using the yaml config per DO link doc: https://www.digitalocean.com/docs/kubernetes/how-to/add-load-balancer/

However, I am not able to hook up to my service. Can you advise on how it can be done so I can access my service from the loadbalancer?

The following is my "kubectl get svc" output for my app service:

NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-springboot          NodePort       10.245.6.216    <none>           8080:31744/TCP   2d18h
kubernetes             ClusterIP      10.245.0.1      <none>           443/TCP          3d20h
sample-load-balancer   LoadBalancer   10.245.53.168   58.183.251.550   80:30495/TCP     2m6s

The following is my loadbalancer.yaml:

apiVersion: v1
kind: Service
metadata:
  name: sample-load-balancer
spec:
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 31744
      name: http

My service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: my-springboot
  labels:
    app: my-springboot
    tier: backend
spec:
  type: NodePort
  ports:
    # the port that this service should serve on
  - port: 8080
  selector:
    app: my-springboot
    tier: backend

Thanks

-- Sonam
digital-ocean
kubernetes

1 Answer

1/1/2019

To expose your service using LoadBalancer instead of NodePort you need to provide type in service as LoadBalancer. So your new service config yaml will be:

apiVersion: v1
kind: Service
metadata:
  name: my-springboot
  labels:
    app: my-springboot
    tier: backend
spec:
  type: LoadBalancer
  ports:
    # the port that this service should serve on
  - port: 8080
  selector:
    app: my-springboot
    tier: backend

Once you apply the above service yaml file, you will get the external IP in kubectl get svc which can be used to access the service from outside the kubernetes cluster.

-- Prafull Ladha
Source: StackOverflow