How to tag VPC and subnets for multiple EKS clusters

Viewed 1388

I have a VPC, 4 subnets (2 public and 2 private) and an EKS Cluster which all created with Terraform. My infra is working without a problem right now. I'm thinking about creating a second EKS Cluster, but I'm a little bit confused about subnet tagging.

For example, one of my private subnets was created like below;

resource "aws_subnet" "vpc-private" {
  vpc_id            = aws_vpc.vpc.id
  cidr_block        = var.private_cidr
  availability_zone = data.aws_availability_zones.available.names[0]

  tags = {
    Environment                                 = var.environment
    Name                                        = "${var.environment}-vpc-private"
    "kubernetes.io/cluster/${var.cluster_name}" = "shared"
    "kubernetes.io/role/internal-elb"           = "1"
  }
}

As you can see, it's tagged with "kubernetes.io/cluster/${var.cluster_name}" = "shared" to enable subnet discovery. Since I'm thinking about creating second cluster for the same subnets, I'm trying to clarify how should subnets be tagged. There is no clear information in AWS documents, at least I didn't find anything clear about this situation. Will adding the second tag like "kubernetes.io/cluster/${var.cluster_2_name}" = "shared" be alright like below ?

resource "aws_subnet" "vpc-private" {
  vpc_id            = aws_vpc.vpc.id
  cidr_block        = var.private_cidr
  availability_zone = data.aws_availability_zones.available.names[0]

  tags = {
    Environment                                 = var.environment
    Name                                        = "${var.environment}-vpc-private"
    "kubernetes.io/cluster/${var.cluster_name}" = "shared"
    "kubernetes.io/cluster/${var.cluster_2_name}" = "shared"
    "kubernetes.io/role/internal-elb"           = "1"
  }
}

Any help/recommendation will be highly appreciated, thank you very much.

1 Answers

To answer my own question, yes tagging the subnet for each EKS Cluster is needed, otherwise load balancers couldn't find where to provision.

In Terraform, I used exact format I asked above

resource "aws_subnet" "vpc-private" {
  vpc_id            = aws_vpc.vpc.id
  cidr_block        = var.private_cidr
  availability_zone = data.aws_availability_zones.available.names[0]

  tags = {
    Environment                                 = var.environment
    Name                                        = "${var.environment}-vpc-private"
    "kubernetes.io/cluster/${var.cluster_name}" = "shared"
    "kubernetes.io/cluster/${var.cluster_2_name}" = "shared"
    "kubernetes.io/role/internal-elb"           = "1"
  }
}
Related