<p>I have one web application which I am trying to run on k8s cluster. I build the image from DockerFile and was testing locally till now using the command:</p>
<pre><code>docker run --name web-app -d -p 8888:80 web-app
</code></pre>
<p>and I was able to access the GUI using http://localhost:8888.</p>
<p>Now, I am trying to run it in k8s cluster, so I executed the same docker run command in my k8s cluster and I am getting the o/p when I am trying to curl http://localhost:8888 from my cluster.
But this is not I want in production, I want to access the web application using node ip like
http://&lt;node_ip&gt;:8888.
I tried a few times but not able to access it using node ip.</p>
<p>Now, I have 2 questions:</p>
<ol>
<li>What changes I need to make in docker run command in order to access the application using node IP?</li>
<li>I also tried running the container using helm charts and by creating a service of type NodePort but it is also not working. Is there anything we need to take care while running any frontend web application using helm install?</li>
</ol>

Amit
<p>For NodePort type service, you need to hit in <code>&lt;node_ip&gt;:&lt;nodePort&gt;</code>. NodePort is the port which you have exposed in you service maniest.</p>
<ul>
<li><code>kubectl get nodes -o wide</code>: To get the NodeIP</li>
</ul>
<p>For example, in this service manifest the nodePort is <code>31000</code>. Remember one thing <code>nodePort</code> range is from 30000 to 32767.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 31000
</code></pre>
<p>You don't need docker run if you deploy your application in kubernetes. Have you created a deployment of your application in k8s? If yes then you can enter your application via <code>kubectl exec -it &lt;pod_nam&gt; sh</code>. If you want to communicate from outside the cluster you need to create se NodePort type service as i said and then you can get the access by <code>http://&lt;node_ip&gt;:&lt;node_port&gt;</code>.</p>
<p>Here I have given a yaml for deployment as an example.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.1
          ports:
            - containerPort: 80
</code></pre>
<p>By the way, your <code>containerPort</code> in deployment must need to be equal to the <code>targetPort</code> in service.</p>
