是否可以在Kubernetes中为部署定义在创建部署后立即执行的命令?
例如:
cd opt/
wget xxxxxx
mkdir new/
到目前为止,我还没有找到解决该问题的任何方法。
还有其他方法可以达到这种效果吗?
答案 0 :(得分:1)
可以这样做:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: example
name: example
spec:
replicas: 1
selector:
matchLabels:
app: example
strategy: {}
template:
metadata:
labels:
app: example
spec:
containers:
- image: busybox
command: ["/bin/sh"]
args: ["-c", "cd opt/ && wget xxxxxx && mkdir new/ && process-that-keeps-container-running"]
name: busybox
这有点棘手,因为在命令参数末尾,您将必须放置使容器保持运行的命令。如果您不知道这是哪一个,则必须查看正在使用的Docker映像的CMD
和ENTRYPOINT
。