Sometime you need some not standart AMI in kubernetes cluster, for example you want to preload some docker images in kubernetes node
-
Make some changes in https://github.com/awslabs/amazon-eks-ami/blob/v20210208/scripts/install-worker.sh - for example
sudo systemctl start docker
# this will preload and extract mysql image on kubernetes node
# as the result, when node start - it's will speed up pod start in cluster ~ 40s
sudo docker pull mysql:8.0.23
- Update AMI (with cached docker layers) in EKS cluster, without recreating ASG
#!/bin/sh
version=^eksctl-
ami=<SOME-AMI>
echo "WARNING!! this will create new launch-template-version in eks cluster"
sleep 30s
set -ex
aws autoscaling describe-auto-scaling-groups --max-items 100 | jq -r '.AutoScalingGroups[] | "\(.AutoScalingGroupName) \(.MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateName)"' | grep -i $version | while read line
do
AutoScalingGroupName=`echo $line | awk '{print $1}'`
LaunchTemplateName=`echo $line | awk '{print $2}'`
template=`aws ec2 create-launch-template-version --launch-template-name "$LaunchTemplateName" --source-version 1 --launch-template-data "{\"ImageId\":\"$ami\"}"`
VersionNumber=`echo $template | jq -r '.LaunchTemplateVersion.VersionNumber'`
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name $AutoScalingGroupName \
--mixed-instances-policy "{\"LaunchTemplate\":{\"LaunchTemplateSpecification\":{\"LaunchTemplateName\":\"$LaunchTemplateName\",\"Version\":\"$VersionNumber\"}}}"
done