Skip to content

Create EKS Service Using Standalone Target Group (No Load Balancer Attached)

0

The problem is that I’ve been assigned to create a service that uses a target group not associated with any load balancer. The target group is new and has not been previously created, and its ARN is being referenced from the EKS manifests. I need anywork around or docs to create Targetgroup from eks without any loadbalancer.

2 Answers
0

This guide demonstrates how to use AWS Controllers for Kubernetes (ACK) to provision and manage Application Load Balancer (ALB) resources through Kubernetes APIs.

Prerequisites

  • EKS cluster
  • kubectl configured
  • Helm installed
  • Necessary IAM permissions

Method 1: Using ACK ELBv2 Controller

Step 1: Install ACK ELBv2 Controller

# Export required variables in the terminal
export SERVICE=elbv2
export RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")')
export ACK_SYSTEM_NAMESPACE=ack-system
export AWS_REGION=us-east-1 # Use the correct region for your deployment

# Complete the login to public ECR repository (make sure a role/user has logged in the terminal as an AWS identity)
aws ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws

# Run the helm command
helm install --create-namespace -n $ACK_SYSTEM_NAMESPACE ack-$SERVICE-controller \
  oci://public.ecr.aws/aws-controllers-k8s/$SERVICE-chart --version=$RELEASE_VERSION --set=aws.region=$AWS_REGION

Step 2: Deploy ALB Resources

Here's an example manifest that sets up:

  • Two target groups (Blue/Green)
  • One ALB listener
  • Traffic split configuration
apiVersion: elbv2.services.k8s.aws/v1alpha1
kind: TargetGroup
metadata:
  name: blue-tg
spec:
  name: blue-tg
  protocol: HTTP
  port: 80
  targetType: ip
  vpcID: {VPC_ID}
---
apiVersion: elbv2.services.k8s.aws/v1alpha1
kind: TargetGroup
metadata:
  name: green-tg
spec:
  name: green-tg
  protocol: HTTP
  port: 80
  targetType: ip
  vpcID: {VPC_ID}
---
apiVersion: elbv2.services.k8s.aws/v1alpha1
kind: Listener
metadata:
  name: main-listener
spec:
  loadBalancerARN: {LOAD_BALANCER_ARN}
  port: 80
  protocol: HTTP
  defaultActions:
    - type: forward
      forwardConfig:
        targetGroups:
          - targetGroupARN: ${BLUE_TG_ARN}
            weight: 90
          - targetGroupARN: ${GREEN_TG_ARN}
            weight: 10

Benefits

  1. Declarative management of ALB reyour source documents. Native Kubernetes experience
  2. Simplified canary and blue-green deployments
  3. Version-controlled infrastructure

Notes

  • Replace placeholder values (VPC_ID, ARNs) with your actual values
  • Adjust weights in forwardConfig based on your traffic split requirements
  • Ensure proper IAM permissions are configured for the ACK controller

Additional Resources

#aws #kubernetes #eks #alb #ack

UPDATES:

AWS

answered a year ago

  • I don't want blue green, I just want to create target for service from manifests

  • btw the commands for helm install is not working

0

To create a standalone target group for use with EKS without attaching it to a load balancer, you can use the AWS Load Balancer Controller's TargetGroupBinding custom resource. This approach allows you to create a target group independently and then reference it from your EKS manifests.

Here's how you can accomplish this:

  1. First, create the target group using the AWS CLI or SDK:
aws elbv2 create-target-group \
--name my-standalone-targetgroup \
--protocol HTTP \
--port 80 \
--target-type instance \
--vpc-id vpc-12345678

The command above creates a target group with HTTP protocol on port 80 for instance targets. You can adjust parameters like protocol, port, and target-type based on your requirements.

  1. After creating the target group, you can use the TargetGroupBinding custom resource in your EKS manifests to associate pods with this target group:
apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
name: my-targetgroup-binding
spec:
targetGroupARN: <your-target-group-arn>
serviceRef:
name: my-service
port: 80

This TargetGroupBinding resource will register the pods backing your Kubernetes service as targets in the standalone target group.

For multi-cluster scenarios, you can use the multiClusterTargetGroup flag in the TargetGroupBinding to allow the same target group to be used across multiple EKS clusters:

apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
name: my-targetgroup-binding
spec:
targetGroupARN: <your-target-group-arn>
serviceRef:
name: my-service
port: 80
multiClusterTargetGroup: true

This approach gives you the flexibility to create and manage target groups independently of load balancers, which can be useful for scenarios where you need to pre-create target groups or share them across multiple resources.
Sources
Use CreateTargetGroup with an AWS SDK or CLI - AWS SDK Code Examples
Building Resilient Multi-cluster Applications with Amazon EKS, Part 1: Implementing Cross-cluster Load Balancing with NLB | Networking & Content Delivery

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.