#!/bin/bash # Copyright 2020-2025 the Pinniped contributors. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 set -euo pipefail echo "Using Kubernetes version $KUBE_VERSION" cd deploy-eks-cluster-output # Set up our AWS service account in the AWS CLI. aws configure set credential_source Environment --profile service-account aws configure set role_arn "$AWS_ROLE_ARN" --profile service-account # Set some variables. CLUSTER_NAME="eks-$(openssl rand -hex 8)" ADMIN_USERNAME="$CLUSTER_NAME-admin" export CLUSTER_NAME export ADMIN_USERNAME export AWS_PAGER="" # prevent aws CLI hang with "WARNING: terminal is not fully functional" ADMIN_KUBECONFIG="admin-kubeconfig" SERVICE_ACCOUNT_NAME=test-admin-service-account SERVICE_ACCOUNT_NAMESPACE=default SECRET_NAME="${SERVICE_ACCOUNT_NAME}-secret" NEW_KUBECONFIG_FILE="metadata" NEW_CONTEXT=default NEW_KUBECONFIG_USER="admin-service-account" # The cluster name becomes the name of the lock in the pool. echo "$CLUSTER_NAME" > name # The kubeconfig file becomes the value of the lock in the pool. echo "Creating $CLUSTER_NAME in $AWS_DEFAULT_REGION..." # Note that the AWS account being used to run this command needs to have certain permissions. # See https://eksctl.io/usage/minimum-iam-policies/ for permissions. # See https://eksctl.io/usage/schema/ for documentation of this yaml. cat < ${NEW_KUBECONFIG_FILE}.minified mv ${NEW_KUBECONFIG_FILE}.minified ${NEW_KUBECONFIG_FILE} # Check that the new kubeconfig file works kubectl get namespaces --kubeconfig "${NEW_KUBECONFIG_FILE}" # Set the permissions on the file. chmod 0644 "${NEW_KUBECONFIG_FILE}"