<p>I deployed a web app in minikube.</p>
<p>Deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: maypp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myapp
          imagePullPolicy: Never
          ports:
          - containerPort: 8080
      restartPolicy: Always
</code></pre>
<p>Service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  type: NodePort
  ports:
  - port: 8080
</code></pre>
<p>After <code>kubectl apply -f .</code> to deploy, all of them are running.</p>
<pre><code>kubectl get po
NAMESPACE   NAME                       READY   STATUS    RESTARTS   AGE
default     myapp-5d042b65c8-h7kag     1/1     Running   0          10m

kubectl get svc
NAMESPACE   NAME        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
default     myservice   NodePort   10.102.128.35  &lt;none&gt;        8080:32212/TCP           10m
</code></pre>
<p>Run <code>minikube service</code> to open service in browser:</p>
<pre><code>minikube service myservice
|----------------|--------------------|-------------|---------------------------|
|   NAMESPACE    |        NAME        | TARGET PORT |            URL            |
|----------------|--------------------|-------------|---------------------------|
|   default      | myservice          |        8080 | http://192.168.49.2:32212 |
|----------------|--------------------|-------------|---------------------------|
🏃  Starting tunnel for service myservice.
|----------------|--------------------|-------------|------------------------|
|   NAMESPACE    |        NAME        | TARGET PORT |          URL           |
|----------------|--------------------|-------------|------------------------|
|   default      | myservice          |             | http://127.0.0.1:55401 |
|----------------|--------------------|-------------|------------------------|
🎉  Opening service default/myservice in default browser...
</code></pre>
<p>In browser, I can't access my app with both <code>http://192.168.49.2:32212</code> and <code>http://127.0.0.1:55401</code>. Even <code>http://127.0.0.1:8080</code>.</p>
<p>From the pod's log, the web server in the container is running:</p>
<pre><code>kubectl logs -f myapp-5d042b65c8-h7kag

...
____________________________________O/_______
                                    O\
⇨ http server started on [::]:8080
</code></pre>
<p>But didn't get the way to access the endpoint correctly. So there isn't any traffic happened.</p>
<p>If I deploy the container with docker, it works with <code>http://127.0.0.1:8080</code>.</p>

<p>The problem is the missing <code>selector</code> field in the <code>Service</code>.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
  - port: 8080
</code></pre>
<p>Services route the traffic to the pods based on the selector defined in the service spec that match to the labels defined on the pods.</p>
<p>From the <a href="https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service" rel="nofollow noreferrer">defining-a-service</a> section of the docs:</p>
<blockquote>
<p>The controller for the Service selector continuously scans for Pods
that match its selector, and then POSTs any updates to an Endpoint
object also named &quot;my-service&quot;.</p>
</blockquote>
