删除临时吊舱的问题

时间:2019-08-10 00:19:57

标签: kubernetes openshift redhat kubernetes-helm

我正在尝试使用头盔删除功能删除临时吊舱和其他工件。我正在尝试运行此头盔删除以按计划运行。这是我有效的独立命令

helm delete --purge $(helm ls -a -q temppods.*)

但是,如果我尝试按以下时间表进行操作,则会遇到问题。

这是mycron.yaml的样子:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cronbox
  namespace: mynamespace
spec:
  serviceAccount: cron-z
  successfulJobsHistoryLimit: 1
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cronbox
            image: alpine/helm:2.9.1
            args: ["delete", "--purge", "$(helm ls -a -q temppods.*)"
            env:
            - name: TILLER_NAMESPACE
              value: mynamespace-build
            - name: KUBECONFIG
              value: /kube/config
            volumeMounts:
            - mountPath: /kube
              name: kubeconfig
          restartPolicy: OnFailure
          volumes:
          - name: kubeconfig
            configMap:
              name: cronjob-kubeconfig

我跑了

oc create -f ./mycron.yaml

这创建了cronjob

每隔5分钟就会创建一个Pod,并运行cron作业中的helm命令。

我希望删除以temppods *开头的工件/容器名称。

我在吊舱日志中看到的是:

Error: invalid release name, must match regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])+$ and the length must not longer than 53

1 个答案:

答案 0 :(得分:1)

CronJob容器规范正在尝试删除名为(字面意义)的发行版:

$(helm ls -a -q temppods.*)

该版本不存在,并且未能满足helm的预期命名约定。

为什么

alpine/helm:2.9.1容器映像的entrypointhelm。这意味着所有参数都将通过exec直接传递到helm二进制文件。由于没有外壳运行,因此不会发生外壳扩展($())。

修复

要执行预期的操作,可以使用sh(在高山图像中可用)。

sh -uexc 'releases=$(helm ls -a -q temppods.*); helm delete --purge $releases'

在Pod规范中,它翻译为:

spec:
  containers:
  - name: cronbox
    command: 'sh'
    args:
    - '-uexc'
    - 'releases=$(helm ls -a -q temppods.*); helm delete --purge $releases;'

头盔

请注意,当集群或版本进入模糊状态时,掌舵并不是最可靠的工具。在同一版本中同时运行多个与之交互的头盔命令通常会带来灾难,这看起来很可能是灾难。也许有其他方式实现您正在实施的过程的问题吗?