Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view logs of failed jobs with kubectl?

I've created a Kubernetes job that has now failed. Where can I find the logs to this job?

I'm not sure how to find the associated pod (I assume once the job fails it deletes the pod)?

Running kubectl describe job does not seem to show any relevant information:

Name:           app-raiden-migration-12-19-58-21-11-2018 Namespace:      localdev Selector:       controller-uid=c2fd06be-ed87-11e8-8782-080027eeb8a0 Labels:         jobType=database-migration Annotations:    kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"labels":{"jobType":"database-migration"},"name":"app-raiden-migration-12-19-58-21-1... Parallelism:    1 Completions:    1 Start Time:     Wed, 21 Nov 2018 12:19:58 +0000 Pods Statuses:  0 Running / 0 Succeeded / 1 Failed Pod Template:   Labels:  controller-uid=c2fd06be-ed87-11e8-8782-080027eeb8a0            job-name=app-raiden-migration-12-19-58-21-11-2018   Containers:    app:     Image:  pp3-raiden-app:latest     Port:   <none>     Command:       php       artisan       migrate     Environment:       DB_HOST:        local-mysql       DB_PORT:        3306       DB_DATABASE:    raiden       DB_USERNAME:    <set to the key 'username' in secret 'cloudsql-db-credentials'>  Optional: false       DB_PASSWORD:    <set to the key 'password' in secret 'cloudsql-db-credentials'>  Optional: false       LOG_CHANNEL:    stderr       APP_NAME:       Laravel       APP_KEY:        ABCDEF123ERD456EABCDEF123ERD456E       APP_URL:        http://192.168.99.100       OAUTH_PRIVATE:  <set to the key 'oauth_private.key' in secret 'laravel-oauth'>  Optional: false       OAUTH_PUBLIC:   <set to the key 'oauth_public.key' in secret 'laravel-oauth'>   Optional: false     Mounts:           <none>   Volumes:            <none> Events:   Type     Reason                Age   From            Message   ----     ------                ----  ----            -------   Normal   SuccessfulCreate      2m    job-controller  Created pod: app-raiden-migration-12-19-58-21-11-2018-pwnjn   Warning  BackoffLimitExceeded  2m    job-controller  Job has reach the specified backoff limit 
like image 735
Chris Stryczynski Avatar asked Nov 21 '18 12:11

Chris Stryczynski


People also ask

How do you check Kubernetes failed pod logs?

If you are using Cloud environment you can use Integrated with Cloud Logging tools (i.e. in Google Cloud Platform you can use Stackdriver ). In case you want to check logs to find reason why pod failed, it's good described in K8s docs Debug Running Pods.

How do I get all the Kubernetes logs?

To get all logs, set tail to -1 . Add -f or --follow to the example to follow the logs. If you don't need all of the logs, change the value of the --tail option.


2 Answers

One other approach:

  • kubectl describe job $JOB
  • Pod name is shown under "Events"
  • kubectl logs $POD
like image 105
David Thomas Avatar answered Oct 18 '22 02:10

David Thomas


Use this command to show all pods, even failed ones:

kubectl get pods -A 

And then a pod will be shown like below:

app-raiden-migration-12-19-58-21-11-2018-pwnjn   0/1       Error     0          6m 

Then use:

kubectl logs lighthouse-timer-1553800620-pwssv 
like image 43
Chris Stryczynski Avatar answered Oct 18 '22 02:10

Chris Stryczynski