Why am I getting 502 errors on my ALB end points, targeted at EKS hosted services

11/26/2019

I am building a service in EKS that has two deployments, two services (NodePort) , and a single ingress.

  • I am using the aws-alb-ingress-controller.
  • When I run kubectl port-forward POD 8080:80 It does show me my working pods.
  • When I look at the generated endpoints by the alb I get 502 errors.
  • When I look at the Registered Targets of the target group I am seeing the message, Health checks failed with these codes: [502]

Here is my complete yaml.

---
#Example game deployment and service
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: "example-game"
  namespace: "example-app"
spec:
  replicas: 5
  template:
    metadata:
      labels:
        app: "example-game"
    spec:
      containers:
      - image: alexwhen/docker-2048
        imagePullPolicy: Always
        name: "example-game"
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: "service-example-game"
  namespace: "example-app"
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    app: "example-app"


#Example nginxdemo Deployment and Service
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: "example-nginxdemo"
  namespace: "example-app"
spec:
  replicas: 5
  template:
    metadata:
      labels:
        app: "example-nginxdemo"
    spec:
      containers:
      - image: nginxdemos/hello
        imagePullPolicy: Always
        name: "example-nginxdemo"
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: "service-example-nginxdemo"
  namespace: "example-app"
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    app: "example-app"
---

#Shared ALB ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "example-ingress"
  namespace: "example-app"
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
    Alb.ingress.kubernetes.io/healthcheck-port: traffic-port
    alb.ingress.kubernetes.io/healthcheck-path: /

#   alb.ingress.kubernetes.io/scheme: internal
#   alb.ingress.kubernetes.io/load-balancer-attributes: routing.http2.enabled=true

  labels:
    app: example-app
spec:
  rules:
    - http:
        paths:
          - path: /game/*
            backend:
              serviceName: "service-example-game"
              servicePort: 80
          - path: /nginxdemo/*
            backend:
              serviceName: "service-example-nginxdemo"
              servicePort: 80
-- Josh Beauregard
aws-alb
eks
kubernetes
kubernetes-ingress

1 Answer

2/18/2020

I don't know why but it turns out that the label given to to ingress has to be unique.

When I changed the label from 'example-app' to 'example-app-ingress' it just started working.

-- Josh Beauregard
Source: StackOverflow