使用 Helm 图表在部署清单中序列化创建 Pods
Serialize creation of Pods in a deployment manifest using Helm charts
所以我有一个部署 pod 的 helm chart,所以下一个任务是在第一个 pod 是 运行 后创建另一个 pod。
所以我在 chart/templates 中创建了一个简单的 pod.yaml,它创建了一个简单的 pod-b,所以下一步只在 pod-a 之后创建 pod-b 是 运行。
所以只是在 helm hooks 但不认为他们关心 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
任何建议都很好。
如果你想要你的 post-install/post-upgrade
chart hooks to work, you should add readiness probes to your first pod and use --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"
所以我有一个部署 pod 的 helm chart,所以下一个任务是在第一个 pod 是 运行 后创建另一个 pod。
所以我在 chart/templates 中创建了一个简单的 pod.yaml,它创建了一个简单的 pod-b,所以下一步只在 pod-a 之后创建 pod-b 是 运行。
所以只是在 helm hooks 但不认为他们关心 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
任何建议都很好。
如果你想要你的 post-install/post-upgrade
chart hooks to work, you should add readiness probes to your first pod and use --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"