Created
November 12, 2019 14:52
-
-
Save RezhaBlue/3b6751bb7ac38ee01a94176a9255defd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo -e " | |
# \e[33mPrerequisites:\e[39m | |
# ~/.aws/config and ~/.aws/credentials setup for cwdevpf and cw accounts. | |
# KUBECONFIG is setup and stored in ~/.kube directory. | |
# | |
# \e[32mUsage:\e[39m | |
# Update PROFILE_DEV|PROD w/respective names from ~/.aws/credentials. | |
# Replace path at end of this script w/literal KUBECONFIG path, no variable. | |
# Source this script w/profile name mentioned above (e.g. source ./this_script.sh jdoe). | |
# | |
# \e[31mWARNING:\e[39m Will install \e[35mjq\e[39m pkg, used to parse JSON, to your machine. | |
" | |
PROFILE_DEVPF="devpf" # Modifiable | |
PROFILE_PROD="prod" # Modifiable | |
# If jq is not installed, install jq | |
#dpkg -l jq | grep -qw jq || curl -s 'https://api.github.com/users/lambda' | jq -r '.name' | |
# Set stack suffix based on profile | |
if [[ "$1" =~ ^($PROFILE_DEVPF|$PROFILE_PROD)$ ]]; then | |
export AWS_PROFILE=$1 | |
echo "AWS IAM Authenticator configured for [$AWS_PROFILE] using AWS_PROFILE env var." | |
# Get eks cluster info from aws, parse and store the endpoint and cert | |
EKS_JSON=$(aws eks describe-cluster --name pf-ekscluster-v1p12 --profile $AWS_PROFILE) | |
ENDPOINT=$(echo "$EKS_JSON" | jq -r '.cluster.endpoint') | |
CERT_AUTH=$(echo "$EKS_JSON" | jq -r '.cluster.certificateAuthority.data') | |
# Replace cluster api endpoint and cert data with account specific parts | |
sed -ri "s+(server: ).*+\1$ENDPOINT+; s+(certificate-authority-data: ).*+\1$CERT_AUTH+" ~/.kube/config-cluster.yml | |
echo "Config file updated. Start executing kubeclt commands." | |
else | |
echo -e "\e[31mUnrecognized profile name. Acceptable names are $PROFILE_DEVPF and $PROFILE_PROD." | |
return | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment