简体   繁体   English

通过 ansible 部署 Openshift 计划

[英]Openshift schedule deployment via ansible

I have multiple openshift application deployment configured to be deployed by ansible (triggered by Jenkins).我有多个 openshift 应用程序部署配置为由 ansible(由 Jenkins 触发)部署。 Some of the applications need to be scaled down to cut costs.一些应用程序需要按比例缩小以降低成本。

Is it possible to adapt the deployment helm chart to scale down and scale up according to a schedule?是否可以根据计划调整部署掌舵图以缩小和扩大规模? Can openshift scheduler be used for this?可以为此使用 openshift 调度程序吗?

Would scaling up and down be equivalent to completely deleting the deployment and associated PV and charts?扩大和缩小是否等同于完全删除部署和关联的 PV 和图表?

Right now a Jenkins job is scheduled to delete and then recreate the deployment.现在,计划删除 Jenkins 作业,然后重新创建部署。 But it makes every application to have the same downtime which is not the desired result.但它使每个应用程序都有相同的停机时间,这不是预期的结果。 I do not want to write a Jenkinspipeline for each and every application.我不想为每个应用程序编写一个 Jenkins 管道。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test
  namespace: vini-test
spec:
  schedule: "*/2 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: partner-db
              image: some-image
              command:
              - /bin/sh
              - -c
              - date; echo $date > /tmp/cronjob.log
              - mkdir -p /tmp/openshift && cd /tmp/openshift && curl -L https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz -o openshiftstuff.tar.gz && tar -xf openshiftstuff.tar.gz && mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc /usr/bin -f && mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/kubectl /usr/bin -f
              - oc get pods -n vini-test
              - oc scale deployment partner-db --replicas=0
          restartPolicy: OnFailure

Is it possible to adapt the deployment helm chart to scale down and scale up according to a schedule?是否可以根据计划调整部署掌舵图以缩小和扩大规模? Can openshift scheduler be used for this?可以为此使用 openshift 调度程序吗?

Helm is used to deploy applications, so I do not think you can use this to scale the application during runtime, but I might be wrong. Helm 用于部署应用程序,因此我认为您不能在运行时使用它来扩展应用程序,但我可能错了。

What you can always do is to deploy an additional CronJob that will use oc scale or a similar command to do the scaling on a regular basis.您始终可以做的是部署一个额外的CronJob ,它将使用oc scale或类似的命令定期进行缩放。 This can also be done in a single Jenkins Pipeline that will loop over the necessary projects dynamically and scale them down (maybe only do this for projects with a certain label?).这也可以在单个 Jenkins 管道中完成,该管道将动态循环必要的项目并缩小它们(也许只对具有特定 label 的项目执行此操作?)。

Would scaling up and down be equivalent to completely deleting the deployment and associated PV and charts?扩大和缩小是否等同于完全删除部署和关联的 PV 和图表?

Scaling using oc scale / kubectl scale works by setting the replicas in the Deployment spec to another value, thus adding or removing Pods, not by deleting Deployments or something like that.使用oc scale / kubectl scale通过将Deployment spec中的replicas设置为另一个值来进行扩展,从而添加或删除 Pod,而不是通过删除 Deployment 或类似的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM