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

Last updated: 2019-11-22

How do I create multiple node groups for Amazon Elastic Kubernetes Service (Amazon EKS) worker nodes using eksctl?

Short Description

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

Resolution

Create a worker 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 the following command:

$ eksctl version

3.    To create an additional worker node group with default parameters, run the following 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, 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 worker node groups are attached to the cluster and to verify that the node group configuration is applied, run the following commands:

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

Create a worker node group with custom parameters

1.    Define the parameters for the new worker node group in a configuration file. See the following example:

kind: ClusterConfig
apiVersion: eksctl.io/v1alpha5
metadata:
    name: yourClusterName
    region: yourRegionName
nodeGroups:
 - name: ng1-Workers
   availabilityZones: ["az-name"]
   desiredCapacity: 3
   instanceType: m5.large
    desiredCapacity: 3
    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 worker node group using the configuration file, run the following command:

$ eksctl create nodegroup --config-file= yourConfigFileName

3.    Open the AWS CloudFormation console, 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 worker node groups are attached to the cluster and to verify that the node group configuration is applied, run the following commands:

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

You see that your worker nodes have joined the cluster. Two node groups should be visible through eksctl.


Did this article help you?

Anything we could improve?


Need more help?