Migrating to a new node group
This topic describes how you can create a new node group, gracefully migrate your existing
applications to the new group, and remove the old node group from your cluster. You can
migrate to a new node group using eksctl
or the AWS Management Console.
- eksctl
-
To migrate your applications to a new node group with
eksctl
For more information on using eksctl for migration, see Unmanaged nodegroup upgrades
in the eksctl
documentation.This procedure requires
eksctl
version0.135.0
or later. You can check your version with the following command:eksctl version
For instructions on how to install or upgrade
eksctl
, see Installing or updating eksctl.Note This procedure only works for clusters and node groups that were created with
eksctl
.-
Retrieve the name of your existing node groups, replacing
with your cluster name.my-cluster
eksctl get nodegroups --cluster=
my-cluster
The example output is as follows.
CLUSTER NODEGROUP CREATED MIN SIZE MAX SIZE DESIRED CAPACITY INSTANCE TYPE IMAGE ID default standard-nodes 2019-05-01T22:26:58Z 1 4 3 t3.medium ami-05a71d034119ffc12
-
Launch a new node group with
eksctl
with the following command. In the command, replace every
with your own values. The version number can't be later than the Kubernetes version for your control plane. Also, it can't be more than two minor versions earlier than the Kubernetes version for your control plane. We recommend that you use the same version as your control plane.example value
We recommend blocking pod access to IMDS if the following conditions are true:
You plan to assign IAM roles to all of your Kubernetes service accounts so that pods only have the minimum permissions that they need.
No pods in the cluster require access to the Amazon EC2 instance metadata service (IMDS) for other reasons, such as retrieving the current AWS Region.
For more information, see Restrict access to the instance profile assigned to the worker node
. To block pod access to IMDS, add the
--disable-pod-imds
option to the following command.Note For more available flags and their descriptions, see https://eksctl.io/
. eksctl create nodegroup \ --cluster
my-cluster
\ --version1.25
\ --namestandard-nodes-new
\ --node-typet3.medium
\ --nodes3
\ --nodes-min1
\ --nodes-max4
\ --managed=false -
When the previous command completes, verify that all of your nodes have reached the
Ready
state with the following command:kubectl get nodes
-
Delete the original node group with the following command. In the command, replace every
with your cluster and node group names:example value
eksctl delete nodegroup --cluster
my-cluster
--namestandard-nodes-old
-
- AWS Management Console and AWS CLI
-
To migrate your applications to a new node group with the AWS Management Console and AWS CLI
-
Launch a new node group by following the steps that are outlined in Launching self-managed Amazon Linux nodes.
-
When your stack has finished creating, select it in the console and choose Outputs.
-
Record the NodeInstanceRole for the node group that was created. You need this to add the new Amazon EKS nodes to your cluster.
Note If you attached any additional IAM policies to your old node group IAM role, attach those same policies to your new node group IAM role to maintain that functionality on the new group. This applies to you if you added permissions for the Kubernetes Cluster Autoscaler
, for example. -
Update the security groups for both node groups so that they can communicate with each other. For more information, see Amazon EKS security group requirements and considerations.
-
Record the security group IDs for both node groups. This is shown as the NodeSecurityGroup value in the AWS CloudFormation stack outputs.
You can use the following AWS CLI commands to get the security group IDs from the stack names. In these commands,
oldNodes
is the AWS CloudFormation stack name for your older node stack, andnewNodes
is the name of the stack that you are migrating to. Replace every
with your own values.example value
oldNodes="
old_node_CFN_stack_name
" newNodes="new_node_CFN_stack_name
" oldSecGroup=$(aws cloudformation describe-stack-resources --stack-name $oldNodes \ --query 'StackResources[?ResourceType==`AWS::EC2::SecurityGroup`].PhysicalResourceId' \ --output text) newSecGroup=$(aws cloudformation describe-stack-resources --stack-name $newNodes \ --query 'StackResources[?ResourceType==`AWS::EC2::SecurityGroup`].PhysicalResourceId' \ --output text) -
Add ingress rules to each node security group so that they accept traffic from each other.
The following AWS CLI commands add inbound rules to each security group that allow all traffic on all protocols from the other security group. This configuration allows pods in each node group to communicate with each other while you're migrating your workload to the new group.
aws ec2 authorize-security-group-ingress --group-id $oldSecGroup \ --source-group $newSecGroup --protocol -1 aws ec2 authorize-security-group-ingress --group-id $newSecGroup \ --source-group $oldSecGroup --protocol -1
-
-
Edit the
aws-auth
configmap to map the new node instance role in RBAC.kubectl edit configmap -n kube-system aws-auth
Add a new
mapRoles
entry for the new node group. If your cluster is in the AWS GovCloud (US-East) or AWS GovCloud (US-West) AWS Regions, then replacearn:aws:
witharn:aws-us-gov:
.apiVersion: v1 data: mapRoles: | - rolearn:
ARN of instance role (not instance profile)
username: system:node:{{EC2PrivateDNSName}} groups: - system:bootstrappers - system:nodes> - rolearn:arn:aws:iam::111122223333:role/nodes-1-16-NodeInstanceRole-U11V27W93CX5
username: system:node:{{EC2PrivateDNSName}} groups: - system:bootstrappers - system:nodesReplace the
snippet with the NodeInstanceRole value that you recorded in a previous step. Then, save and close the file to apply the updated configmap.ARN of instance role (not instance profile)
-
Watch the status of your nodes and wait for your new nodes to join your cluster and reach the
Ready
status.kubectl get nodes --watch
-
(Optional) If you're using the Kubernetes Cluster Autoscaler
, scale the deployment down to zero (0) replicas to avoid conflicting scaling actions. kubectl scale deployments/cluster-autoscaler --replicas=0 -n kube-system
-
Use the following command to taint each of the nodes that you want to remove with
NoSchedule
. This is so that new pods aren't scheduled or rescheduled on the nodes that you're replacing. For more information, see Taints and Tolerationsin the Kubernetes documentation. kubectl taint nodes
node_name
key=value:NoScheduleIf you're upgrading your nodes to a new Kubernetes version, you can identify and taint all of the nodes of a particular Kubernetes version (in this case,
1.23
) with the following code snippet. The version number can't be later than the Kubernetes version of your control plane. It also can't be more than two minor versions earlier than the Kubernetes version of your control plane. We recommend that you use the same version as your control plane.K8S_VERSION=
1.23
nodes=$(kubectl get nodes -o jsonpath="{.items[?(@.status.nodeInfo.kubeletVersion==\"v$K8S_VERSION\")].metadata.name}") for node in ${nodes[@]} do echo "Tainting $node" kubectl taint nodes $node key=value:NoSchedule done -
Determine your cluster's DNS provider.
kubectl get deployments -l k8s-app=kube-dns -n kube-system
The following is the output. This cluster is using CoreDNS for DNS resolution, but your cluster can return
kube-dns
instead):NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE coredns 1 1 1 1 31m
-
If your current deployment is running fewer than two replicas, scale out the deployment to two replicas. Replace
withcoredns
if your previous command output returned that instead.kubedns
kubectl scale deployments/
coredns
--replicas=2 -n kube-system -
Drain each of the nodes that you want to remove from your cluster with the following command:
kubectl drain
node_name
--ignore-daemonsets --delete-local-dataIf you're upgrading your nodes to a new Kubernetes version, identify and drain all of the nodes of a particular Kubernetes version (in this case,
) with the following code snippet.1.23
K8S_VERSION=
1.23
nodes=$(kubectl get nodes -o jsonpath="{.items[?(@.status.nodeInfo.kubeletVersion==\"v$K8S_VERSION\")].metadata.name}") for node in ${nodes[@]} do echo "Draining $node" kubectl drain $node --ignore-daemonsets --delete-local-data done -
After your old nodes finished draining, revoke the security group inbound rules you authorized earlier. Then, delete the AWS CloudFormation stack to terminate the instances.
Note If you attached any additional IAM policies to your old node group IAM role, such as adding permissions for the Kubernetes Cluster Autoscaler
), detach those additional policies from the role before you can delete your AWS CloudFormation stack. -
Revoke the inbound rules that you created for your node security groups earlier. In these commands,
oldNodes
is the AWS CloudFormation stack name for your older node stack, andnewNodes
is the name of the stack that you are migrating to.oldNodes="
old_node_CFN_stack_name
" newNodes="new_node_CFN_stack_name
" oldSecGroup=$(aws cloudformation describe-stack-resources --stack-name $oldNodes \ --query 'StackResources[?ResourceType==`AWS::EC2::SecurityGroup`].PhysicalResourceId' \ --output text) newSecGroup=$(aws cloudformation describe-stack-resources --stack-name $newNodes \ --query 'StackResources[?ResourceType==`AWS::EC2::SecurityGroup`].PhysicalResourceId' \ --output text) aws ec2 revoke-security-group-ingress --group-id $oldSecGroup \ --source-group $newSecGroup --protocol -1 aws ec2 revoke-security-group-ingress --group-id $newSecGroup \ --source-group $oldSecGroup --protocol -1 Open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation
. -
Select your old node stack.
-
Choose Delete.
-
In the Delete stack confirmation dialog box, choose Delete stack.
-
-
Edit the
aws-auth
configmap to remove the old node instance role from RBAC.kubectl edit configmap -n kube-system aws-auth
Delete the
mapRoles
entry for the old node group. If your cluster is in the AWS GovCloud (US-East) or AWS GovCloud (US-West) AWS Regions, then replacearn:aws:
witharn:aws-us-gov:
.apiVersion: v1 data: mapRoles: | - rolearn:
arn:aws:iam::111122223333:role/nodes-1-16-NodeInstanceRole-W70725MZQFF8
username: system:node:{{EC2PrivateDNSName}} groups: - system:bootstrappers - system:nodes - rolearn:arn:aws:iam::111122223333:role/nodes-1-15-NodeInstanceRole-U11V27W93CX5
username: system:node:{{EC2PrivateDNSName}} groups: - system:bootstrappers - system:nodes>Save and close the file to apply the updated configmap.
-
(Optional) If you are using the Kubernetes Cluster Autoscaler
, scale the deployment back to one replica. Note You must also tag your new Auto Scaling group appropriately (for example,
k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/
) and update the command for your Cluster Autoscaler deployment to point to the newly tagged Auto Scaling group. For more information, see Cluster Autoscaler on AWSmy-cluster
. kubectl scale deployments/cluster-autoscaler --replicas=1 -n kube-system
-
(Optional) Verify that you're using the latest version of the Amazon VPC CNI plugin for Kubernetes
. You might need to update your CNI version to use the latest supported instance types. For more information, see Working with the Amazon VPC CNI plugin for Kubernetes Amazon EKS add-on. -
If your cluster is using
kube-dns
for DNS resolution (see previous step), scale in thekube-dns
deployment to one replica.kubectl scale deployments/kube-dns --replicas=1 -n kube-system
-