<p>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. </p>

<p>I created a Loadbalancer using the yaml config per DO link doc: <a href="https://www.digitalocean.com/docs/kubernetes/how-to/add-load-balancer/" rel="nofollow noreferrer">https://www.digitalocean.com/docs/kubernetes/how-to/add-load-balancer/</a> </p>

<p>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? </p>

<p>The following is my "kubectl get svc" output for my app service: </p>

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

<p>The following is my loadbalancer.yaml:</p>

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

<p>My service.yaml:</p>

<pre><code>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
</code></pre>

<p>Thanks</p>

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

<pre><code>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
</code></pre>

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