【发布时间】:2019-12-17 16:30:27
【问题描述】:
我正在尝试使用 helm delete 删除临时 pod 和其他工件。我正在尝试运行此 helm delete 以按计划运行。这是我的独立命令,有效
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* 开头的工件/pod 名称。
我在 pod 的日志中看到的是:
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
【问题讨论】:
-
你确定不需要 sh -c 吗?您正在使用 shell 语法。
-
扩展@coderanger 所说的内容,使您的命令类似于
["/bin/sh"]和您的参数["-c", "helm delete --purge $(helm ls -a -q temppods.*)"]。它在本地工作,因为您在 shell 中运行,但在您的 cron 作业中,"$(helm ls -a -q temppods.*)"被逐字作为helm命令的 RELEASE 参数传递,并且 shell 并没有按照您认为的方式扩展.
标签: kubernetes openshift redhat kubernetes-helm