<p>My CI tool uses lifecycles so  if Dev deployments works, it goes to QA.</p>

<p>I have an end to end test container that i want to run in kubernetes, but how do i get the exit code from the container?</p>

<p>Can i somehow run the container and get back the exit code in one command?</p>

<p><code>kubectl run -it</code>
doesn't seem to get the exit code and has some extra things to say after the container is done.</p>

tekno45
<p>To get the exit code from a Pod (container) you can get the pod details with the command:</p>

<pre><code>kubectl get pod termination-demo --output=yaml
</code></pre>

<p>Output:</p>

<pre><code>apiVersion: v1
kind: Pod
...
    lastState:
      terminated:
        containerID: ...
        exitCode: 0
        finishedAt: ...
        message: |
          Sleep expired
        ...
</code></pre>

<p>To know more, you can check the <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/determine-reason-pod-failure/#writing-and-reading-a-termination-message" rel="noreferrer">documentation.</a> </p>

<p>To make it easier as you wish you can run: </p>

<pre><code>kubectl get pod busybox-term -ojson | jq .status.containerStatuses[].lastState.terminated.exitCode
</code></pre>

<p>Or if you don't want to install <code>jq</code>, you can run: </p>

<pre><code>kubectl get pod busybox-term --output="jsonpath={.status.containerStatuses[].lastState.terminated.exitCode}"
</code></pre>
