简体   繁体   English

如何登录运行在特定Kubernetes容器内的Docker容器并运行test.sh文件?

[英]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.

相关问题 如何在具有运行中的spring-boot应用程序的kubernetes容器/容器中运行cron? - How do I run a cron inside a kubernetes pod/container which has a running spring-boot application? 如何检查在 kubernetes pod 的 docker 容器内运行的工人数量? - How to check the number of workers running inside a docker container of kubernetes pod? 如何将 docker 容器添加到正在运行的 kube.netes pod? - How to add a docker container to a running kubernetes pod? 我有一个 python 脚本在 kubernetes pod 的容器内运行。如何停止与 pod 一起运行的脚本? - I have a python script running inside a container of kubernetes pod.How do i stop the script which runs along with the starting of the pod? 通过“ revel build”运行.sh二进制文件 <testapp> &#39;没有在docker容器中运行 - run.sh binary file thru 'revel build <testapp>' not running inside docker container 测试 docker 容器的 Kubernetes pod 失败 - failed Kubernetes pod of a test docker container 无法从kubernetes容器内运行的docker写入文件 - Unable to write file from docker run inside a kubernetes pod 如何从运行在同一 Kube.netes 集群中的容器连接到 Docker,它在 Kube.netes 集群中的主机虚拟机上运行? - How do I connect to Docker, running on host VMs in a Kubernetes cluster from a container running in the same Kubernetes cluster? 将文件传递到 kube.netes Pod 中的 docker 容器 - Pass file to docker container in a kubernetes Pod 如何使用 docker 容器创建 kubernetes pod - how to create kubernetes pod with docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM