-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_karpenter.sh
57 lines (47 loc) · 2.42 KB
/
setup_karpenter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
. utils.sh
orangeln "Setup Karpenter..."
println "This process is crucial for doing this workshop. If there is any failed step, you won't complete your workshop!!"
infoln "1. Setup ENV"
# Set ENV
export CLUSTER_ENDPOINT="$(aws eks describe-cluster --name "${CLUSTER_NAME}" --query "cluster.endpoint" --output text)"
export KARPENTER_IAM_ROLE_ARN="arn:${AWS_PARTITION}:iam::${AWS_ACCOUNT_ID}:role/${CLUSTER_NAME}-karpenter"
successln "Done!"
echo "export CLUSTER_ENDPOINT=$CLUSTER_ENDPOINT" >> "$HOME"/.bashrc
echo "export KARPENTER_IAM_ROLE_ARN=$KARPENTER_IAM_ROLE_ARN" >> "$HOME"/.bashrc
# Add Karpenter node role to aws-auth configmap
infoln "2. Add the Karpenter node role to the aws-auth configmap"
eksctl create iamidentitymapping \
--username system:node:{{EC2PrivateDNSName}} \
--cluster "${CLUSTER_NAME}" \
--arn "arn:aws:iam::${AWS_ACCOUNT_ID}:role/KarpenterNodeRole-${CLUSTER_NAME}" \
--group system:bootstrappers \
--group system:nodes
successln "Done!"
# Create KarpenterController IAM Role
infoln "3. Create KarpenterController IAM Role"
eksctl utils associate-iam-oidc-provider --cluster ${CLUSTER_NAME} --approve
eksctl create iamserviceaccount \
--cluster ${CLUSTER_NAME} --name karpenter --namespace ${KARPENTER_NAMESPACE} \
--role-name "${CLUSTER_NAME}-karpenter-service-account" \
--attach-policy-arn "arn:aws:iam::${AWS_ACCOUNT_ID}:policy/KarpenterControllerPolicy-${CLUSTER_NAME}" \
--role-only \
--approve
orangeln "Check IAM service account was created - $(eksctl get iamserviceaccount --cluster $CLUSTER_NAME --namespace $KARPENTER_NAMESPACE)"
successln "Done!"
# Create the EC2 Spot Service Linked Role
infoln "4. Create the EC2 Spot Service Linked Role"
aws iam create-service-linked-role --aws-service-name spot.amazonaws.com || true
successln "Done!"
# Use Helm to install Karpenter
infoln "5. Install Karpenter using Helm"
helm registry logout public.ecr.aws
helm upgrade --install karpenter oci://public.ecr.aws/karpenter/karpenter --version ${KARPENTER_VERSION_STR} --namespace ${KARPENTER_NAMESPACE} --create-namespace \
--set serviceAccount.annotations."eks\.amazonaws\.com/role-arn"=${KARPENTER_IAM_ROLE_ARN} \
--set settings.clusterName=${CLUSTER_NAME} \
--set settings.clusterEndpoint=${CLUSTER_ENDPOINT} \
--set settings.interruptionQueue=${CLUSTER_NAME} \
--set settings.featureGates.drift=true \
--set settings.featureGates.SpotToSpotConsolidation=true \
--wait
successln "Done!"