Last active
December 20, 2022 16:56
-
-
Save dooferlad/5a7ec14023f2975b8673afe8582230b4 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
#!/usr/bin/env bash | |
set -e | |
if [ "$#" -lt 1 ] | |
then | |
echo "Usage: update-kubeconfig <aws profile> [cluster-name]" | |
exit 1 | |
fi | |
export AWS_PROFILE=$1 | |
if [ "$#" -eq 2 ] | |
then | |
CLUSTER_NAME=$2 | |
else | |
CLUSTERS=$(aws eks list-clusters --output json | jq .clusters[] -r) | |
NUM_CLUSTERS=$(echo "$CLUSTERS" | grep -c '^') | |
if [ $NUM_CLUSTERS -ne 1 ] | |
then | |
echo "Found more than one Kubernetes cluster. Please re-run with an explicit cluster name." | |
echo "Clusters:" | |
echo "$CLUSTERS" | |
exit 1 | |
fi | |
CLUSTER_NAME=$CLUSTERS | |
fi | |
aws eks update-kubeconfig --name $CLUSTER_NAME --alias $AWS_PROFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment