PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 26, 2022

[FIXED] How to start container with kubectl and get exit code back? without kubectl exec

 September 26, 2022     continuous-deployment, kubectl, kubernetes     No comments   

Issue

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

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?

Can i somehow run the container and get back the exit code in one command?

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


Solution

To get the exit code from a Pod (container) you can get the pod details with the command:

kubectl get pod termination-demo --output=yaml

Output:

apiVersion: v1
kind: Pod
...
    lastState:
      terminated:
        containerID: ...
        exitCode: 0
        finishedAt: ...
        message: |
          Sleep expired
        ...

To know more, you can check the documentation.

To make it easier as you wish you can run:

kubectl get pod busybox-term -ojson | jq .status.containerStatuses[].lastState.terminated.exitCode

Or if you don't want to install jq, you can run:

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


Answered By - Mark Watney
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing