Kubernetes: Four Ways to Punch Out
In my day job I work with EKS, where I almost exclusively rely on LoadBalancer and ClusterIP Services for external and internal networking, respectively. Things are often not so straightforward in the homelab or on local, temporary clusters, and every once in a while I find myself needing a refresher on what my other options are. Here are the four essential ways to let external traffic into your cluster:
LoadBalancerService type- Requires integration with some external load balancer provider, usually pre-configured as part of a batteries-included Kubernetes distribution like EKS or GKE. Alternatively, you can use MetalLB, but so far I’ve found it to be overkill in my homelab.
NodePortService type- Allocates a port on the node that links to the Service. You can optionally specify a port with
service.spec.ports.nodePort. The main constraint here is that the port must be in the range 30000 – 32767.
- Allocates a port on the node that links to the Service. You can optionally specify a port with
pod.spec.containers.ports.hostPortfield- Like a
NodePortService, this allocates a port on the host node. There are two key differences to note: First,hostPortis specified at the Pod level rather than at the Service level. Second, there is no restriction on what port you can allocate, though standard OS restrictions still apply (on Linux, ports 1 - 1023 can only be allocated byroot). - The fact that
hostPortis a Pod-level field has an important consequence: if you usehostPort(you should avoid it where possible), you must ensure that only one pod per node will ask for a given port. This way you will avoid port collisions. One way to mitigate this is by limiting your use of this field to inside DaemonSets. Presumably, you could also enforce this with a policy engine.
- Like a
kubectl port-forwardcommand- Forwards a port on the machine running the
kubectlcommand, and terminates when the selected pod dies. This is only really useful for debugging purposes, but can be very handy when working with local clusters (e.g.kind).
- Forwards a port on the machine running the
2025-06-16