0

I'm trying to deploy my app to Digital Ocean using Kubernetes and I went through their tutorial but it is not working. This is my manifest:

---
kind: Service
apiVersion: v1
metadata:
  name: my-app-load-balancer
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: addamsson/my-app:v6
          ports:
          - containerPort: 80

What happens is that instead of routing to the 80 port of the droplet it forwards to a random port:

my-app-load-balancer   LoadBalancer   10.245.109.64   206.189.247.38   80:32225/TCP   4m1s

What am I doing wrong?

I tried my app locally with Docker and it works and if I check the logs of my pod it also looks good:

2020-02-25 14:15:30.105 [main] INFO  Application - Responding at http://127.0.0.1:80

Edit:

I tried it with an image I know should work: springio/gs-spring-boot-docker and it works. But I don't understand why it is not working with my image. If I check the logs it looks good. Do I have a problem in my Dockerfile?

FROM openjdk:8-jre-alpine
RUN mkdir /app
COPY ./build/libs/my-app.jar /app/my-app.jar
WORKDIR /app
ENTRYPOINT ["java", "-jar", "my-app.jar"]

If I run the .jar file on my computer it is also fine.

Adam Arold
  • 103
  • 5

1 Answers1

1

This is correct configuration. The first port shown in the output is the value of the port specified in the service manifest. This is the port on which service is available inside the cluster.

The second port is a NodePort- the port on each node on which this service is exposed when service type is either NodePort or LoadBalancer. It is usually assigned by the system from the range between 30000-32767. This port can be manually chosen but you have to consider port collision that might occur. This is the port on which the service is available on the node. Each node proxies that port (the same number on every node) into your service.

kool
  • 190
  • 6