Question
Create a service called webapp-svc listening on port 8080.
Deploy a pod with label app=web and image nginx as backend of the service.
Deploy an Ingress called webapp-ingress and map it with the service webapp-svc on path /web
Answer
First we need to deploy a pod with label app=web using nginx image. Name of the pod doesn’t matter:
kubectl run nginx --image=nginx -l=app=web
Then we to expose the pod using service name webapp-svc on port 8080:
kubectl expose pod nginx --name=webapp-svc --port=8080
Finally we need to deploy Ingress resource which reaches to service webapp-svc on path /web:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: webapp-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /web
pathType: Prefix
backend:
service:
name: webapp-svc
port:
number: 8080
Verify:
kubectl describe ingress webapp-ingress