Setting up nginx-ingress without Google Load Balancer in GKE

It's nice to have a load balancer to dynamically distribute incoming traffic across nodes inside Kubernetes cluster. However, it is a bit of overkill when you are running your side projects on GKE with a single node and it costs additional ~$20 a month for an otherwise inexpensive cluster.

We could avoid this by running ingress controller on hostPort which exposes http ports via the host IP. Changing the service type to NodePort prevents GCP from creating forwarding rules in Google Load Balancer. Using nginx-ingress Helm chart we can easily achieved this by setting the values as below:

controller:
  kind: DaemonSet
  daemonset:
    useHostPort: true
  service:
    type: NodePort
values.yml

I'm not a big fan of Helm charts in general, so here I'm just using it to generate the yaml configurations and then manually apply it using  kubectl.

helm fetch stable/nginx-ingress --untar --untardir nginx
helm template nginx/nginx-ingress --name nginx-ingress --values values.yml > k8s.yml
kubectl apply -f k8s.yml

Ideally, in a production system I would recommend you to use a load balancer as the cost out weights the benefits.