[英]How do I login into a Docker container running inside the specific Kubernetes pod and run an test.sh file?
I have a test.sh file which need to be run in an docker container which runs inside the Kubernetes pods via Jenkins job. 我有一个test.sh文件,该文件需要在通过Jenkins作业在Kubernetes容器内运行的Docker容器中运行。
Flow: 流:
Step1 : Run a Jenkins job which should login to a docker container running inside the pods 步骤1:运行一个Jenkins作业,该作业应登录到在Pod内运行的Docker容器
Step: From the container execute the test.sh script. 步骤:从容器中执行test.sh脚本。
test.sh test.sh
echo "This is demo file" 回声“这是演示文件”
I have a command which will give docker image running in a kubenertes pods 我有一个命令可以让docker image在kubenertes pods中运行
kubectl get pods -n eum -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}" -l app=${TIER}
TIER = list of apps added in jenkins as choice parameter TIER =在jenkins中添加的应用程序列表作为选择参数
I wanted to login to the container and run the test.sh script 我想登录到容器并运行test.sh脚本
You can use command "kubectl exec ${POD } /bin/bash --all-namespaces -- /bin/sh test.sh" to run directly test.sh inside container, but make sure test.sh is available inside container. 您可以使用命令“ kubectl exec $ {POD} / bin / bash --all-namespaces-/ bin / sh test.sh”直接在容器内运行test.sh,但要确保test.sh在容器内可用。 But in this case you need to pass pod name in this command.
但是在这种情况下,您需要在此命令中传递容器名称。 you can get all pods name using command
您可以使用命令获取所有吊舱名称
kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\\n"}}{{end}}' kubectl get pods -o go-template --template'{{range .items}} {{。metadata.name}} {{“ \\ n”}} {{end}}'
and if you want pods only for specific label then use 如果您只想将豆荚用于特定标签,则使用
kubectl get pods -l -o go-template --template '{{range .items}}{{.metadata.name}}{{"\\n"}}{{end}}' kubectl get pods -l -o go-template --template'{{range .items}} {{。metadata.name}} {{“ \\ n”}} {{end}}'
here replace with your label selector of pods 在这里替换为您的吊舱标签选择器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.