【问题标题】:Serialize creation of Pods in a deployment manifest using Helm charts使用 Helm 图表在部署清单中序列化 Pod 的创建
【发布时间】:2020-05-27 14:58:14
【问题描述】:

所以我有一个部署 pod 的 helm chart,所以下一个任务是在第一个 pod 运行后创建另一个 pod。

所以我在 chart/templates 中创建了一个简单的 pod.yaml,它创建了一个简单的 pod-b,所以下一步只在 pod-a 运行后创建 pod-b。

所以只是掌舵钩子,但不认为他们关心 pod 状态。

另一个想法是使用下面这样的 Init 容器,但不确定如何编写命令来查找正在运行的 pod?

spec:
  containers:
  - name: myapp-container
    image: busybox
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']

另一个想法是一个简单的脚本来检查 pod 状态,例如:

y=`kubectl get po -l app=am -o 'jsonpath={.items[0].status.phase}'`
   while [ $i -le 5 ]
   do
    if [[ "$y" == "Running" ]]; then
      break
    fi
    sleep 5
   done

任何建议都会很棒。

【问题讨论】:

    标签: bash kubernetes-helm kubectl helmfile


    【解决方案1】:

    如果您希望您的 post-install/post-upgrade chart hooks 正常工作,您应该将 readiness probes 添加到您的第一个 pod 并使用 --wait 标志。

    helm upgrade --install -n test --wait mychart .

    pod.yaml

    apiVersion: v1
    kind: Pod
    metadata:
      name: readiness-exec
      labels:
        test: readiness
    spec:
      containers:
      - name: readiness
        image: k8s.gcr.io/busybox
        args:
        - /bin/sh
        - -c
        - sleep 30; touch /tmp/healthy; sleep 600
        readinessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 10
          periodSeconds: 5
          failureThreshold: 10
    

    hook.yaml

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: "post-deploy"
      annotations:
        "helm.sh/hook": post-upgrade,post-install
        "helm.sh/hook-delete-policy": before-hook-creation
    spec:
      backoffLimit: 1
      template:
        metadata:
          name: "post-deploy"
        spec:
          restartPolicy: Never
          containers:
            - name: post-deploy
              image: k8s.gcr.io/busybox
              args:
              - /bin/sh
              - -c
              - echo "executed only after previous pod is ready"
    

    【讨论】:

    • 谢谢,我上次玩 helm hooks 时缺少 --wait 标志。
    • @daverocks ,所以最好接受 edbighead 的回答 :)
    猜你喜欢
    • 1970-01-01
    • 2019-09-16
    • 2020-03-19
    • 2018-12-04
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2021-05-13
    • 2022-11-09
    相关资源
    最近更新 更多