Changes are not picked up when I access application through Node Port i

11/2/2019

I am using minikube

My deployment file

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

simple php application I build docker image I am able to access in both the ways

After that I:

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

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

-- Rajendar Talatam
docker
kubectl
kubernetes
kubernetes-ingress
minikube

2 Answers

11/5/2019

it is browser cache issue once used private session it is working fine

-- Rajendar Talatam
Source: StackOverflow

11/5/2019

Please take look on similar problem.

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.

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).

Your configuration files should look similar:

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

Then expose deployment:

$ kubectl expose deployment phpdeployment --type=NodePort

Official documentations: kubernetes-service-nodeport, kubernestes-ingress, kubernetes-deployment-exposing.

-- MaggieO
Source: StackOverflow