#!/bin/bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 CWD=$(pwd) echo "Installing kubectl" curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl # set kubectl as executable, move to path, populate kubectl bash-completion chmod +x kubectl && sudo mv kubectl /usr/local/bin/ echo "source <(kubectl completion bash)" >> ~/.bashrc echo "Installing Node and CDK" nvm install 16 2> 0 nvm use 16 npm install -g yarn # Update awscli v1, just in case it's required pip install --user --upgrade awscli # Install awscli v2 curl -O "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" unzip -o awscli-exe-linux-x86_64.zip sudo ./aws/install rm awscli-exe-linux-x86_64.zip echo "Installing helper tools" sudo yum -y install jq gettext bash-completion moreutils # Install yq (yaml query) echo 'yq() { docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" }' | tee -a ~/.bashrc && source ~/.bashrc # Install eksctl and move to path curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin echo Resizing Cloud9 instance EBS Volume sh scripts/resize-cloud9-ebs-vol.sh 40 echo "Installing helm" curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash echo "Set Environment Variables" # Set AWS region in env and awscli config AWS_REGION=$(curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region) echo "export AWS_REGION=${AWS_REGION}" | tee -a ~/.bash_profile cat << EOF > ~/.aws/config [default] region = ${AWS_REGION} output = json EOF echo Set accountID ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account) echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile echo Set EKS cluster name EKS_CLUSTER_NAME=$(aws eks list-clusters --region ${AWS_REGION} --query clusters --output text) echo "export EKS_CLUSTER_NAME=${EKS_CLUSTER_NAME}" | tee -a ~/.bash_profile echo "export CLUSTER_NAME=${EKS_CLUSTER_NAME}" | tee -a ~/.bash_profile echo Update kubeconfig and set cluster-related variables if an EKS cluster exists if [[ "${EKS_CLUSTER_NAME}" != "" ]] then echo Update kube config aws eks update-kubeconfig --name ${EKS_CLUSTER_NAME} echo Set EKS node group name EKS_NODEGROUP=$(aws eks list-nodegroups --cluster ${EKS_CLUSTER_NAME} | jq -r '.nodegroups[0]') echo "export EKS_NODEGROUP=${EKS_NODEGROUP}" | tee -a ~/.bash_profile echo Set EKS node group stack name STACK_NAME=$(aws eks describe-nodegroup --cluster-name $EKS_CLUSTER_NAME --nodegroup-name ${EKS_NODEGROUP} | jq -r '.nodegroup.tags."aws:cloudformation:stack-name"') echo "export STACK_NAME=${STACK_NAME}" | tee -a ~/.bash_profile echo Set EKS nodegroup worker node instance profile ROLE_NAME=$(aws cloudformation describe-stack-resources --stack-name $STACK_NAME | jq -r '.StackResources[] | select(.ResourceType=="AWS::IAM::Role") | .PhysicalResourceId') echo "export ROLE_NAME=${ROLE_NAME}" | tee -a ~/.bash_profile elif [[ "${EKS_CLUSTER_NAME}" = "" ]] then echo "No EKS clusters provisioned in region: ${AWS_REGION}" fi if [[ "${ROLE_NAME}" = "" ]] then echo "Please set an EC2 instance profile for your worker nodes in the ${EKS_CLUSTER_NAME} cluster" fi # Update aws-auth ConfigMap granting cluster-admin to TeamRole (since the cluster is created by eksworkshop-admin) eksctl create iamidentitymapping \ --cluster eksworkshop-eksctl \ --arn arn:aws:iam::${ACCOUNT_ID}:role/TeamRole \ --username cluster-admin \ --group system:masters