首页 文章

在Helm中的升级前挂钩内传递参数

提问于
浏览
0

我的Helm图表中有一个预升级钩子,如下所示:

apiVersion: batch/v1
kind: Job
metadata:
  name: "{{.Release.Name}}-preupgrade"
  labels:
    heritage: {{.Release.Service | quote }}
    release: {{.Release.Name | quote }}
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": pre-upgrade
    "helm.sh/hook-weight": "0"
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  template:
    metadata:
      name: "{{.Release.Name}}"
      labels:
        heritage: {{.Release.Service | quote }}
        release: {{.Release.Name | quote }}
        chart: "{{.Chart.Name}}-{{.Chart.Version}}"
    spec:
      restartPolicy: Never
      securityContext:
#       Because we are running as non root user and group id/User id of the flink user is 1000/1000.
        fsGroup: {{ .Values.spec.securityContext.fsGroup }}
        runAsNonRoot: {{ .Values.spec.securityContext.runAsNonRootFlag }}
        runAsUser: {{ .Values.spec.securityContext.runAsUser }}
      containers:
      - name: pre-upgrade-job
        image: {{ .Values.registry }}/{{ .Values.imageRepo }}:{{ .Values.imageTag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
# Got error /bin/sleep: invalid time interval 'lcm_hook'
        args:
        - lcm_hook
        env:
#       Need to add this env variable so that the custom flink conf values will be written to $FLINK_HOME/conf.
#       This is needed for the hook scripts to connect to the Flink JobManager
        - name: FLINK_KUBE_CONFIGMAP_PATH
          value: {{ .Values.spec.config.mountPath }}
        volumeMounts:
        - name: {{ template "fullname" . }}-flink-config
          mountPath: {{ .Values.spec.config.mountPath }}
        - mountPath: {{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}
          name: shared-pvc
        command: ["/bin/sh", "-c", "scripts/preUpgradeScript.sh","{{ .Values.pvc.shared_storage_path }}/{{ template "fullname" . }}"]
        command: ["/bin/sleep","10"]
      volumes:
        - name: {{ template "fullname" . }}-flink-config
          configMap:
            name: {{ template "fullname" . }}-flink-config
        - name: shared-pvc
          persistentVolumeClaim:
            claimName: {{ template "fullname" . }}-shared-pv-claim

在这里,我需要将一个名为“lcm_hooks”的参数传递给我的docker容器 . 但是当我这样做时,这个参数似乎覆盖了我的第二个命令[“/ bin / sleep”,“10”]的参数,我得到一个错误

/ bin / sleep:无效的时间间隔'lcm_hook'

在升级阶段 . 什么是确保我能够将一个参数传递给我的容器的正确方法,以及一个与helm hook中的bash命令完全不同的参数?

1 回答

  • 2

    我的docker容器,名为“lcm_hooks”

    你的钩子有一个容器,它不叫 lcm_hooks ,你叫它 pre-upgrade-job . 我之所以提到这一点,是因为您可能忘了包含一段代码,或者误解了它是如何工作的 .

    我需要将一个参数传递给我的docker容器

    您的yaml指定 commandargs ,因此图像的原始 entrypointcmd 将被完全忽略 . 如果你想"pass argument to container",你应该从yaml中省略 command 并仅覆盖 args .

    第二个命令

    您的容器规范确实指定了两个命令,这意味着只有后者才会执行 . 如果你想要同时执行它们,你应该链接它们 .

    确保我能够将一个参数传递给我的容器的正确方法是什么,并且在helm hook中将一个完全不同的参数传递给我的bash命令

    您使用Helm将挂钩容器与要部署的实际容器分开 .

    我建议您查看容器规范和Helm挂钩文档,这可能会澄清一些事情:

相关问题