(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【Tekton/Kubernetes】kubectlを用いたPipelineRun失敗時のログの見方

スポンサーリンク

はじめに

Tektonを利用したCI/CDの中でPipelineが失敗した際に詳細メッセージを確認する流れを記載しました。

$ kubectl get pipelineruns
NAME                       SUCCEEDED   REASON   STARTTIME   COMPLETIONTIME
test-pipeline-run   False       Failed   100s        92s
環境情報
  • Windows 10
  • Cygwin
  • tekton: v0.19.0
  • Kubernetes 1.19

詳細ログ確認方法

止まっているTaskは

$ kubectl describe pipelineruns test-pipeline-run

で以下のように表示されます。

Events:
  Type     Reason   Age   From         Message
  ----     ------   ----  ----         -------
  Normal   Started  115s  PipelineRun
  Normal   Running  115s  PipelineRun  Tasks Completed: 0 (Failed: 0, Cancelled 0), Incomplete: 2, Skipped: 0
  Warning  Failed   107s  PipelineRun  Tasks Completed: 1 (Failed: 1, Cancelled 0), Skipped: 1

上記でFailedとなっているTaskRunが止まっているのが確認できるので

$ kubectl get taskrun
NAME                                                     SUCCEEDED   REASON   STARTTIME   COMPLETIONTIME
test-pipeline-run-build-image-from-source-bdl4z   False       Failed   5m17s       5m9s

該当のtaskrunの詳細を確認すればメッセージ内に詳細のログを見るためのコマンドが表示されます。

$ kubectl describe taskrun application-pipeline-run-build-image-from-source-bdl4z
...
Message:               "step-git-source-git-source-gxgtm" exited with code 1 (image: "gcr.io/tekton-releases/github.com/tektoncd/pi
peline/cmd/git-init@sha256:db3e7431b11917f21c6978f478298dcb5b2b4048e9f1ec5c0246d72b66c820c7"); for logs run: kubectl -n default logs application-pipeline-run-build-image-from-source-bdl4z-po-jwznv -c step-git-source-git-source-gxgtm

上のログで言うところのfor logs runで始まる箇所です。

実際に同ワンライナーを叩けば

$ kubectl -n default logs application-pipeline-run-build-image-from-source-bdl4z-po-jwznv -c step-git-source-git-source-gxgtm
{"level":"error","ts":1610099581.4638937,"caller":"git/git.go:54","msg":"Error running git [fetch --recurse-submodules=yes --depth=1 or
igin --update-head-ok --force master]: exit status 128\nfatal: unable to access 'https://https://github.com/xx: Could
not resolve host: ...
{"level":"fatal","ts":1610099581.464088,"caller":"git-init/main.go:53","msg":"Error fetching git repository: failed to fetch [master]:
exit status 128","stacktrace":"main.main\n\tgithub.com/tektoncd/pipeline/cmd/git-init/main.go:53\nruntime.main\n\truntime/proc.go:204"}

ログが表示されます。以下コマンドがサクッと確認することも可能。

$ kubectl describe taskrun | tail -n 1 | awk '{print substr($0,index($0,"run:")+5)}'
kubectl -n default logs application-pipeline-run-build-image-from-source-mdh9l-po-vgn9s -c step-git-source-git-source-pmvm6

終わりに

Tekton PipelinesのCLIツールを利用せずにログを確認したければ、Taskrunの詳細から確認用コマンドをコピーするのが手っ取り早いです。

以上、ご参考になれば幸いです。