How to Make Kubectl run a container after pod is created

痞子三分冷 提交于 2019-12-11 06:32:28

问题


Intention is to execute gatling perf tests from command line .Equivalent docker command is

docker run --rm  -w /opt/gatling-fundamentals/ 
tarunkumard/tarungatlingscript:v1.0 
./gradlew gatlingRun-simulations.RuntimeParameters -DUSERS=500 -DRAMP_DURATION=5 -DDURATION=30

Now to map above docker run in Kubernetes using kubectl, I have created a pod for which gradlewcommand.yaml file is below

apiVersion: v1
kind: Pod
metadata:
name: gradlecommandfromcommandline
labels:
purpose: gradlecommandfromcommandline
spec:
containers:
- name: gradlecommandfromcommandline
image: tarunkumard/tarungatlingscript:v1.0
workingDir: /opt/gatling-fundamentals/
command: ["./gradlew"]
args: ["gatlingRun-simulations.RuntimeParameters", "-DUSERS=500", "- 
DRAMP_DURATION=5", "-DDURATION=30"]
restartPolicy: OnFailure

Now pod is created using below command:-

kubectl apply -f gradlewcommand.yaml 

Now comes my actual requirement or question that how do i run or trigger kubectl run command so as to run container inside the above pod created? ,mind you pod name is gradlecommandfromcommandline


回答1:


Here is the command which solves the problem:

 kubectl exec gradlecommandfromcommandline -- \
   ./gradlew gatlingRun-simulations.RuntimeParameters \
   -DUSERS=500 -DRAMP_DURATION=5 -DDURATION=30


来源:https://stackoverflow.com/questions/53753665/how-to-make-kubectl-run-a-container-after-pod-is-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!