<h2>Environment</h2>
<ul>
<li>Windows 10 OS</li>
<li>WSL2 ( minikube is using Linux containers )</li>
<li>minikube v1.25.2</li>
<li>kubectl v1.23.0</li>
</ul>
<h2>Use-case</h2>
<ul>
<li>pod 1 - mongodb</li>
<li>pod 2 - mongo express</li>
<li>Internal service for accessing mongodb</li>
<li>External service (LoadBalancer) for accessing mongo express from a browser</li>
</ul>
<h2>Problem at hand</h2>
<p>Running the following opens a browser on service EndPoint but the mongo express page doesn't load giving &quot;<strong>This site can’t be reached</strong>&quot;</p>
<pre><code>minikube.exe service mongo-express-service
</code></pre>
<h2>YAML Files</h2>
<hr />
<h2>mongo-deployment.yaml</h2>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-username
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key:  mongo-root-password
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
spec:
  selector:
    app: mongodb
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<h2>mongoexpress-deployment.yaml</h2>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
      - name: mongo-express
        image: mongo-express
        ports:
          - containerPort: 8081
        env:
          - name: ME_CONFIG_MONGODB_ADMINUSERNAME
            valueFrom:
              secretKeyRef:
                name: mongodb-secret
                key: mongo-root-username
          - name: ME_CONFIG_MONGODB_ADMINPASSWORD
            valueFrom:
              secretKeyRef:
                name: mongodb-secret
                key:  mongo-root-password
          - name: ME_CONFIG_MONGODB_SERVER
            valueFrom:
              configMapKeyRef:
                name: mongodb-configmap
                key: database_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
spec:
  selector:
    app: mongo-express
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30000
</code></pre>
<h2>mongo-configmap.yaml</h2>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: mongodb-configmap
data:
  database_url: mongodb-service
</code></pre>
<h2>mongo-secret.yaml</h2>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: mongodb-secret
type: Opaque
data:
  mongo-root-username: cm9vdA==
  mongo-root-password: ZXhhbXBsZQ==
</code></pre>
<h2>.\kubectl.exe get all -o wide</h2>
<pre><code>NAME                                      READY   STATUS    RESTARTS      AGE   IP           NODE       NOMINATED NODE   READINESS GATES
pod/mongo-express-68c4748bd6-5qnnh        1/1     Running   2 (16h ago)   20h   172.17.0.3   minikube   &lt;none&gt;           &lt;none&gt;
pod/mongodb-deployment-7bb6c6c4c7-w2bdx   1/1     Running   1 (16h ago)   22h   172.17.0.4   minikube   &lt;none&gt;           &lt;none&gt;

NAME                            TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE   SELECTOR
service/kubernetes              ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP          8d    &lt;none&gt;
service/mongo-express-service   LoadBalancer   10.108.182.35    &lt;pending&gt;     8081:30000/TCP   20h   app=mongo-express
service/mongodb-service         ClusterIP      10.107.207.139   &lt;none&gt;        27017/TCP        21h   app=mongodb

NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS      IMAGES          SELECTOR
deployment.apps/mongo-express        1/1     1            1           20h   mongo-express   mongo-express   app=mongo-express
deployment.apps/mongodb-deployment   1/1     1            1           22h   mongodb         mongo           app=mongodb

NAME                                            DESIRED   CURRENT   READY   AGE   CONTAINERS      IMAGES          SELECTOR
replicaset.apps/mongo-express-68c4748bd6        1         1         1       20h   mongo-express   mongo-express   app=mongo-express,pod-template-hash=68c4748bd6
replicaset.apps/mongo-express-6f76745c84        0         0         0       20h   mongo-express   mongo-express   app=mongo-express,pod-template-hash=6f76745c84
replicaset.apps/mongodb-deployment-7bb6c6c4c7   1         1         1       22h   mongodb         mongo           app=mongodb,pod-template-hash=7bb6c6c4c7
</code></pre>
<p><strong>While executing <em>minikube.exe service mongo-express-service</em> the browser opens on <em><a href="http://192.168.49.2:30000/" rel="nofollow noreferrer">http://192.168.49.2:30000/</a></em> and returns &quot;<em>This site can’t be reached 192.168.49.2 took too long to respond.</em>&quot;, same happen if I use the loopback IP, what am I doing wrong ?</strong></p>

NadavRub
<p>Well, it appears that I had to use <em>minikube tunnel</em> to enable access to the service, strangely, the mongo express service was accessible on port 8081 rather than 30000... I guess this is because it is bring access by the tunnel and not directly</p>
<pre><code>kubectl get svc
NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes              ClusterIP      10.96.0.1        &lt;none&gt;        443/TCP          8d
mongo-express-service   LoadBalancer   10.108.182.35    127.0.0.1     8081:30000/TCP   22h
mongodb-service         ClusterIP      10.107.207.139   &lt;none&gt;        27017/TCP        23h
</code></pre>
