# reset yum history sudo yum history new # Install jq (json query) sudo yum -y -q install jq # Install yq (yaml query) echo 'yq() { docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" }' | tee -a ~/.bashrc && source ~/.bashrc # Install other utils: sudo yum -y install gettext bash-completion moreutils # Update awscli 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 # Install kubectl # enable desired version by uncommenting the desired version below: # kubectl version 1.17 # curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.12/2020-11-02/bin/linux/amd64/kubectl # kubectl version 1.18 curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl # kubectl version 1.19 # curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/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 # 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 # Install helm curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash ##################### ## Set 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 # Set accountID ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account) echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile # 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 # Update kubeconfig and set cluster-related variables if an EKS cluster exists if [[ "${EKS_CLUSTER_NAME}" != "" ]] then # Update kube config aws eks update-kubeconfig --name ${EKS_CLUSTER_NAME} # 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 # 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 # 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 # Print a message if there's no EKS cluster echo "There are no EKS clusters provisioned in region: ${AWS_REGION}" fi # Print a message if there's no worker node instance profile set 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