<p>I have a simple kubernetes setup: 1 pod, 1 service with LoadBalancer and things just work. But I don't want to pay extra for a load balancer when I have only 1 pod.</p>
<p>I tried to switch to NodePort, but I'm not able to access the service on the right ports (because they are remapped to 30000+ ports). I have a service that I'd like to access on port 443, but I can't, so what can I do in this case?</p>
<p>My service would be <code>https://server.aaa.com</code>, but if the port is remapped to 30000, I need to use <code>https://server.aaa.com:30000</code>? any way to be on port 443?</p>
<p><a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types</a></p>

07mm8
<p>If you wish to avoid paying for the loadbalancer i would suggest to take a look into <a href="https://metallb.universe.tf/" rel="nofollow noreferrer">Metallb</a>.</p>
<blockquote>
<p>MetalLB hooks into your Kubernetes cluster, and provides a network
load-balancer implementation. In short, it allows you to create
Kubernetes services of type “LoadBalancer” in clusters that don’t run
on a cloud provider, and thus cannot simply hook into paid products to
provide load-balancers.</p>
</blockquote>
<p>This would be better solution than using <code>nodePort</code> since it has significant downsides for production use. Changing the <code>nodePort</code> range also is not recommended since it might get in to conflict with other ports (<a href="https://stackoverflow.com/questions/63698150/in-kubernetes-why-nodeport-has-default-port-range-from-30000-32767/63704276#63704276">You may find here more information why) </a>. However if you want to do it there is nothing blocking you from doing that.</p>
<p>Still worth to note that there is not good alternative to cloud native LBs. The possible substitutes have issues, that makes them less convenient to use and less secure.</p>
<p>Lastly you may want to check the Kubernestes <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces" rel="nofollow noreferrer">host namespaces</a> :</p>
<ul>
<li><p><strong>HostNetwork</strong> - Controls whether the pod may use the node network namespace. Doing so gives the pod access to the loopback device,
services listening on localhost, and could be used to snoop on
network activity of other pods on the same node.</p>
</li>
<li><p><strong>HostPorts</strong>  - Provides a list of ranges of allowable ports in the host network namespace. Defined as a list of  <code>HostPortRange</code>, with
<code>min</code>(inclusive) and  <code>max</code>(inclusive). Defaults to no allowed host
ports.</p>
</li>
</ul>
<p>However <code>HostPort</code> has couple of downsides as it limits the scheduling options for your pod, as only hosts with vacancies for your chosen port can be used. If the host where your pods are running become unreachable, K8s will reschedule it to different nodes. So if the IP address for you workload change, clients of your application will lose access to the pod (the same thing will happen if you restart the pod).</p>
<p>You may want to read <a href="https://medium.com/@maniankara/kubernetes-tcp-load-balancer-service-on-premise-non-cloud-f85c9fd8f43c#:%7E:text=NodePort%20vs%20HostPort%20vs%20HostNetwork&amp;text=It%20specifies%20the%20port%20number,access%20to%20nodes%20network%20namespace." rel="nofollow noreferrer">this document</a> where the author compares <code>hostNetwork</code>, <code>hostPorts</code>and <code>nodePort</code>.</p>
