unable to configure NGINX Ingress Controller

9/12/2019

I have an eks cluster and my deployment , service and loadBalancer all work fine.each service creates its own LoadBalancer and all services are up and running .I have one front end service and 2 backend services here is the my deployment and ingress file

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache-kubernetes
spec:
  replicas: 2
  selector:
    matchLabels:
      app: apache-kubernetes
  template:
    metadata:
      labels:
        app: apache-kubernetes
    spec:
      containers:
      - name: apache-kubernetes
        image: httpd
        ports:
        - containerPort: 80
        env:
        - name: MESSAGE
          value: Hello Kubernetes!
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-apache-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"

spec:
  rules:
  - host: apache.example.com
  - http:
      paths:
      - path: /
        backend:
          serviceName: apache-kubernetes
          servicePort: 80

I have a similar deployment and service yaml file which deploys and creates a nginx web server .I also ran the following commands The following Mandatory Command is required for all deployments.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

and

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml

as documented in this url https://kubernetes.github.io/ingress-nginx/deploy/#aws

I then run these two commands kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/service-l4.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/patch-configmap-l4.yaml

I run kubectl get all, I see my pods , replicatsets and deployments are running fine ,

kubectl get ingress shows 
hosts                 ADDRESS
apache.example.com   216990309c-1626238635.us-east-2.elb.amazonaws.com
nginx.example.com    216990309c-1626238635.us-east-2.elb.amazonaws.com

I was expecting that when I hit apache.example.com -- it should show "it works" and Nginx.example.com should show "welcome Nginx"

Am I doing this right

browser ==>ALB==>ingresscontroller==>ekscluster

update 1

when I hit the url I get 503 but the pods are running

kubectl -n ingress-nginx logs nginx-ingress-controller-db5f9d7b5-cwwh2

gives me

6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:02.505451       6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store
W0911 23:43:20.846517       6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:20.846540       6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store
-- user17970
amazon-eks
kubernetes
nginx-ingress

1 Answer

9/13/2019

So just a thought (and I might have missed read your question) but the ingress-controller doesn't route directly to your deployment, it needs a service to route with, so in your case you would have to create a service like this:

apiVersion: v1
kind: Service
metadata:
  name: apache-kubernetes
spec:
  selector:
    app: apache-kubernetes
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

This will then configure the nginx ingress with endpoints to route to, where in your ingress you specify:

...
paths:
      - path: /
        backend:
          serviceName: apache-kubernetes
          servicePort: 80

this will point to a service not a deployment

The flow (logically as nginx ingress doess some magic for less hops):

browser ==>ALB==>ekscluster==>ingresscontroller==>service==>pod

-- Spazzy757
Source: StackOverflow