amazon-web-servicesaws-api-gatewayamazon-ekseksctl

EKS configuration: API Gateway and pods in private subnets


In AWS, I'm trying to configure my K8S cluster with EKS, and from my limited experience with AWS and its services, I am struggling in configuring the integration between different parts.

Context:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-dev-deployment
  namespace: dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api-dev
  template:
    metadata:
      labels:
        app: api-dev
    spec:
      nodeSelector:
        subnet-type: private
      containers:
        - name: api-dev
          image: [my private image URL from ECR]
          ports:
              - containerPort: 5000

The pod deployment is OK, and it's able to connect to the internet from the private subnet (connection to mongodb atlas in my case), so NAT Gateway is working fine here.

What I am trying to achieve:

What I did:

What's going wrong:

When I am trying to do a test call to the API Gateway endpoint, I am getting an error 500 with the message:

Sat Aug 05 16:33:18 UTC 2023 : Execution failed due to configuration error: Invalid endpoint address.

Can please anyone help me in configuring the above mentioned? I was going through much documentation, but I can't find a good one.


Solution

  • I think first of all you need service type Loadbalancer to expose your pod, I also think that both API Gateway and EKS cluster are in different VPCs, so it is not possible to connect them without VPC endpoints

    So the external traffic will be routed via API Gateway which sends traffic to the services hosted inside EKS via VPC Private Link -> ELB.

    Here is a blog for reference