<p>I am using minikube </p>

<p>My deployment file</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpdeployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: phpapp
  template:
    metadata:
      labels:
        app: phpapp
    spec:
      containers:
      - image: rajendar38/myhtmlapp:latest
        name: php
        ports:
        - containerPort: 80

ingress
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  backend:
    serviceName: php-service
    servicePort: 80

this is my service
apiVersion: v1
kind: Service
metadata:
  name: php-service
spec:
  selector:
    app: phpapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 31000
  type: NodePort
</code></pre>

<p>simple php application I build docker image I am able to access 
in both the ways </p>

<ul>
<li><a href="http://192.168.99.100/test.html" rel="nofollow noreferrer">http://192.168.99.100/test.html</a></li>
<li><a href="http://192.168.99.100:31000/test.html" rel="nofollow noreferrer">http://192.168.99.100:31000/test.html</a></li>
</ul>

<p>After that I:</p>

<ul>
<li>updated my php application </li>
<li>create the Image again, pushed to Docker Hub</li>
<li>deleted all resources </li>
<li>kubectl delete all --all</li>
<li>Then forced apply deployment and service </li>
</ul>

<p>but with node port way I am able access old application. but with Ingress  way I am able access changes are picked up</p>

Rajendar Talatam
<p>Please take look on similar <a href="https://stackoverflow.com/questions/52522570/how-to-expose-a-kubernetes-service-on-a-specific-nodeport">problem</a>. </p>

<p>You have to know that container port is the port container listens on. Service port is the port where kubernetes service is exposed on cluster internal ip and mapped to the container port. Nodeport is the port exposed on the host and mapped to kubernetes service.</p>

<p>NodePort  lets you expose a service by specifying that value in the service’s type. Ingress, on the other hand, is a completely independent resource to your service. You declare, create and destroy it separately to your services.
Thanks to service type NodePort you are able to expose both ports(31000, 80).</p>

<p>Your configuration files should look similar:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpdeployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: phpapp
  template:
    metadata:
      labels:
        app: phpapp
    spec:
      containers:
      - image: rajendar38/myhtmlapp:latest
        name: php
        command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
        ports:
        - containerPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
        - path: /example
          backend:
            serviceName: php
            servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: php
spec:
  selector:
    app: php
  ports:
    - port: 31000
      targetPort: 80
      protocol: TCP
      name:
  type: NodePort
</code></pre>

<p>Then expose deployment:</p>

<pre><code>$ kubectl expose deployment phpdeployment --type=NodePort
</code></pre>

<p>Official documentations: <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">kubernetes-service-nodeport</a>, <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">kubernestes-ingress</a>, <a href="https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/" rel="nofollow noreferrer">kubernetes-deployment-exposing</a>.</p>
