简体   繁体   English

初始化容器的 Kubectl 等待命令

[英]Kubectl wait command for init containers

I am looking for a Kubectl wait command for init containers.我正在为 init 容器寻找 Kubectl 等待命令。 Basically I need to wait until pod initialization of init container before proceeding for next step in my script.基本上我需要等到 init 容器的 pod 初始化,然后再继续我的脚本中的下一步。

I can see a wait option for pods but not specific to init containers.我可以看到 pod 的等待选项,但不特定于 init 容器。

Any clue how to achieve this任何线索如何实现这一目标

Please suggest any alternative ways to wait in script请建议在脚本中等待的任何替代方法

You can run multiple commands in the init container or multiple init containers to do the trick.您可以在 init 容器或多个 init 容器中运行多个命令来完成此操作。


  • Multiple commands多个命令
command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]

Refer: https://stackoverflow.com/a/33888424/3514300参考: https://stackoverflow.com/a/33888424/3514300


* Multiple init containers * 多个初始化容器

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"]

Refer: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use参考: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM