Skip to content
Advertisement

EKS/AKS cluster name convention

I am writing a script that receives a Kubernetes context name as an input and outputs the different elements of the cluster ->

class GKE:
    def __init__(self, context):
        s = context.split("_")
        self.provider: str = s[0]
        self.project: str = s[1]
        self.data_center: GKE.DataCenter = GKE.DataCenter(data_center=s[2])
        self.cluster_name: str = s[3]

    def __str__(self):
        return f'provider: {self.provider}, project: {self.project}, {self.data_center}, cluster name: {self.cluster_name}'

    class DataCenter:
        def __init__(self, data_center: str):
            s = data_center.split("-")
            self.country: str = s[0]
            self.region: str = s[1]
            self.zone: str = s[2]

        def __str__(self):
            return f'country: {self.country}, region: {self.region}, zone: {self.zone}'

class EKS:
    # TODO: What are the fields? What is the convention?
    pass

class AKS:
    # TODO: What are the fields? What is the convention?
    pass

if __name__ == '__main__':
    print(GKE(context="gke_XXX-YYY-ZZZ_us-central1-c_name"))

Output:

provider: gke, project: XXX-YYY-ZZZ, country: us, region: central1, zone: c, cluster name: name

This will support only the three main providers (GKE, EKS, AKS).

My question is:

What are the different elements of EKS and AKS context names?

Advertisement

Answer

You need to differentiate between the correct name of the cluster and the naming schema of a resource.

When I run kubectl config get-contexts on the clusters Aks, Eks, and Gke I get the following results:

NAME                                               AUTHINFO
gke_project-1234_us-central1-c_myGKECluster        gke_project-1234_us-central1-c_myGKECluster  
myAKSCluster                                       clusterUser_myResourceGroup_myAKSCluster
arn:aws:eks:eu-west-1:1234:cluster/myEKSCluster    arn:aws:eks:eu-west-1:1234:cluster/myEKSCluster

In all three clouds, the correct name of the cluster in this example is my***Cluster.

The naming scheme in ~/.kube/config is used to distinguish one cluster (contexts wise) from another. For example when you want to change the context with kubectl, then you have to differentiate between cluster whose name is myCluster and is in region-code1 Compared to another cluster whose name is also myCluster but he is in region-code2, and so on, so you will use the naming scheme.

GKE:

As you wrote, the naming scheme in gke consists of 4 parts: provider_project-id_zone_cluster-name
For example gke_project-123_us-central1-c_myGKECluster

  • provider: gke
  • project-id: project-123
  • zone: us-central1-c
  • cluster-name: myGKECluster

AKS:
In aks the naming schema is the name of the cluster.
But the AUTHINFO, (which is actually the configuration of the user in the kubeconfig file), consists of three parts: Resource-type_Resource-group_Resource-name
For example clusterUser_myResourceGroup_myAKSCluster

  • The Resource-type is clusterUser
  • The Resource-group is myResourceGroup
  • The Resource-name is myAKSCluster

EKS:

AWS requires an ARN when needed to specify a resource unambiguously across all of AWS.

The ARN format is arn:partition:service:region:account-id:resource-type/resource-id
For example arn:aws:eks:eu-west-1:1234:cluster/myEKSCluster

  • partition: the partition in which the resource is located (such as aws Regions).
  • service: The service namespace that identifies the AWS product (such as eks).
  • region: The Region code (such as eu-west-1).
  • account-id: The ID of the AWS account that owns the resource(such as 1234).
  • resource-type: The resource type (such as cluster).
  • resource-id The resource identifier. This is the name of the resource, the ID of the resource, or a resource path (such as myEKSCluster).

Additional resources:

https://stackoverflow.com/a/63824179/20571972 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#aws-resource-eks-cluster-return-values

Advertisement