Why can't I attach a service type ClusterIP to Ingress on GKE?

10/10/2019

Before I begin, I would like to mention that I am on the free trial version of GKE. I have a simple server running in a GKE cluster. I have a service that I use to expose the server. I am trying to configure an Ingress Controller and attach it to this service.

Everything works perfectly if my service is of type LoadBalancer, NodePort. However, if my service is of type ClusterIP, I get an error saying

error while evaluating the ingress spec: service "default/simple-server" is type "ClusterIP"
, expected "NodePort" or "LoadBalancer" 

GKE then stops trying to provision an IP for the ingress. Why can't I provision a service of type clusterIP and is there a work around?

I tried using annotations.kubernetes.io/ingress.class: "nginx" and it still didn't work.

-- goldentiger
google-kubernetes-engine
kubernetes
kubernetes-ingress

3 Answers

10/10/2019

Use something like this.Use NodPort or LoadBalancer infront of type as per you convenience.

spec:
  ports:
    - protocol: TCP
      port: XX
      targetPort: XX
  type: NodePort
-- Dashrath Mundkar
Source: StackOverflow

10/10/2019

The native GKE ingress controller does not support ClusterIP, but it works perfectly with LoadBalancer and NodePort type. Take a look at this issue

Non-native ingress controller Nginx works with ClusterIP.

-- Kamol Hasan
Source: StackOverflow

10/10/2019

That's normal and it's pretty simple why you have the error.

A ClusterIP service is an internal only service inside of your Kubernetes cluster and what you are trying to create (from what I undestood) is a publicly exposed service using ingress, meaning you are going to create a Google Load balancer.

Now the why it doesn't support ClusterIP is because when you create the ingress, the LB resource created inside google cloud needs a target port on your cluster to call on And for that you need to expose an ip/port for it.

I would not recommend combining LB service (wich by default create a LB on cloud provider) and ingress, but stay on a nodeport/ingress duo that is cleaner.

Bonus: The annotation you used is for internal services with ingress to be linked to your ingress controller. This will allow the ingress-controller to list the hosts and proxy traffic to the right service.

-- night-gold
Source: StackOverflow