How do I create multiple node groups for Amazon EKS nodes using eksctl?

Last updated: 2022-08-04

I want to create multiple node groups for Amazon Elastic Kubernetes Service (Amazon EKS) nodes using eksctl.

Short description

You can create a node group using eksctl either with default parameters or with custom parameters using a configuration file for multiple node groups.

Resolution

Create a node group with default parameters

1.    Install eksctl.

2.    To confirm that eksctl is configured and installed on the terminal with the correct permissions, run this command:

$ eksctl version

3.    To create an additional node group with default parameters, run this command:

$ eksctl create nodegroup --cluster=yourClusterName --name=yourNodeGroupName --region yourRegionName

Here are the default parameters:

Instance type = m5.large
AMI : lastest AWS EKS AMI
Nodes-desired capacity = 2
Nodes-min capacity =2 
Nodes-max capacity=2

Note: By default, new node groups inherit the version of Kubernetes installed from the control plane (–version=auto), but you can specify a different version of Kubernetes (for example, version=1.13). To use the latest version of Kubernetes, run the –version=latest command.

4.    Open the AWS CloudFormation console and choose the stack associated with the node group that you created. Then, choose the Events tab to look for an AWS CloudFormation event showing that your stack is deployed.

5.    To confirm that the new node groups are attached to the cluster and to verify that the node group configuration is applied, run these commands:

$ Kubectl get nodes
$ eksctl get nodegroups --cluster yourClusterName

Create a node group with custom parameters

1.    Define the parameters for the new node group in a configuration file. For example:

kind: ClusterConfig
apiVersion: eksctl.io/v1alpha5
metadata:
    name: yourClusterName
    region: yourRegionName
nodeGroups:
  - name: ng1-Workers
    availabilityZones: ["az-name"]
    desiredCapacity: 3
    instanceType: m5.large
    iam:
      instanceProfileARN: "arn:aws:iam::11111:instance-profile/eks-nodes-base-role" #Attaching IAM role
      instanceRoleARN: "arn:aws:iam::1111:role/eks-nodes-base-role"
    privateNetworking: true
    securityGroups:
      withShared: true
      withLocal: true
      attachIDs: ['sg-11111', 'sg-11112']
    ssh:
      publicKeyName: 'my-instance-key'
    kubeletExtraConfig:
        kubeReserved:
            cpu: "300m"
            memory: "300Mi"
            ephemeral-storage: "1Gi"
        kubeReservedCgroup: "/kube-reserved"
        systemReserved:
            cpu: "300m"
            memory: "300Mi"
            ephemeral-storage: "1Gi"
    tags:
      'environment': 'development'
  - name: ng-2-builders #example of a nodegroup that uses 50% spot instances and 50% on demand instances:
    minSize: 2
    maxSize: 5
    instancesDistribution:
      maxPrice: 0.017
      instanceTypes: ["t3.small", "t3.medium"] # At least two instance types should be specified
      onDemandBaseCapacity: 0
      onDemandPercentageAboveBaseCapacity: 50
      spotInstancePools: 2
    tags:
      'environment': 'production'

2.    To create an additional node group using the configuration file, run this command:

$ eksctl create nodegroup --config-file= yourConfigFileName

3.    Open the AWS CloudFormation console, and then choose the stack associated with the node group that you created. Then, choose the Events tab to look for an AWS CloudFormation event showing that your stack is deployed.

4.    To confirm that the new node groups are attached to the cluster and to verify that the node group configuration is applied, run these commands:

$ kubectl get nodes
$ eksctl get nodegroups --cluster yourClusterName

You see that your nodes have joined the cluster. You can see that the two node groups are visible by using eksctl.


Did this article help?


Do you need billing or technical support?