如何登录运行在特定Kubernetes容器内的Docker容器并运行test.sh文件? [英] How do I login into a Docker container running inside the specific Kubernetes pod and run an test.sh file?

查看:429
本文介绍了如何登录运行在特定Kubernetes容器内的Docker容器并运行test.sh文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个test.sh文件,该文件需要在通过Jenkins作业在Kubernetes吊舱内运行的Docker容器中运行.

I have a test.sh file which need to be run in an docker container which runs inside the Kubernetes pods via Jenkins job.

流量:

第1步:运行Jenkins作业,该作业应登录到在Pod内运行的Docker容器

Step1 : Run a Jenkins job which should login to a docker container running inside the pods

步骤:从容器中执行test.sh脚本.

Step: From the container execute the test.sh script.

test.sh

回显这是演示文件"

我有一个命令,该命令将给在kubenertes吊舱中运行的docker映像

I have a command which will give docker image running in a kubenertes pods

kubectl get pods -n eum -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}" -l app=${TIER}

TIER =在jenkins中添加的应用程序列表作为选择参数

TIER = list of apps added in jenkins as choice parameter

我想登录到容器并运行test.sh脚本

I wanted to login to the container and run the test.sh script

推荐答案

您可以使用命令"kubectl exec $ {POD}/bin/bash --all-namespaces-/bin/sh test.sh"直接运行容器内有test.sh,但请确保容器内有test.sh.但是在这种情况下,您需要在此命令中传递Pod名称.您可以使用命令获取所有吊舱名称

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. But in this case you need to pass pod name in this command. you can get all pods name using command

kubectl获取容器-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

这篇关于如何登录运行在特定Kubernetes容器内的Docker容器并运行test.sh文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆