Unable to call my Loadbalanced service in Kubernetes

4/26/2020

I have an application, running on Jetty Server and listening on port 8080. I have deployed it as a container. The application is running correctly and if I do curl -v http://127.0.0.1:8080 from within the pod, I get the correct response.

My pod also has an address. Lets call it 10.1.2.3 (hypothetical). If I try to do curl -v http://10.1.2.3:8080, I get a connection closed.

I tried changing the address on which my application starts to 10.1.2.3 and the curl works after that. However, I feel that defeats the purpose of containerization as I wouldn't have access to this IP before hand.

I also have a load balanced service, where I am mapping port 33000 to my service port 8080. The service was assigned a nodeport of 34000. Since this is running on my local docker, my aim was to do a curl -v http://localhost:34000 and reach my application, but that is obviously not happening.

Can some one please help as to what am I doing wrong? My definitions of the container and the service are given below:

resource.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-service-dev-pod1
  labels:
    app: myapp-service-dev
    component: myapp-service-dev
spec:
  selector:
    matchLabels:
      app: myapp-service-dev-pod1
  replicas: 2    
  template:
    metadata:
      labels:
        app: myapp-service-dev-pod1
        component: myapp-service-dev
    spec:
      volumes:
        - name: shared-dev-data
          emptyDir: {}
      containers:
        - name: myapp-service-dev-pod1
          image: docker/my-apps/mybuild_service:9
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: shared-dev-data
              mountPath: /opt/myapp/jetty/logs

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: myapp-service-dev-lb
  labels:
    app: myapp-service-dev
spec:
  ports:
    - port: 33000
      protocol: TCP
      name: http
      targetPort: 8080
  selector:
    component: myapp-service-dev
  type: LoadBalancer
-- launchpad123
docker
jetty
kubernetes
kubernetes-ingress

2 Answers

4/26/2020

According to your configuration, the link should be available at:

http://localhost:33000/

Or you need to change the port

- port: 33000 # external port

to the port:

- port: 8080 # external port

Then the address will change to this:

http://localhost:8080/

According to your "Load Balancer" balancing type, all requests will be sent to the service port with the LoadBalancer type, which in turn will send requests to the pod's targetPort.

You can find more information about your balancing type here.

-- V. Mokrecov
Source: StackOverflow

4/26/2020

Make jetty listen on 0.0.0.0 instead of 127.0.0.1 Check this for how to do that. This should fix the connection closed issue when you access it via http://PODIP:8080

-- Arghya Sadhu
Source: StackOverflow