![](/img/trans.png)
[英]How to keep a Kubernetes pod running when main process is not blocking?
[英]How to keep a process running throughout pod lifecycle?
在这种情况下,使用shareProcessNamespace: true
会有所帮助。 我们只需要通过 init 容器在后台启动一个子进程。
这是一个例子
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: demo
name: demo
spec:
shareProcessNamespace: true
initContainers:
- name: iapp
image: nicolaka/netshoot:latest
command:
- "bash"
args:
- "-c"
- "tail -f /dev/null & echo iapp"
containers:
- name: app
image: nicolaka/netshoot:latest
command:
- "sleep"
args:
- "inifinity"
pod 运行后,当我们 exec 进入app
容器时,执行ps aux
。 我们可以看到tail -f /dev/null
仍然存在。 这证实了我们可以在整个 pod 生命周期中运行一个进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.