<p><a href="https://stackoverflow.com/questions/44714406/google-container-engine-with-external-ip-without-load-balancer">Google Container Engine with external IP, without load balancer</a></p>

<p>I was looking into how to create a bunch of servers on a google cloud kubernetes engine. Ended up making a few with a load balancer... while the price isn't bad now I tried using a service type of NodePort and it binds to the local IP address of the VM it is tied to and not the external IP or anything else. How would I go about routing traffic to a service type of node-port? Also, would it be safe for me to  make a SRV record for the container in the node to access my service with a preemptible instance / possible reassignment if kubernetes does this automatically?  </p>

sfxworks
<p>It is possible to use <a href="https://kubernetes.io" rel="nofollow noreferrer">Kubernetes</a> NodePort to act as external service. </p>

<p>NodePorts will expose a port on each of your hosts that you can use to reach your service.</p>

<p>The downside of this approach is dealing with port-management. </p>

<p>Applications can no assume same things like HTTPS is port 443, or that MySQL runs on port 3306. 
Instead, it may live on port 32042 in PROD, and 32012 in DEV.</p>

<p>Consider using NodePort that way
is a gaping hole in cluster security, moreover <strong>NodePort cannot expose standard low-numbered
ports like 80 and 443.</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:  
  name: my-nodeport-service
spec:
  selector:    
    app: my-app
  type: NodePort
  ports:  
  - name: http
    port: 80
    targetPort: 80
    nodePort: 30036
    protocol: TCP
</code></pre>

<p>With <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">ingress</a>, you can run a software load balancer such as nginx, expose it as port 80/443 on
all your hosts and then control routing any HTTP traffic to Kuberbetes services.</p>

<p>This works best for layer 7 traffic like HTTP/HTTPS.</p>

<p>You may try Ingress resources and Ingress controller and an external load balancer
or public IP to enable path-based routing of external requests to internal Services.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  backend:
    serviceName: other
    servicePort: 8080
  rules:
  - host: foo.mydomain.com
    http:
      paths:
      - backend:
          serviceName: foo
          servicePort: 8080
  - host: mydomain.com
    http:
      paths:
      - path: /bar/*
        backend:
          serviceName: bar
          servicePort: 8080
</code></pre>

<p>Inspirated by 
<a href="https://oteemo.com/2017/12/12/think-nodeport-kubernetes/" rel="nofollow noreferrer">think-nodeport-kubernetes</a> and <a href="https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0" rel="nofollow noreferrer">cloud kubernetes nodeport vs ingress</a> article.</p>
