amazon-ekseksctl

How to parameterize the config file for eksctl?


I have the following config file (edited for brevity):

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: FOO-CLUSTER
  region: eu-central-1

nodeGroups:
  - name: FOO-CLUSTER-group-1
    [..]
  - name: FOO-CLUSTER-group-2
    [..]

that will be used to create clusters with eksctl create cluster -f config.yml.

I would like to avoid hard-coding the cluster name (i.e. FOO-CLUSTER in this case) and extract it to a parameter (e.g. environment variable or additional file or CLI argument), so that I can later use the same file to create BAR-CLUSTER, FEE-CLUSTER and more.

Is it possible?


Solution

  • I don't think this is possible. However what you could do is you could use that file as a template and sed it before running the command. For kubectl apply I have used this technique and it worked fine. You can even use variables. For example:

    template=`curl -sS https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/alb-ingress-controller.yaml | sed -e "s/# - --cluster-name=devCluster/- --cluster-name=$CLUSTER_NAME/g" -e "s/# - --aws-vpc-id=vpc-xxxxxx/- --aws-vpc-id=$VPC_ID/g" -e "s/# - --aws-region=us-west-1/- --aws-region=$AWS_REGION/g"` 
    echo "$template" | kubectl apply -f -
    

    I have never used this with eksctl but I see no reasons why it shouldn't work.


    In a similar manner, you can use envsubst.

    apiVersion: eksctl.io/v1alpha5
    kind: ClusterConfig
    
    metadata:
      name: ${CLUSTER_NAME}
      region: eu-central-1
    
    nodeGroups:
      - name: ${CLUSTER_NAME}-group-1
        [..]
      - name: ${CLUSTER_NAME}-group-2
        [..]
    
    export CLUSTER_NAME=foo
    
    cat cluster-config.yml | envsubst '${CLUSTER_NAME}' > cluster-config-foo.yml