<p>For the <code>main.go</code> code at the end of this question, I ran the following commands to run it on a <code>kubernetes</code> install (on a <code>PC</code>):</p>

<ol>
<li><p><code>docker image build -t myID/go-demo:1.2 .</code></p></li>
<li><p><code>docker image push myID/go-demo:1.2  # Pushed up to DockerHub</code></p></li>
<li><p><code>kubectl run demo2 --image=myID/go-demo:1.2 --port=19999 --labels app=demo2</code></p></li>
<li><p><code>kubectl port-forward deploy/demo2 19999:8888</code></p>

<p><code>Forwarding from 127.0.0.1:19999 -&gt; 8888
 Forwarding from [::1]:19999 -&gt; 8888</code></p></li>
</ol>

<p>Then, in another <code>tmux(1)</code> terminal, I confirmed the service was <code>LISTEN</code>ing:</p>

<pre><code>user@vps10$ sudo netstat -ntlp | egrep "Local|19999"
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:19999         0.0.0.0:*               LISTEN      736786/kubectl      
tcp6       0      0 ::1:19999               :::*                    LISTEN      736786/kubectl
</code></pre>

<p>But here's my problem, noticing success with <code>localhost</code> and failure with <code>hostname -- vps10</code>:</p>

<pre><code>user@vps10$ curl localhost:19999 # Works.
Hello, 世界

user@vps10$ curl vps10:19999     # Fails.
curl: (7) Failed to connect to vps10 port 19999: Connection refused
</code></pre>

<p>From the above, the issue appears to be that the service is listening only via the <code>loopback</code> interface, and if that's indeed the issue, what do I do to get it to listen on <code>all interfaces</code> (or on a <code>specific interface</code> that I specify). I'm not a <code>kubernetes</code> or <code>go</code> expert (this example is from a book actually =:)), so please supply commands if necessary. Thank you in advance!</p>

<p><strong>HTTP server code</strong>:</p>

<pre><code>package main

import (
        "fmt"
        "log"
        "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, "Hello, 世界")
}

func main() {
        http.HandleFunc("/", handler)
        log.Fatal(http.ListenAndServe("0.0.0.0:8888", nil))
}
</code></pre>

<p>According to kubectl help:</p>

<pre><code> # Listen on port 8888 on all addresses, forwarding to 5000 in the pod
  kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000

  # Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
  kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000

</code></pre>

<p>The default is forwarding for localhost only.</p>
