Verified Commit c94784ed authored by Xueshan Feng's avatar Xueshan Feng
Browse files

no longer needed.

parent 6fe088fa
Loading
Loading
Loading
Loading

config-aws-kube.sh

deleted100755 → 0
+0 −49
Original line number Diff line number Diff line
#!/bin/bash

###############################################################################
# Configure kubeconfig for EKS
###############################################################################

# Prerequsite: AWS EKS model, AWS kubectl binary installed in $HOME/bin

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# include functions
source $THIS_DIR/utils/functions.sh
source env.sh > /dev/null 2>&1 || true # Optional 

set -u # Must set these vars
export CLUSTER_NAME=${CLUSTER_NAME}
export AWS_PROFILE=${AWS_PROFILE}
export KUBECONFIG=${HOME}/.kube/${CLUSTER_NAME}
debug_scripts=false

# fail on error or undeclared vars
trap_errors

set +u

kubectx aws

exit 0

# Cleanup previous kubeconfig entries
kubectl config unset users.aws
kubectl config unset clusters.${CLUSTER_NAME}
kubectl config delete-context default-context &> /dev/null || true

# Merge new cluster kubeconfig
MASTER_ENDPOINT=$(aws eks describe-cluster --cluster-name ${CLUSTER_NAME} --output text --query cluster.masterEndpoint)
aws eks describe-cluster --output text --cluster-name ${CLUSTER_NAME} --query cluster.certificateAuthority.data | \
  base64 -D | tee /tmp/ca.crt

# Verify cert
if ! openssl x509  -text -noout -in /tmp/ca.crt &> /dev/null ; then
  abort 1 "Error validating /tmp/ca.crt file."
fi
kubectl config set-cluster ${CLUSTER_NAME} --server=${MASTER_ENDPOINT} --certificate-authority=/tmp/ca.crt --embed-certs=true
kubectl config set-credentials aws --auth-provider=aws --auth-provider-arg=cluster-id=${CLUSTER_NAME}
kubectl config set-context ${CLUSTER_NAME} --cluster=${CLUSTER_NAME} --user=aws
kubectl config use-context ${CLUSTER_NAME}
kubectl config current-context
export AWS_PROFILE=${AWS_PROFILE}