Copy report after kubernetes job is succeeded

8/13/2018

I have some services running on a namespace in kubernetes. I have created a job to run my api tests pointing to these services and when this job is finished(succeeded), I would like to be able to copy the json reports to my machine. I tried to use kubectl cp but this just works when the pod is still running.

Does anyone know how can I copy these reports after the job is completed ? I tried to create a deployment so I would be able to copy these reports, but then there is no restartpolicy for deployments and the tests were restarting everytime, which made me lost the reports before I was able to copy them. Also tried to just create a pod with the restartpolicy: NEVER but I had the same problem as the job.

apiVersion: v1
kind: Pod
metadata:
  name: api-tests
  namespace: tests
spec:
    restartPolicy: Never
    containers:
    - name: api-tests
      image: api-tests:latest
      args: 
          - run
          - https://www.getpostman.com/collections/test23423423
          - -e
          - /etc/newman/envs/kubernetes.postman_environment.json 
          - -d
          - /etc/newman/data/tests.csv
          - --reporters
          - cli,html,json
          - --reporter-json-export
          - /etc/newman/target/api_tests.json
          - --reporter-html-export
          - /etc/newman/target/api_tests.html
          - --reporter-cli-no-failures

This is the job.yaml that I have at the moment.

Any ideas are more than welcome.

-- rafazzevedo
automation
kubernetes

1 Answer

8/13/2018

I think you can push your reports to some system like git server, or you can place the reports to shared storage like nfs using persistentvolume(PV). Your jobs are going to run a specific node host then you can also review the hostPath to share the reports with host server from pods.

I hope it helpful to you.

-- Daein Park
Source: StackOverflow