我有以下配置文件(为简洁而编辑):
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
[..]它将用于使用eksctl create cluster -f config.yml创建集群。
我希望避免对集群名称进行硬编码(在本例中为FOO-CLUSTER ),并将其提取到参数中(例如,环境变量或附加文件或CLI参数),以便以后可以使用相同的文件创建BAR-CLUSTER、FEE-CLUSTER等。
有可能吗?
发布于 2021-07-22 08:33:08
我觉得这不可能。但是,您可以使用该文件作为模板,并在运行该命令之前对其进行sed。对于kubectl apply,我使用了这一技术,它运行得很好。你甚至可以使用变量。例如:
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 -我从来没有在eksctl中使用过这个,但是我没有理由认为它不应该工作。
以类似的方式,您可以使用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.ymlhttps://stackoverflow.com/questions/68470318
复制相似问题