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:
but with node port way I am able access old application. but with Ingress way I am able access changes are picked up
it is browser cache issue once used private session it is working fine
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.