为了减少与运行google-cloud-composer相关的费用,我想知道是否可以在特定时间关闭运行Virtual Environment的VM实例。例如:我们的大多数DAG要么在上午运行,要么在下午运行,所以我们希望在晚上关闭虚拟机,如果可能的话,甚至在中午关闭。我知道我们可以从Google云控制台手动禁用环境,但如果能找到一种自动执行此操作的方法,那就太好了
谢谢!
发布于 2018-10-22 22:04:52
不幸的是,没有办法使用Google Cloud平台以编程方式对其进行配置。您最好的选择是让脚本作为cronjob从另一个主机运行,该主机将在Composer环境不使用时打开或关闭该环境。
发布于 2018-10-31 06:52:58
我们并行设置了一个微型k8s集群,并使用CronJob部署来管理将池节点缩减到0,然后使用第二个cronjob将其恢复。
部署是这样的(更改向上和向下的节点数)。您可以将操作更改为处理VM的方式(是否通过控制台中的Compute暂停实例?)
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: disable-composer
spec:
schedule: "0 10 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: enable-composer
image: google/cloud-sdk:latest
volumeMounts:
- name: google-app-credentials-volume
mountPath: /etc/gcp
readOnly: true
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/gcp/credentials.json
args:
- /bin/bash
- -c
- gcloud auth activate-service-account service-account@gcp-project.iam.gserviceaccount.com --key-file=$GOOGLE_APPLICATION_CREDENTIALS; COMPOSER_ENV=composer-environment-name; COMPOSER_LOCATION=us-central1; COMPOSER_CLUSTER=`gcloud composer environments describe $COMPOSER_ENV --format="csv[no-heading](config.gkeCluster)" --location $COMPOSER_LOCATION | cut -d '/' -f 6`; COMPOSER_ZONE=`gcloud composer environments describe $COMPOSER_ENV --format="csv[no-heading](config.nodeConfig.location)" --location $COMPOSER_LOCATION | cut -d '/' -f 4`; gcloud container clusters resize $COMPOSER_CLUSTER --zone $COMPOSER_ZONE --size=0 --quiet;
restartPolicy: OnFailure
volumes:
- name: google-app-credentials-volume
secret:
secretName: google-app-credentials
items:
- key: credentials.json
path: credentials.json
其中google-app-credentials是包含我们的服务帐户密钥文件的kubernetes密钥。
https://stackoverflow.com/questions/52929615
复制相似问题