Kubernetes Pod is changing status from running to completed very soon ,how do i prevent that

12/13/2018

Created a pod using yaml and once pod is created I am running kubectl exec to run my gatling perf test code

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

but this is ending at kubectl console with below message :-

command terminated with exit code 137

On Investigation its found that pod is changing status from running to completed stage.

How do i increase life span of a pod so that it waits for my command to get executed.Here is 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
-- Margaret real
kubernetes
kubernetes-pod

1 Answer

12/13/2018

Here is yaml file to make pod running always 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 
directory 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
-- Margaret real
Source: StackOverflow