Ingress doesn't work on Google Kubernetes Engine (GKE)

11/5/2018

Below given the config, I am trying to deploy on Google Kubernetes Engine. But after deployment, I can't access the service on the ingress external IP.

I can access the service if I do:

$ kubectl exec POD_NAME
# curl GET localhost:6078/todos

But I can't access it through ingress. GKE UI show errors like:

  • Error during sync: error while evaluating the ingress spec: could not find service "default/todo"

OR

  • Some backend services are in UNHEALTHY state

Even though the backend pod is up and running.

I believe there is something wrong with the service.

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: todo
  labels:
    app: todo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: todo
  template:
    metadata:
      labels:
        app: todo
    spec:
      containers:
        - image: eu.gcr.io/xxxxx/todo
          name: todo
          ports:
            - containerPort: 6078
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: todo
  labels:
    app: todo
spec:
  type: NodePort
  ports:
    - port: 6078
  selector:
    app: todo
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: todo-ingress
spec:
  rules:
  - http:
  paths:
  - path: /*
    backend:
      serviceName: todo
      servicePort: 6078
-- Jahid Shohel
google-kubernetes-engine
kubernetes

1 Answer

11/6/2018

Hard to tell without knowing what 'todo' does, but there's a few things:

  1. There's an indentation error on the Ingress definition. I'm not sure if it's typo or it didn't get applied:

    Instead, it should be something:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: todo-ingress
    spec:
      rules:
      - http:
          paths:
          - path: /*
            backend:
              serviceName: todo
              servicePort: 6078
  2. If you really want /* with no host then the default backend is overriding you, since it's the last rule in the nginx.conf, so you might as well configure:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: todo-ingress
    spec:
      backend:
        serviceName: todo
        servicePort: 6078
  3. Is your service binding to 0.0.0.0 and not 127.0.0.1. Listening to on 127.0.0.1 will cause it to serve locally in the pod but not to any service outside.

-- Rico
Source: StackOverflow