Kubernetes Nginx Ingress not finding service endpoint
I discovered what I was doing wrong. In my application definition I was using name
as my selector
selector: matchLabels: name: hello-world template: metadata: labels: name: hello-world
Whereas in my service I was using app
selector: app: hello-world
After updating my service to use app
, it worked
selector: matchLabels: app: hello-world template: metadata: labels: app: hello-world
Another situation when it may happen is when ingress class of the ingress controller does not match ingress class in the ingress resource manifest used for your services.
Nginx installation command, short example:
helm install stable/nginx-ingress \ --name ${INGRESS_RELEASE_NAME} \ --namespace ${K8S_NAMESPACE} \ --set controller.scope.enabled=true \ --set controller.scope.namespace=${K8S_NAMESPACE} \ --set controller.ingressClass=${NGINX_INGRESS_CLASS}
ingress resource spec. , excerpt:
apiVersion: extensions/v1beta1kind: Ingressmetadata: labels: annotations: # folowing line is not valid for K8s or Helm, # but reflects the values must be the same kubernetes.io/ingress.class: ${NGINX_INGRESS_CLASS}
In my case, I included an "id" directive in my Service selector that was missing from the Deployment metadata and this prevented the endpoints controller from finding the correct Pod. I expect the reverse case would also fail:
---apiVersion: v1kind: Servicemetadata: name: some-servicespec: ports: - name: port-name port: 1234 protocol: TCP selector: app: some-app id: "0" ## include in both or neither