<p>I have a kubernetes setup running nicely, but I can't seem to expose services externally. I'm thinking my networking is not set up correctly:</p>

<p>kubernetes services addresses: --service-cluster-ip-range=172.16.0.1/16</p>

<p>flannel network config: etcdctl get /test.lan/network/config {"Network":"172.17.0.0/16"}</p>

<p>docker subnet setting: --bip=10.0.0.1/24</p>

<p>Hostnode IP: 192.168.4.57</p>

<p>I've got the nginx service running and I've tried to expose it like so:</p>

<pre><code>[root@kubemaster ~]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
nginx-px6uy   1/1       Running   0          4m
[root@kubemaster ~]# kubectl get services
NAME         LABELS                                    SELECTOR    IP(S)           PORT(S)    AGE
kubernetes   component=apiserver,provider=kubernetes   &lt;none&gt;      172.16.0.1      443/TCP    31m
nginx        run=nginx                                 run=nginx   172.16.84.166   9000/TCP   3m
</code></pre>

<p>and then I exposed the service like this:</p>

<pre><code>kubectl expose rc nginx --port=9000 --target-port=9000 --type=NodePort
NAME      LABELS      SELECTOR    IP(S)     PORT(S)    AGE
nginx     run=nginx   run=nginx             9000/TCP   292y
</code></pre>

<p>I'm expecting now to be able to get to the nginx container on the hostnodes IP (192.168.4.57) - have I misunderstood the networking? If I have, can explanation would be appreciated :(</p>

<p>Note: This is on physical hardware with no cloud provider provided load balancer, so NodePort is the only option I have, I think?</p>

<p>So the issue here was that there's a missing piece of the puzzle when you use nodePort.</p>

<p>I was also making a mistake with the commands.</p>

<p>Firstly, you need to make sure you expose the right ports, in this case 80 for nginx:</p>

<pre><code>kubectl expose rc nginx --port=80 --type=NodePort
</code></pre>

<p>Secondly, you need to use <code>kubectl describe svc nginx</code> and it'll show you the NodePort it's assigned on each node:</p>

<pre><code>[root@kubemaster ~]# kubectl describe svc nginx
Name:           nginx
Namespace:      default
Labels:         run=nginx
Selector:       run=nginx
Type:           NodePort
IP:         172.16.92.8
Port:           &lt;unnamed&gt;   80/TCP
NodePort:       &lt;unnamed&gt;   32033/TCP
Endpoints:      10.0.0.126:80,10.0.0.127:80,10.0.0.128:80
Session Affinity:   None
No events.
</code></pre>

<p>You can of course assign one when you deploy, but I was missing this info when using randomly assigned ports.</p>
