Nginx ingress is one of the common way to access a containerized service.
References:
References:
If you are using minikube, confirm that ingress addon is enabled
minikube addons enable ingress
Create a namespace to run the deployments
kubectl create namespace ingress
Deploy the app in the namespace.
helm install tr-webapp ./tr-webapp --namespace ingress
Create a file (ingress.yaml) to apply ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: hello-world.ingress
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: tr-webapp
port:
number: 8080
Apply the new settings
kubectl apply -f ingress.yaml --namespace ingress
Check service and ingress resources
[roberto@vmlab01 ingress]$ kubectl get svc --namespace ingress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
tr-webapp NodePort 10.100.96.113 <none> 8080:31682/TCP 6m52s
[roberto@vmlab01 ingress]$ kubectl get ingress --namespace ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress <none> hello-world.ingress 192.168.49.2 80 4m4s
(you should wait a few seconds until “ADDRESS” list an IP address for the ingress resource)
Create a static entry in /etc/hosts to point to the new hostname hello-world.ingress
sudo echo "192.168.49.2 hello-world.ingress" >> /etc/hosts
Now you should be able to access the url:
[roberto@vmlab01 ingress]$ curl hello-world.ingress
Hello World