开发者社区> 问答> 正文

Kubernetes Pod很快将状态从运行变为完成,我该如何防止这种情况发生

创建一个pod使用yaml,一旦创建了pod ,我正在kubectl exec运行我的gatling perf测试代码

kubectl exec gradlecommandfromcommandline -- ./gradlew gatlingRun-
simulations.RuntimeParameters -DUSERS=500 -DRAMP_DURATION=5 -DDURATION=30
但这是以kubectl控制台结束,并带有以下消息: -

命令以退出代码137终止

在调查中,它发现pod正在从运行阶段改变到完成阶段。

如何增加pod的生命周期,以便等待我的命令执行。这是pod yaml

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

展开
收起
k8s小能手 2018-12-14 17:32:43 3232 0
2 条回答
写回答
取消 提交回答
  • 在容器中,建议使用前台服务,而不是后台服务。比如运行 /bin/sshd, 而不是service sshd start.
    这样可以让你的应用一直运行在前台,容器不会进入ready状态。
    使用脚本也是一种方式,但是会有一个问题,容器的生命周期和应用不匹配,设计的时候可以考虑进去

    2019-07-17 23:21:27
    赞同 1 展开评论 打赏
  • 整合最优质的专家资源和技术资料,问答解疑

    这是yaml文件,使pod始终运行apiVersion:v1

    kind: Pod
    metadata:
    name: gradlecommandfromcommandline
    labels:
    purpose: gradlecommandfromcommandline
    spec:
    volumes:

    • name: docker-sock
      hostPath:

      path: /home/vagrant/k8s/pods/gatling/user-files/simulations    # A file or 
    1. location on the node that you want to mount into the Pod

    # command: [ "git clone https://github.com/TarunKDas2k18/PerfGatl.git" ]
    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"]

    • name: gatlingperftool
      image: tarunkumard/gatling:FirstScript # Run the ubuntu 16.04

    command: [ "/bin/bash", "-c", "--" ] # You need to run some task inside a
    container to keep it running
    args: [ "while true; do sleep 10; done;" ] # Our simple program just sleeps inside
    an infinite loop
    volumeMounts:

    - mountPath: /opt/gatling/user-files/simulations     # The mount path within the 

    container

      name: docker-sock                   # Name must match the hostPath volume name

    ports:

    - containerPort: 80
    2019-07-17 23:21:27
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
ACK 云原生弹性方案—云原生时代的加速器 立即下载
ACK集群类型选择最佳实践 立即下载
企业运维之云原生和Kubernetes 实战 立即下载

相关镜像