【发布时间】:2020-05-14 03:22:20
【问题描述】:
我正在寻找用于初始化容器的 Kubectl 等待命令。基本上我需要等到 init 容器的 pod 初始化,然后再继续我的脚本中的下一步。
我可以看到 pod 的等待选项,但不是特定于 init 容器。
任何线索如何实现这一点
请建议任何其他在脚本中等待的方法
【问题讨论】:
标签: kubernetes containers
我正在寻找用于初始化容器的 Kubectl 等待命令。基本上我需要等到 init 容器的 pod 初始化,然后再继续我的脚本中的下一步。
我可以看到 pod 的等待选项,但不是特定于 init 容器。
任何线索如何实现这一点
请建议任何其他在脚本中等待的方法
【问题讨论】:
标签: kubernetes containers
您可以在 init 容器或多个 init 容器中运行多个命令来达到目的。
command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]
参考:https://stackoverflow.com/a/33888424/3514300
* 多个初始化容器
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
参考:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use
【讨论】: