<p>I have a simple REST app I want to deploy into kubernetes. <em>Before</em> I deploy into a cloud provider environment, I want to test out locally using <code>minikube</code>. Here's my setup:</p>

<pre class="lang-yaml prettyprint-override"><code>---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: example
  spec:
    replicas: 3
    selector:
      matchLabels:
        name: example
    template:
      metadata:
        labels:
          name: example
      spec:
        containers:
        - name: application
          image: 1ijk/example
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000

---
  apiVersion: v1
  kind: Service
  metadata:
    name: example
  spec:
    type: NodePort
    ports:
    - name: http
      port: 80
      targetPort: 3000
    selector:
      name: example
</code></pre>

<p>and how I'm invoking it</p>

<pre><code>$ minikube start --driver=hyperkit
[ output omitted ]
$ kubectl apply -f deployment.yml
deployment.apps/example created
ingress.extensions/example-ingress created
$ kubectl get service example
NAME           TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
example        NodePort   10.100.198.224   &lt;none&gt;        3000:32275/TCP   4s
minikube service example --url
http://192.168.64.2:32275
$ minikube service example
|-----------|---------|-------------|---------------------------|
| NAMESPACE |  NAME   | TARGET PORT |            URL            |
|-----------|---------|-------------|---------------------------|
| default   | example | http/80     | http://192.168.64.2:31726 |
|-----------|---------|-------------|---------------------------|
🎉  Opening service default/example in default browser...
</code></pre>

<p>However the browser is unable to connect. I've verified the application binary and its container image both function properly. I seem to be missing a piece of the kubernetes setup on minikube, and all the tutorials I've seen assume a cloud deployment with the <code>LoadBalancer</code> service type.</p>

<p>What can I do to test this simple kubernetes application locally using <code>minikube</code>?</p>

<hr>

<h3>updates</h3>

<p>here's the service description</p>

<pre><code>$ kubectl describe service example
Name:                     example
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"example","namespace":"default"},"spec":{"ports":[{"name":"http","...
Selector:                 name=example
Type:                     NodePort
IP:                       10.107.95.114
Port:                     http  80/TCP
TargetPort:               3000/TCP
NodePort:                 http  31726/TCP
Endpoints:
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>after bypassing the yml file and using the cli to create the deployment and service like so</p>

<pre><code>kubectl create deployment example --image=1ijk/example
kubectl expose deployment example --type=LoadBalancer --port=8080 --target-port=3000
</code></pre>

<p>I get the service set like so</p>

<pre><code>$ kubectl describe service example
Name:                     example
Namespace:                default
Labels:                   app=example
Annotations:              &lt;none&gt;
Selector:                 app=example
Type:                     LoadBalancer
IP:                       10.100.117.7
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               3000/TCP
NodePort:                 &lt;unset&gt;  31683/TCP
Endpoints:                172.17.0.10:3000,172.17.0.5:3000,172.17.0.7:3000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>and same result</p>

<h3>final update: see comments guiding the debug process in the answer below</h3>

<p>The problem was <em>not</em> with the kubernetes -- it was with my app! I made the mistake of binding the go server to <code>"127.0.0.1:3000"</code> instead of <code>":3000"</code> :faceplam:. Binding to the port without specifying IP allows the application server to be accessible on all the containers networking interfaces :)</p>

1ijk
<p>The endpoints of the service is not showing POD IPs.You need to expose pods via a LoadBalancer type service. Instead of using a service yaml use below command.</p>

<pre><code>kubectl expose deployment example --type=LoadBalancer --port=8080 --target-port=3000
</code></pre>

<p>And then you can get the url via below command and use it browser to access the  application.</p>

<pre><code>minikube service example
</code></pre>

<p>Edit:</p>

<p>The go app had a hard-coded value for address which was bound to <code>127.0.0.1</code>.Because of the hardcoding it was not accessible from inside the cluster as well which was verified by curl to <code>10.100.117.7:3000</code> from another pod on the cluster.Removing that hardcoding solved the problem.</p>

<p><a href="https://kubernetes.io/docs/tutorials/hello-minikube/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/hello-minikube/</a></p>
