Skip to content

Instantly share code, notes, and snippets.

@dooferlad
Last active December 20, 2022 16:56
Show Gist options
  • Save dooferlad/5a7ec14023f2975b8673afe8582230b4 to your computer and use it in GitHub Desktop.
Save dooferlad/5a7ec14023f2975b8673afe8582230b4 to your computer and use it in GitHub Desktop.
#!/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