Nginx Ingress Controller offers a lot more features than the default ingress controller by GKE This post explains how to quickly setup an Nginx ingress controller on your K8s cluster running on GKE

The setup

First of all, we need to make your GCP user as the cluster admin so that you have the sufficient permissions to create the service accounts and whatnot

kubectl create clusterrolebinding cluster-admin-binding \
  --clusterrole cluster-admin \
  --user $(gcloud config get-value account)

If you have Kubernetes version older than 1.14

If you have an older version of Kubernetes, we need to make a small label change for it to work


on line 217, change to


kubectl apply -f mandatory.yaml

If you don’t do this, you will see an error as below

kubectl describe pod nginx-ingress-controller-5bcd4b688-9msjm -n ingress-nginx
  Type     Reason             Age                  From                Message
  ----     ------             ----                 ----                -------
  Warning  FailedScheduling   8s (x9 over 2m28s)   default-scheduler   0/3 nodes are available: 3 node(s) didn't match node selector.
  Normal   NotTriggerScaleUp  7s (x14 over 2m26s)  cluster-autoscaler  pod didn't trigger scale-up (it wouldn't fit if a new node is added): 3 node(s) didn't match node selector

This happens because in previous versions of k8s in GKE, the nodes are labelled as

If you have a newer than 1.14 k8s version

No need to edit anything

kubectl apply -f

And finally

kubectl apply -f

Create the Ingress

Once you have created the ingress controller on your cluster, you can create the ingress resource. An example is given below

apiVersion: extensions/v1beta1
kind: Ingress
  annotations: nginx
  name: demo-ingress
  namespace: demo
    - host:
          - backend:
              serviceName: demo-backend
              servicePort: 9000
            path: /
    - host:
          - backend:
              serviceName: demo-backend-2
              servicePort: 9001
            path: /
    - hosts:
      secretName: tls-data

That’s all