Reputation: 43
I have a webapp deployed on Kubernetes running on a VM and I can access it on my PC through http://node-ip1:31000
.
However, I want to add a second VM, also running that app, which will have its own IP and be accessed by http://node-ip2:31000
. But it doesn't make much sense that we have to access an app through another IP if one fails, is there an easy way to map the NodePort to a URL like http://my-app
? I know it can be done with a DNS server but I don't know how or if it's the easiest way.
Upvotes: 0
Views: 408
Reputation: 60046
I know it can be done with a DNS server but I don't know how or if it's the easiest way
Node port is not recommended approach to expose; it is hard to manage and it reveals security risks.
So you install ingress, if you are some cloud provider then its that simple
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install ingress-nginx ingress-nginx/ingress-nginx
and then the ingress for the service which you want to expose, for example nodejs-app
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
name: ingress-nodejs
spec:
tls:
- hosts:
- demoapp.example.com
secretName: demoapp.example.com.tls
rules:
- host: demoapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nodejs-app
port:
number: 3000
Upvotes: 1