<p>I have a simple Express.js server Dockerized and when I run it like:</p>

<pre><code>docker run -p 3000:3000 mytag:my-build-id
</code></pre>

<p><a href="http://localhost:3000/" rel="nofollow noreferrer">http://localhost:3000/</a> responds just fine and also if I use the LAN IP of my workstation like <a href="http://10.44.103.60:3000/" rel="nofollow noreferrer">http://10.44.103.60:3000/</a></p>

<p>Now if I deploy this to MicroK8s with a service deployment declaration like:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  name: my-service
spec:
  type: NodePort
  ports:
  - name: "3000"
    port: 3000
    targetPort: 3000
status:
  loadBalancer: {}
</code></pre>

<p>and pod specification like so (update 2019-11-05):</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: my-service
spec:
  replicas: 1
  selector:
    matchLabels:
      name: my-service
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: my-service
    spec:
      containers:
      - image: mytag:my-build-id
        name: my-service
        ports:
        - containerPort: 3000
        resources: {}
      restartPolicy: Always
status: {}
</code></pre>

<p>and obtain the exposed NodePort via <code>kubectl get services</code> to be 32750 and try to visit it on the MicroK8s host machine like so:</p>

<p>curl <a href="http://127.0.0.1:32750" rel="nofollow noreferrer">http://127.0.0.1:32750</a></p>

<p>then the request just hangs and if I try to visit the LAN IP of the MicroK8s host from my workstation at 
<a href="http://192.168.191.248:32750/" rel="nofollow noreferrer">http://192.168.191.248:32750/</a>
then the request is immediately refused.</p>

<p>But, if I try to port forward into the pod with</p>

<pre><code>kubectl port-forward my-service-5db955f57f-q869q 3000:3000
</code></pre>

<p>then <a href="http://localhost:3000/" rel="nofollow noreferrer">http://localhost:3000/</a> works just fine.</p>

<p>So the pod deployment seems to be working fine and example services like the microbot-service work just fine on that cluster.</p>

<p>I've made sure the Express.js server listens on all IPs with </p>

<pre><code>app.listen(port, '0.0.0.0', () =&gt;  ...
</code></pre>

<p>So what can be the issue?</p>

<p>You need to add a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service" rel="nofollow noreferrer">selector</a> to your service. This will tell Kubernetes how to find your deployment. Additionally you can use nodePort to specify the port number of your service. After doing that you will be able to curl your MicroK8s IP.</p>

<p>Your Service YAML should look like this: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  name: my-service
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    targetPort: 80
    nodePort: 30001
  selector: 
    name: my-service      
status:
  loadBalancer: {}
</code></pre>
