<p>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 <a href="http://127.0.0.1:8080" rel="nofollow noreferrer">http://127.0.0.1:8080</a> from within the pod, I get the correct response.</p>

<p>My pod also has an address. Lets call it 10.1.2.3 (hypothetical). If I try to do curl -v <a href="http://10.1.2.3:8080" rel="nofollow noreferrer">http://10.1.2.3:8080</a>, I get a connection closed.</p>

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

<p>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 <a href="http://localhost:34000" rel="nofollow noreferrer">http://localhost:34000</a> and reach my application, but that is obviously not happening.</p>

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

<p>resource.yaml</p>

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

<p>service.yaml</p>

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

<p>According to your configuration, the link should be available at:</p>

<pre><code>http://localhost:33000/
</code></pre>

<p>Or you need to change the port</p>

<pre><code>- port: 33000 # external port
</code></pre>

<p>to the port:</p>

<pre><code>- port: 8080 # external port
</code></pre>

<p>Then the address will change to this:</p>

<pre><code>http://localhost:8080/
</code></pre>

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

<p>You can find more information about your balancing type <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">here</a>.</p>
