<p>I have a webapp deployed on Kubernetes running on a VM and I can access it on my PC through <code>http://node-ip1:31000</code>.</p>
<p>However, I want to add a second VM, also running that app, which will have its own IP and be accessed by <code>http://node-ip2:31000</code>. 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 <code>http://my-app</code>? I know it can be done with a DNS server but I don't know how or if it's the easiest way.</p>

PedroG
<blockquote>
<p>I know it can be done with a DNS server but I don't know how or if it's the easiest way</p>
</blockquote>
<p>Node port is not recommended approach to expose; it is hard to manage and it reveals security risks.</p>
<p>So you install <a href="https://I%20know%20it%20can%20be%20done%20with%20a%20DNS%20server%20but%20I%20don%27t%20know%20how%20or%20if%20it%27s%20the%20easiest%20way." rel="nofollow noreferrer">ingress</a>, if you are some cloud provider then its that simple</p>
<pre><code>helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install ingress-nginx ingress-nginx/ingress-nginx
</code></pre>
<p>and then the ingress for the service which you want to expose, for example <code>nodejs-app</code></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
  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

</code></pre>
