<p>I am new to kubernetes and trying to deploy a simple hello-world app. I am using Ubuntu 20.04 and running it on VMware workstation. I have installed minikube and trying to deploy. However, the pods are deployed but the service is not accessible through browser.</p>
<p>Below is my <code>deployment.yaml</code> file:</p>
<pre><code>---
kind: Service
apiVersion: v1
metadata:
  name: exampleservice
spec:
  selector:
    name: myapp
  ports:
    - protocol: &quot;TCP&quot;
      # Port accessible inside cluster
      port: 8081
      # Port to forward to inside the pod
      targetPort: 8080
      # Port accessible outside cluster
      nodePort: 30000
  type: NodePort
 
 
 
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myappdeployment
spec:
  replicas: 5
  selector:
    matchLabels:
        name: myapp
  template:
    metadata:
      labels:
        name: myapp
    spec:
      containers:
        - name: myapp
          image: pritishkapli/example:v1.0.0
          ports:
            - containerPort: 8080
          resources:
            limits:
              memory: 512Mi
              cpu: &quot;1&quot;
            requests:
              memory: 256Mi
              cpu: &quot;0.2&quot;
</code></pre>
<p>Below is the kubernetes service:</p>
<pre><code>pritish@ubuntu:~$ kubectl get svc
NAME             TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
exampleservice   LoadBalancer   10.101.149.155   &lt;pending&gt;     8081:30000/TCP   12m
kubernetes       ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP          9h
</code></pre>
<p>Below is the pods running:</p>
<pre><code>pritish@ubuntu:~$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
myappdeployment-b85b56d64-knhhc   1/1     Running   0          17m
myappdeployment-b85b56d64-m4vbg   1/1     Running   0          17m
myappdeployment-b85b56d64-qss4l   1/1     Running   0          17m
myappdeployment-b85b56d64-r2jq4   1/1     Running   0          17m
myappdeployment-b85b56d64-tflnz   1/1     Running   0          17m
</code></pre>
<p>Please help!</p>
<p>PS: I have updated the <code>deployment.yaml</code> file and it's working as expected.</p>

Pritish
<h3><strong>TL;DR</strong></h3>
<p>This is not the issue with the <code>Service</code> of type <code>LoadBalancer</code> but the <strong>mismatch between <code>service.spec.selector</code> value and <code>deployment.spec.selector.matchLabels</code></strong> value.</p>
<hr />
<h3>How you can fix your setup?</h3>
<p>To fix your setup you can use the same values from either <code>Service</code> or <code>Deployment</code>.</p>
<p><strong>Please choose only one of the following options:</strong></p>
<ul>
<li><code>deployment.yaml</code> changes:</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myappdeployment
spec:
  replicas: 5
  selector:
    matchLabels:
        app: myapp # &lt;-- CHANGES
  template:
    metadata:
      labels:
        app: myapp # &lt;-- CHANGES
    spec:
      containers:
        - name: myapp
          image: pritishkapli/example:v1.0.0
          ports:
            - containerPort: 8080
          resources:
            limits:
              memory: 512Mi
              cpu: &quot;1&quot;
            requests:
              memory: 256Mi
              cpu: &quot;0.2&quot;
</code></pre>
<ul>
<li><code>service.yaml</code> changes:</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>kind: Service
apiVersion: v1
metadata:
  name: exampleservice
spec:
  selector:
    app.kubernetes.io/name: myapp # &lt;-- CHANGES
  ports:
    - protocol: &quot;TCP&quot;
      # Port accessible inside cluster
      port: 8081
      # Port to forward to inside the pod
      targetPort: 8080
      # Port accessible outside cluster
      nodePort: 30000
  type: LoadBalancer
</code></pre>
<hr />
<h3>How could you tell that this was the issue with <code>selector</code>?</h3>
<p>This comes down to the experience on working with Kubernetes, but the easiest method to check it is by either (using old examples):</p>
<ul>
<li><code>kubectl describe service exampleservice</code> (part of this output is redacted due to readability)</li>
</ul>
<pre class="lang-sh prettyprint-override"><code>Name:                     exampleservice
Namespace:                default
Labels:                   &lt;none&gt;
Selector:                 app=myapp
Type:                     LoadBalancer
IP:                       10.8.10.103
Port:                     &lt;unset&gt;  8081/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  30000/TCP
Endpoints:                &lt;none&gt; # &lt;-- LOOK HERE!
</code></pre>
<ul>
<li><code>kubectl get endpoints exampleservice</code></li>
</ul>
<pre><code>NAME             ENDPOINTS   AGE
exampleservice   &lt;none&gt;      2m3s
</code></pre>
<p>As you can see on above output there are no <code>endpoints</code> to send the traffic to (<code>Pods</code>).</p>
<hr />
<h3>Service of type <code>LoadBalancer</code> on <code>minikube</code></h3>
<p>Talking from the perspective of the <code>Service</code> of type <code>Loadbalancer</code> on <code>minikube</code>:</p>
<p>The easiest method would be to connect as said previously by a <code>NodePort</code>. Due to <code>minikube</code>'s local nature, it won't get the <code>External IP</code> assigned unless you opt for a workaround including for example:</p>
<ul>
<li><code>minikube tunnel</code></li>
</ul>
<blockquote>
<p><strong>tunnel</strong> - creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP. for a detailed example see <a href="https://minikube.sigs.k8s.io/docs/tasks/loadbalancer" rel="nofollow noreferrer">https://minikube.sigs.k8s.io/docs/tasks/loadbalancer</a></p>
<p><em><a href="https://minikube.sigs.k8s.io/docs/commands/tunnel/" rel="nofollow noreferrer">Minikube.sigs.k8s.io: Docs: Commands: Tunnel</a></em></p>
</blockquote>
<hr />
<p><strong>A side note!</strong></p>
<p>I haven't tested it personally but you could try to experiment with: <code>$ minikube addons enable metallb</code> to assign it the IP address in the same <code>CIDR</code> as your <code>minikube</code> instance and then query (<code>curl</code>) this newly assigned IP.</p>
<p>A guide for more reference:</p>
<ul>
<li><em><a href="https://medium.com/faun/metallb-configuration-in-minikube-to-enable-kubernetes-service-of-type-loadbalancer-9559739787df" rel="nofollow noreferrer">Medium.com: Faun: Metallb configuration in minikube to enable Kubernetes service of type Loadbalancer</a></em></li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/" rel="nofollow noreferrer">Kubernetes.io: Docs: Tasks: Access application cluster: Create external load balancer</a></em></li>
<li><em><a href="https://minikube.sigs.k8s.io/docs/start/" rel="nofollow noreferrer">Minikube.sigs.k8s.io: Docs: Start</a></em></li>
</ul>
