【问题标题】:Is it possible to turn off the VM´s hosting the google-cloud-composer at certain hours?是否可以在特定时间关闭托管 google-cloud-composer 的虚拟机?
【发布时间】:2018-10-31 06:52:58
【问题描述】:

为了减少与运行 google-cloud-composer 相关的费用,我想知道在特定时间关闭运行虚拟环境的 VM 实例的可能性。例如:我们的大多数 DAG 都在早上或下午运行,因此我们希望在夜间关闭 VM,如果可能的话甚至在中午关闭。我知道我们可以从 Google 云控制台手动禁用环境,但如果能找到一种自动执行此操作的方法,那就太好了

谢谢!

【问题讨论】:

  • 欢迎来到 Stack Overflow!为了给您一个很好的答案,如果您还没有看过How to Ask,它可能会对我们有所帮助。如果您可以提供minimal reproducible example,它可能也很有用。

标签: airflow google-cloud-composer


【解决方案1】:

很遗憾,无法使用 Google Cloud Platform 以编程方式进行配置。为此,您最好的选择是让脚本作为 cronjob 从另一台主机运行,该主机将在 Composer 环境不使用时打开或关闭它。

【讨论】:

  • @Patrick W:我希望这样做,但找不到合适的 API/文档来打开/关闭整个 Composer 环境。你能指点一下正确的方向吗
  • @dkapitan this 是 Cloud Composer API 的文档
【解决方案2】:

我们已经并行设置了一个小型 k8s 集群,并使用 CronJob 部署来管理将池节点缩小到 0,然后再使用第二个 cronjob 将其恢复。

部署是这样的(向上和向下更改节点数)。您可以将操作更改为处理虚拟机的方式(是否通过控制台中的计算暂停实例?)

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 机密。

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多