GKE kubernetes delayed_job pod logs

2019-04-24 07:22发布

I have a deployment object with the following rake jobs:work command:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: staging-delayed-job-deployment
  namespace: staging
spec:
  template:
    metadata:
      labels:
        env: staging
        name: delayed-job
    spec:
      containers:
        - name: job
          image: gcr.io/ej-gc-dev/redacted:<%= ENV['IMAGE_TAG'] %>
          command: ["/bin/bash", "-l", "-c"]
          args: ["RAILS_ENV=production bundle exec rake jobs:work"]

When I run kubectl logs I get nothing. How do I get the rake jobs:work output to show in kubectl logs ? i.e if run directly in the pod it gives output like this:

[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Starting job worker
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=67) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=67) COMPLETED after 0.4903
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=68) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=68) COMPLETED after 0.9115
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=69) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job UpdateHubspotPersonaJob (id=69) COMPLETED after 0.1752
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=70) RUNNING
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] Job Mailerjack.registration_created_user_welcome (id=70) COMPLETED after 0.4770
[Worker(host:staging-deployment-cc7dc559f-bswvr pid:2381)] 4 jobs processed at 1.7649 j/s, 0 failed

I want that to show up when I run kubectl logs

1条回答
Juvenile、少年°
2楼-- · 2019-04-24 07:53

I needed to add an initializer: config/initializers/delayed_job.rb and set the worker's logger to stdout like so:

Delayed::Worker.logger = Logger.new(STDOUT)

查看更多
登录 后发表回答