|
#!/usr/bin/env bash |
|
|
|
set -o errexit |
|
set -o errtrace |
|
set -o nounset |
|
set -o pipefail |
|
|
|
############################################################################### |
|
### xARM - Amazon EKS on ARM |
|
### Installs an EKS cluster using ARM worker nodes |
|
### Dependencies: aws, eksctl, kubectl, jq |
|
### https://docs.aws.amazon.com/eks/latest/userguide/arm-support.html |
|
|
|
|
|
############################################################################### |
|
### User parameters |
|
# choose a custom name for the cluster: |
|
export XARM_CLUSTER_NAME=xarm |
|
# choose number of worker nodes (between 1 and 4): |
|
export XARM_NODES_INITIAL_NUM=2 |
|
# choose EC2 instance type as per https://aws.amazon.com/ec2/instance-types/a1/ |
|
export XARM_NODES_TYPE=a1.large |
|
|
|
############################################################################### |
|
### Main |
|
echo Starting! Will take some 15 to 20min |
|
|
|
# create the control plane and gather some data we need for the node group: |
|
eksctl create cluster \ |
|
--name $XARM_CLUSTER_NAME \ |
|
--version 1.14 \ |
|
--region us-west-2 \ |
|
--without-nodegroup |
|
|
|
ControlPlaneSecurityGroup=$(aws eks describe-cluster --name $XARM_CLUSTER_NAME | jq .cluster.resourcesVpcConfig.securityGroupIds[0] -r) |
|
VPCId=$(aws eks describe-cluster --name $XARM_CLUSTER_NAME | jq .cluster.resourcesVpcConfig.vpcId -r) |
|
PublicSubnets=$(aws cloudformation describe-stacks --stack-name eksctl-$XARM_CLUSTER_NAME-cluster | jq -r '.Stacks[0].Outputs' | jq -c '.[] | select( .OutputKey == "SubnetsPublic" )' | jq -r '.OutputValue') |
|
|
|
# update control plane (ARM it): |
|
echo Updating control plane with ARM components |
|
|
|
kubectl set image -n kube-system deployment.apps/coredns \ |
|
coredns=602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/coredns-arm64:v1.3.1 |
|
|
|
kubectl set image -n kube-system daemonset.apps/kube-proxy \ |
|
kube-proxy=602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/kube-proxy-arm64:v1.14.7 |
|
|
|
kubectl apply -f https://raw.githubusercontent.com/aws/containers-roadmap/master/preview-programs/eks-ec2-a1-preview/aws-k8s-cni-arm64.yaml |
|
|
|
kubectl -n kube-system get ds kube-proxy -o yaml > kube-proxy.yaml && \ |
|
sed 's/- amd64/- arm64/g' kube-proxy.yaml > kube-proxy-arm.yaml && \ |
|
kubectl apply -f kube-proxy-arm.yaml |
|
|
|
kubectl -n kube-system get deploy coredns -o yaml > coredns.yaml && \ |
|
sed 's/- amd64/- arm64/g' coredns.yaml > coredns-arm.yaml && \ |
|
kubectl apply -f coredns-arm.yaml |
|
|
|
# launch worker nodes and gather some data to join nodes: |
|
echo Launching worker nodes |
|
|
|
tsnow=$(date +%s) |
|
xarmkeyname=xarm-$tsnow |
|
|
|
curl -o amazon-eks-arm-nodegroup.yaml https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2019-11-15/amazon-eks-arm-nodegroup.yaml |
|
|
|
aws ec2 create-key-pair \ |
|
--key-name "$xarmkeyname" | \ |
|
jq -r ".KeyMaterial" > ~/.ssh/$xarmkeyname.pem |
|
|
|
aws cloudformation deploy \ |
|
--template-file amazon-eks-arm-nodegroup.yaml \ |
|
--stack-name eksctl-$XARM_CLUSTER_NAME-ng \ |
|
--capabilities CAPABILITY_IAM \ |
|
--parameter-overrides "ClusterControlPlaneSecurityGroup=$ControlPlaneSecurityGroup" \ |
|
"ClusterName=$XARM_CLUSTER_NAME" \ |
|
"KeyName=$xarmkeyname" \ |
|
"KubernetesVersion=1.14" \ |
|
"NodeAutoScalingGroupDesiredCapacity=$XARM_NODES_INITIAL_NUM" \ |
|
"NodeGroupName=xarmdng" \ |
|
"NodeInstanceType=$XARM_NODES_TYPE" \ |
|
"Subnets=$PublicSubnets" \ |
|
"VpcId=$VPCId" |
|
|
|
NodeInstanceRole=$(aws cloudformation describe-stacks --stack-name eksctl-$XARM_CLUSTER_NAME-ng | jq -r '.Stacks[0].Outputs' | jq -c '.[] | select( .OutputKey == "NodeInstanceRole" )' | jq -r '.OutputValue') |
|
|
|
# join worker nodes to cluster |
|
echo Adding worker nodes to cluster |
|
curl -o aws-auth-cm.yaml https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2019-11-15/aws-auth-cm.yaml && \ |
|
sed "s|<ARN of instance role (not instance profile)>|$NodeInstanceRole|g" aws-auth-cm.yaml > aws-auth-cm-arm.yaml && \ |
|
kubectl apply -f aws-auth-cm-arm.yaml |
|
|
|
echo DONE |