我有一个用于pod定义的YAML文件。希望使用启动脚本启动应用程序。当我深入到pod应用程序时,还没有启动。这意味着启动脚本没有被执行。当执行YAML文件时,我希望它执行脚本文件来启动When服务器。因此,当我进入吊舱时,我的应用程序web服务器正在运行。实际上,我的应用程序是这样的,当我安装rpm时,它会自动在home/文件夹中创建启动脚本。因此,当我进入容器时,im in / dir。我只需要转到/home并执行start脚本。YAML文件的一部分如下:
apiVersion: v1
kind: Pod
metadata:
name: app-pod6
labels:
name: app-pod
app: containerization
spec:
containers:
- name: appimage1
image: appimage6:1.0
command: ["/bin/sh"]
args: ["-c", "cd home/ && ./start.sh"]
ports:
- containerPort: 8000应用程序文件
FROM amazoncorretto:8
WORKDIR /
ADD app.rpm .
ADD start.sh .
RUN rpm -ivh app.rpm && bash
RUN chmod +x start.sh
EXPOSE 8000发布于 2021-11-08 04:52:50
无法在YAML配置的参数中运行shell脚本。
您应该使用多个命令行选项,类似于
command:
- /bin/sh
- -c
- >
i=0;
while [ $i -lt 100 ];
do
echo "hello $i";
echo "$i : $(date)" >> /var/mylog/1.log;
echo "$(date)" >> /var/mylog/2.log;
i=$((i+1));
sleep 1;
done如果你想运行他的多个命令,你可以试试。
这样您就可以像前面提到的那样打开bash并运行shell脚本。
command:
- /bin/sh
- -c
- >
./start.sh;
tail -f /dev/null另一个例子
containers:
- command:
- /bin/sh
- -c
- |
echo "running below scripts"
echo "command 2"更新
运行shell脚本的示例
在Kubernetes中使用这个
containers:
- image: busybox
command: ["/bin/sh"]
args: ["-c", "cd home/ && ./test.sh && mkdir new/ && other commands"]
name: busyboxhttps://stackoverflow.com/questions/69878689
复制相似问题