【问题标题】:helm hook post-install shell script executionhelm hook 安装后 shell 脚本执行
【发布时间】:2020-10-21 19:45:57
【问题描述】:

我正在尝试设置 helm“安装后”挂钩并看到以下错误。 错误: sh:脚本/jenkins.sh:未找到

postinstall.yaml 内容

apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Release.Name }}"
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-5"
spec:
  template:
    spec:
      containers:
      - name: post-install-jenkins-job
        image: alpine:3.3
        imagePullPolicy: IfNotPresent
        command: [ "/bin/sh", "-c", "scripts/jenkins.sh"]
      restartPolicy: Never
      terminationGracePeriodSeconds: 0

helm包的文件夹结构 scripts/jenkins.h 是我尝试使用“postinstall.yaml”作为安装后 helm hook 执行的脚本。

riq-agent
├── Chart.yaml
├── README.md
├── scripts
│   └── jenkins.sh
├── templates
│   ├── NOTES.txt
│   ├── Untitled-1.yml
│   ├── _helpers.tpl
│   ├── awssecret.yaml
│   ├── clusterrolebinding.yaml
│   ├── configurationFiles-configmap.yaml
│   ├── deployment.yaml
│   ├── hook-aws-ecr.yaml
│   ├── initializationFiles-configmap.yaml
│   ├── postinstall.yaml
│   ├── pvc.yaml
│   ├── secrets.yaml
│   ├── serviceaccount.yaml
│   ├── servicemonitor.yaml
│   ├── svc.yaml
│   └── tests
│       ├── test-configmap.yaml
│       └── test.yaml
└── values.yaml

我尝试在 helm hook 中执行 shell 脚本(存储在 helm 包中)的方式是否有任何错误?

【问题讨论】:

    标签: sh hook kubernetes-helm


    【解决方案1】:

    为了被执行,scripts/jenkins.sh 应该是post-install-jenkins-job 容器的一部分,作为卷安装。你可以populate a volume with data stored in a configmap

    postinstall-configmap.yaml

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{ .Release.Name }}-postinstall-configmap
    data:
      jenkins.sh: |-
    {{ .Files.Get "scripts/jenkins.sh" | indent 4}}
    

    postinstall.yaml

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: "{{ .Release.Name }}"
      annotations:
        "helm.sh/hook": post-install
        "helm.sh/hook-weight": "-5"
    spec:
      template:
        spec:
          containers:
          - name: post-install-jenkins-job
            image: alpine:3.3
            imagePullPolicy: IfNotPresent
            command: [ "/bin/sh", "-c", "/opt/scripts/jenkins.sh"]
            volumeMounts:
              - name: config-volume
                mountPath: /opt/scripts
          volumes:
            - name: config-volume
              configMap:
                name: {{ .Release.Name }}-postinstall-configmap
                defaultMode: 0777
          restartPolicy: Never
          terminationGracePeriodSeconds: 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2022-07-28
      • 2021-10-22
      相关资源
      最近更新 更多