For the complete documentation index, see llms.txt. This page is also available as Markdown.

Reducing AWS EKS get-token Calls Made by Kubectl

Introduction

This should be applied when there is a need to optimize the latency of kubectl calls to AWS EKS.

Prerequisites

AWS EKS deployment targetKubeconfig file configured to run aws eks get-token

Instructions

Create script

Create a script named aws-get-token.sh with the following content

#!/bin/bash -e
awsCluster=$1
region=$2
# 840 sec = 14 min <a href="#840-sec-14-min" id="840-sec-14-min"></a>
maxFileAge=840

if [[ -f /tmp/$awsCluster.token ]]; then
    # file age in seconds = current_time - file_modification_time.
    fileage=$(($(date +%s) - $(stat -c '%Y' "/tmp/$awsCluster.token")))
    if [[ $fileage > $maxFileAge ]]; then
        #echo "Getting token again ..."
        TOKEN=$(aws eks get-token --cluster-name $awsCluster --region $region)
        echo $TOKEN > /tmp/$awsCluster.token
    else
    	TOKEN=$( /tmp/$awsCluster.token
fi
echo -n $TOKEN

Create configMap in Spinnaker Namespace for Script aws-get-token.sh

Run the following command: kubectl -n $SPINNAKER_NAMESPACE create configmap aws-get-token --from-file aws-get-token.sh

Alter kubeconfig File

Alter kubeconfig file to make use of the aws-get-token.sh script created above. The kubeconfig file should look something like the following. Take note of the args and the command portion of this file.

Configure Spinnaker to Mount the Script

Configure Spinnaker to mount the script aws-get-token.sh as a configMap.

Using Halyard

In the service-settings/clouddriver.yml file add the following content:

Using Operator

Create a YAML file with the following content. Make sure to change `````` to match your CRD version

Configure initContainer for Clouddriver

Configure an initContainer for Clouddriver which will copy the script aws-get-token.sh from the read-only location to /home/spinnaker/bin and make it executable.

Halyard

In the ~/.hal/config file find the initContainers section and add the following:

Operator

Create a YAML file with the following content. Make sure to change `````` to match your CRD version

Redeploy Spinnaker

Redeploy Spinnaker with the changed configuration and new kubeconfig file

Last updated

Was this helpful?