<p>I am new to Kubernetes &amp; Docker. I created a simple nodejs application and deployed on BlueMix Kubernetes. But I am unable to accesses the application on internet. The ip &amp; port mentioned in the kubernetes is not accessible. Can somebody help me.</p>

<p>I tried to <a href="http://10.76.193.146:31972" rel="nofollow noreferrer">http://10.76.193.146:31972</a>, but it did not go through. I am not sure if this the public ip as its 10. series.</p>

<p>I also tried the public ip ( <a href="http://184.173.1.79:31972" rel="nofollow noreferrer">http://184.173.1.79:31972</a> ) mentioned in the blue mix kubernetes cluster - screenshot below. But that too failed.</p>

<p>This are steps I followed.</p>

<ol>
<li>Created a nodejs app locally. It ran as desired on the local</li>
</ol>

<blockquote>
<pre><code>// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
</code></pre>
</blockquote>

<p>---------- package.json</p>

<blockquote>
<pre><code>{
  "name": "helloworld-nodejs",
  "version": "0.0.1",
  "description": "First Docker",
  "main": "app.js",
  "scripts": {
    "start": "PORT=8000 node ./app.js"
  },
  "author": "",
  "license": "ISC"
}
</code></pre>
</blockquote>

<ol start="2">
<li><p>Created a docker container locally and ran the docker. It worked properly</p></li>
<li><p>Uploaded the docker container on Bluemix registry as</p>

<blockquote>
  <p>registry.ng.bluemix.net/testkubernetes/helloworld-nodejs:0.0.1</p>
</blockquote></li>
<li><p>Created the Nodes and Services in Kubernetes, using the following YAML file</p></li>
</ol>

<p>----------Node YAML file</p>

<blockquote>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: helloworld-nodejs
  labels:
    name: helloworld-nodejs
spec:
  containers:
    - name: helloworld-nodejs
      image: registry.ng.bluemix.net/testkubernetes/helloworld-nodejs:0.0.1
      ports:
        - containerPort: 8000
</code></pre>
</blockquote>

<p>---------- Services YAML</p>

<blockquote>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: helloworld-nodejs
  labels:
    name: helloworld-nodejs
spec:
  type: NodePort
  selector:
    name: helloworld-nodejs
  ports:
  - port: 8080
</code></pre>
</blockquote>

<ol start="5">
<li>The application gets deployed properly and is also running, which I can confirm from the logs</li>
</ol>

<p><a href="https://i.stack.imgur.com/uuRik.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uuRik.png" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/coKmv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/coKmv.png" alt="enter image description here"></a></p>

<p>Result of kubectl get services &amp; kubectl get nodes command</p>

<p><a href="https://i.stack.imgur.com/K9DV0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K9DV0.png" alt="Result of kubectl get services"></a></p>

<p><a href="https://i.stack.imgur.com/0HMQA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0HMQA.png" alt="Result of kubectl get nodes"></a></p>

<p><a href="https://i.stack.imgur.com/9atM8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9atM8.png" alt="enter image description here"></a></p>

<p>Since your service's <code>port</code> is different from your pod's <code>containerPort</code>, you will have to specify <code>targetPort</code> in your service.</p>

<pre><code>spec:
  type: NodePort
  selector:
    name: helloworld-nodejs
  ports:
    - port: 8080
      targetPort: 8000
</code></pre>

<p>According to the Kubernetes <a href="https://kubernetes.io/docs/api-reference/v1.5/#serviceport-v1" rel="nofollow noreferrer">documentation</a> on <code>targetPort</code>, it is the:</p>

<blockquote>
  <p>Number or name of the port to access on the pods targeted by the
  service. .... If this is not specified, the value of the 'port' field
  is used (an identity map).</p>
</blockquote>
