【KubernetesでCI/CD】Tektonコマンドまとめ

2021.12.23
2024.03.24
CI/CD
TektonTekton CLI

はじめに

Tekton CLI(tkn)のよく使いそうなコマンドをまとめました。

これからTektonを使い始める方は下記を参考にしてください。

【KubernetesでCI/CD】Tektonとは

【KubernetesでCI/CD】Tektonとは

はじめに KubernetesでCI/CDができる**Tektonについてどんなものなのか**、

Tektonを動かしながらコマンドを試したい場合は、下記の記事を参考に動かしながら試してください。

【KubernetesでCI/CD】Tekton Pipelineでビルドからデプロイまでやってみる

【KubernetesでCI/CD】Tekton Pipelineでビルドからデプロイまでやってみる

はじめに Tekton Pipelineで**JGithubからソースを取得して、ビルドしてデプ

【KubernetesでCI/CD】Tektonのパラメーターを理解する

【KubernetesでCI/CD】Tektonのパラメーターを理解する

はじめに Tektonでの**パラメーターがどのように設定され、どのように受け渡しがされるのか*

Tekton CLI

インストール

Tekton CLIのインストール方法は下記の通りです。

1brew tap tektoncd/tools
2brew install tektoncd/tools/tektoncd-cli

CLI

Command-Line Interface

バージョンの確認

1tkn version

ヘルプの確認

基本的にヘルプでコマンドの使い方が確認できます。

1tkn help

下記のように使い方を知りたいコマンドで-h--helpフラグをつけることで詳細な使い方が確認できます。

1❯ tkn task create -h
2Create a Task from ClusterTask
3
4Usage:
5tkn task create [flags]
6
7Examples:
8  Create a Task from ClusterTask 'foo' in namespace 'ns':
9        tkn task create --from foo
10or
11        tkn task create foobar --from=foo -n ns
12
13Flags:
14      --from string   Create a ClusterTask from Task in a particular namespace
15  -h, --help          help for create
16
17Global Flags:
18  -c, --context string      name of the kubeconfig context to use (default: kubectl config current-context)
19  -k, --kubeconfig string   kubectl config file (default: $HOME/.kube/config)
20  -n, --namespace string    namespace to use (default: from $KUBECONFIG)
21  -C, --no-color            disable coloring (default: false)

EventListener

エイリアス

  • el
  • eventlistener
  • eventlisteners

list

EventListenerの一覧を表示します。

1tkn el list
1❯ tkn el list
2NAME                      AGE              URL                                                                AVAILABLE
3hello-greeting-listener   18 minutes ago   http://el-hello-greeting-listener.default.svc.cluster.local:8080   True

describe

EventListenerの詳細を表示します。

1tkn el describe <EventListener>
1❯ tkn el describe hello-greeting-listener
2Name:                      hello-greeting-listener
3Namespace:                 default
4Service Account:           tekton-triggers-example-sa
5URL:                       http://el-hello-greeting-listener.default.svc.cluster.local:8080
6EventListnerServiceName:   el-hello-greeting-listener
7
8EventListenerTriggers
9
10 NAME
11 ∙ hello-greeting-trigger
12
13 BINDINGS
14
15  REF                                 KIND             APIVERSION
16  ∙ hello-greeting-pipeline-binding   TriggerBinding
17
18 TEMPLATE REF                         APIVERSION
19 ∙ hello-greeting-pipeline-template

logs

EventListenerのログを表示します。

1tkn el logs <EventListener>
1❯ tkn el logs hello-greeting-listener
2
3[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.619Z","caller":"logging/config.go:116","msg":"Successfully created the logger."}
4[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.620Z","caller":"logging/config.go:117","msg":"Logging level set to: info"}
5[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.620Z","caller":"logging/config.go:79","msg":"Fetch GitHub commit ID from kodata failed","error":"open /var/run/ko/HEAD: no such file or directory"}
6[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.622Z","logger":"eventlistener","caller":"metrics/metrics_worker.go:76","msg":"Flushing the existing exporter before setting up the new exporter."}
7[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.624Z","logger":"eventlistener","caller":"metrics/prometheus_exporter.go:51","msg":"Created Prometheus exporter with config: &{tekton.dev/triggers eventlistener prometheus 5000000000 <nil> <nil>  false 9000 0.0.0.0}. Start the server for Prometheus exporter."}
8[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"info","ts":"2021-12-23T11:30:57.625Z","logger":"eventlistener","caller":"metrics/metrics_worker.go:91","msg":"Successfully updated the metrics exporter; old config: <nil>; new config &{tekton.dev/triggers eventlistener prometheus 5000000000 <nil> <nil>  false 9000 0.0.0.0}"}
9[hello-greeting-listener-el-hello-greeting-listener-db54474fb-6jbsj]: {"level":"warn","ts":"2021-12-23T11:30:57.625Z","logger":"eventlistener","caller":"v2/config.go:178","msg":"Sink timeout configuration is invalid, default to -1 (no timeout)"}

delete

EventListenerを削除します。

1tkn el delete <EventListener>
1❯ tkn el delete hello-greeting-listener
2Are you sure you want to delete eventlistener(s) "hello-greeting-listener" (y/n): y
3EventListeners deleted: "hello-greeting-listener"

Pipeline

エイリアス

  • p
  • pipeline
  • pipelines

list

Pipelineの一覧を表示します。

1tkn p list
1❯ tkn p list
2NAME                      AGE              LAST RUN   STARTED   DURATION   STATUS
3pipeline-hello-greeting   32 minutes ago   ---        ---       ---        ---

describe

Pipelineの詳細を表示します。

1tkn p describe <Pipeline>
1❯ tkn p describe pipeline-hello-greeting
2Name:        pipeline-hello-greeting
3Namespace:   default
4
5📦 Resources
6
7 No resources
8
9⚓ Params
10
11 NAME        TYPE     DESCRIPTION   DEFAULT VALUE
12 ∙ my-name   string                 ---
13 ∙ greet     string                 ---
14
15📝 Results
16
17 No results
18
19📂 Workspaces
20
21 No workspaces
22
23🗒  Tasks
24
25 NAME              TASKREF         RUNAFTER   TIMEOUT   CONDITIONS   PARAMS
26 ∙ task-hello      task-hello                 ---       ---          my-name: string
27 ∙ task-greeting   task-greeting              ---       ---          my-name: string, greet: string
28
29⛩  PipelineRuns
30
31 No pipelineruns

logs

Pipelineから生成されたPipelineRunのログを出力します。

1tkn p logs <Pipeline>
1❯ tkn p logs pipeline-hello-greeting
2Good morning masa
3
4hello masa

start

Pipelineを実行します。パラメータがある場合は入力します。

1tkn p start <Pipeline>
1❯ tkn p start pipeline-hello-greeting
2? Value for param `my-name` of type `string`?
3? Value for param `greet` of type `string`?
4PipelineRun started: pipeline-hello-greeting-run-z8np5
5
6In order to track the PipelineRun progress run:
7tkn pipelinerun logs pipeline-hello-greeting-run-z8np5 -f -n default

delete

Pipelineを削除します。

1tkn p delete <Pipeline>
1❯ tkn p delete pipeline-hello-greeting
2Are you sure you want to delete Pipeline(s) "pipeline-hello-greeting" (y/n): y
3Pipelines deleted: "pipeline-hello-greeting"

PipelineRun

エイリアス

  • pr
  • pipelinerun
  • pipelineruns

list

PipelineRunの一覧を表示します。

1tkn pr list
1❯ tkn pr list
2NAME                                STARTED          DURATION     STATUS
3pipeline-hello-greeting-run-z8np5   3 minutes ago    8 seconds    Succeeded
4hello-greeting-run-txvgl            8 minutes ago    27 seconds   Succeeded
5hello-greeting-run-pkfr4            8 minutes ago    25 seconds   Succeeded
6hello-greeting-run-z664z            8 minutes ago    19 seconds   Succeeded

describe

PipelineRunの詳細を表示します。

1tkn pr describe <PipelineRun>
1❯ tkn pr describe pipeline-hello-greeting-run-z8np5
2Name:              pipeline-hello-greeting-run-z8np5
3Namespace:         default
4Pipeline Ref:      pipeline-hello-greeting
5Service Account:   default
6Timeout:           1h0m0s
7Labels:
8 tekton.dev/pipeline=pipeline-hello-greeting
9
10🌡️  Status
11
12STARTED         DURATION    STATUS
135 minutes ago   8 seconds   Succeeded
14
15📦 Resources
16
17 No resources
18
19⚓ Params
20
21 NAME        VALUE
22 ∙ greet
23 ∙ my-name
24
25📝 Results
26
27 No results
28
29📂 Workspaces
30
31 No workspaces
32
33🗂  Taskruns
34
35 NAME                                                TASK NAME       STARTED         DURATION    STATUS
36 ∙ pipeline-hello-greeting-run-z8np5-task-greeting   task-greeting   5 minutes ago   6 seconds   Succeeded
37 ∙ pipeline-hello-greeting-run-z8np5-task-hello      task-hello      5 minutes ago   8 seconds   Succeeded
38
39⏭️  Skipped Tasks
40
41 No Skipped Tasks

logs

PipelineRunのログを出力します。

1tkn pr logs <PipelineRun>
1❯ tkn pr logs pipeline-hello-greeting-run-z8np5
2[task-greeting : echo-greeting-my-name]
3
4[task-hello : echo-hello-my-name] hello

cancel

実行中のPipelineRunを停止します。

1tkn pr cancel <PipelineRun>
1❯ tkn pr cancel pipeline-hello-greeting-run-zd6xt
2PipelineRun cancelled: pipeline-hello-greeting-run-zd6xt

delete

PipelineRunを削除します。

1tkn pr delete <PipelineRun>
1❯ tkn pr delete pipeline-hello-greeting-run-z8np5
2Are you sure you want to delete PipelineRun(s) "pipeline-hello-greeting-run-z8np5" (y/n): y
3PipelineRuns deleted: "pipeline-hello-greeting-run-z8np5"

Resource

エイリアス

  • res
  • resource
  • resources

list

PipelineResourceの一覧を表示します。

1tkn res list
1❯ tkn res list
2NAME                     TYPE   DETAILS
3goserver-source-github   git    url: https://github.com/monda00/go-server

describe

PipelineResourceの詳細を表示します。

1tkn res describe <PipelineResource>
1❯ tkn res describe goserver-source-github
2Name:                    goserver-source-github
3Namespace:               default
4PipelineResource Type:   git
5
6Params
7
8 NAME         VALUE
9 ∙ revision   main
10 ∙ url        https://github.com/monda00/go-server
11
12Secret Params
13
14 No secret params

create

PipelineResourceを作成します。

1tkn res create
1❯ tkn res create
2? Enter a name for a pipeline resource : git
3? Select a resource type to create : git
4? Enter a value for url :  https://github.com
5? Enter a value for revision :
6New git resource "git" has been created

delete

PipelineResourceを削除します。

1tkn res delete <PipelineResource>
1❯ tkn res delete git
2Are you sure you want to delete pipelineresource(s) "git" (y/n): y
3PipelineResources deleted: "git"

Task

エイリアス

  • t
  • task
  • tasks

list

Taskの一覧を表示します。

1tkn t list
1❯ tkn t list
2NAME            DESCRIPTION   AGE
3task-greeting                 1 hour ago
4task-hello                    1 hour ago

describe

Taskの詳細を表示します。

1tkn t describe <Task>
1❯ tkn t describe task-greeting
2Name:        task-greeting
3Namespace:   default
4
5📨 Input Resources
6
7 No input resources
8
9📡 Output Resources
10
11 No output resources
12
13⚓ Params
14
15 NAME        TYPE     DESCRIPTION              DEFAULT VALUE
16 ∙ my-name   string   My name which steps...   unknown
17 ∙ greet     string   Greeting                 Hello
18
19📝 Results
20
21 No results
22
23📂 Workspaces
24
25 No workspaces
26
27🦶 Steps
28
29 ∙ echo-greeting-my-name
30
31🗂  Taskruns
32
33NAME                                              STARTED          DURATION     STATUS
34pipeline-hello-greeting-run-zd6xt-task-greeting   14 minutes ago   9 seconds    Cancelled(TaskRunCancelled)
35pipeline-hello-greeting-run-z8np5-task-greeting   23 minutes ago   6 seconds    Succeeded
36hello-greeting-run-txvgl-task-greeting            28 minutes ago   26 seconds   Succeeded
37hello-greeting-run-pkfr4-task-greeting            28 minutes ago   24 seconds   Succeeded
38hello-greeting-run-z664z-task-greeting            28 minutes ago   18 seconds   Succeeded
39hello-greeting-run-7wnhq-task-greeting            28 minutes ago   18 seconds   Succeeded
40hello-greeting-run-spgd6-task-greeting            28 minutes ago   12 seconds   Succeeded
41hello-greeting-run-t7hfq-task-greeting            29 minutes ago   15 seconds   Succeeded

logs

Taskから生成されたTaskRunのログを出力します。

1tkn t logs <Task>
1❯ tkn t logs task-greeting
2? Select taskrun: hello-greeting-run-txvgl-task-greeting started 29 minutes ago
3Good morning masa

create

ClusterTaskからTaskを作成します。

1tkn t create --from <ClusterTask>
1❯ tkn t create --from task-greeting -n clustertask
2Task task-greeting created from ClusterTask task-greeting in namespace clustertask

start

Taskを実行します。パラメータがある場合は入力します。

1tkn t start <Task>
1❯ tkn t start task-greeting
2? Value for param `my-name` of type `string`? (Default is `unknown`) unknown
3? Value for param `greet` of type `string`? (Default is `Hello`) Hello
4TaskRun started: task-greeting-run-dd7t4
5
6In order to track the TaskRun progress run:
7tkn taskrun logs task-greeting-run-dd7t4 -f -n default

delete

Taskを削除します。

1tkn t delete <Task>
1❯ tkn t delete task-greeting
2Are you sure you want to delete Task(s) "task-greeting" (y/n): y
3Tasks deleted: "task-greeting"

TaskRun

エイリアス

  • tr
  • taskrun
  • taskruns

list

TaskRunの一覧を表示します。

1tkn tr list
1❯ tkn tr list
2NAME                                              STARTED          DURATION     STATUS
3task-greeting-run-dd7t4                           2 minutes ago    6 seconds    Succeeded
4pipeline-hello-greeting-run-zd6xt-task-hello      26 minutes ago   8 seconds    Succeeded
5pipeline-hello-greeting-run-zd6xt-task-greeting   26 minutes ago   9 seconds    Cancelled(TaskRunCancelled)
6pipeline-hello-greeting-run-z8np5-task-hello      35 minutes ago   8 seconds    Succeeded
7pipeline-hello-greeting-run-z8np5-task-greeting   35 minutes ago   6 seconds    Succeeded
8hello-greeting-run-txvgl-task-greeting            39 minutes ago   26 seconds   Succeeded

describe

TaskRunの詳細を表示します。

1tkn tr describe <TaskRun>
1❯ tkn tr describe task-greeting-run-dd7t4
2Name:              task-greeting-run-dd7t4
3Namespace:         default
4Task Ref:          task-greeting
5Service Account:   default
6Timeout:           1h0m0s
7Labels:
8 app.kubernetes.io/managed-by=tekton-pipelines
9 tekton.dev/task=task-greeting
10
11🌡️  Status
12
13STARTED         DURATION    STATUS
144 minutes ago   6 seconds   Succeeded
15
16📨 Input Resources
17
18 No input resources
19
20📡 Output Resources
21
22 No output resources
23
24⚓ Params
25
26 NAME        VALUE
27 ∙ greet     Hello
28 ∙ my-name   unknown
29
30📝 Results
31
32 No results
33
34📂 Workspaces
35
36 No workspaces
37
38🦶 Steps
39
40 NAME                      STATUS
41 ∙ echo-greeting-my-name   Completed
42
43🚗 Sidecars
44
45No sidecars

logs

TaskRunのログを出力します。

1tkn tr logs <TaskRun>
1❯ tkn tr logs task-greeting-run-dd7t4
2[echo-greeting-my-name] Hello unknown

cancel

実行中のTaskRunを停止します。

1tkn tr cancel <TaskRun>
1❯ tkn tr cancel task-greeting-run-8vzzr
2TaskRun cancelled: task-greeting-run-8vzzr

delete

TaskRunを削除します。

1tkn tr delete <TaskRun>
1❯ tkn tr delete task-greeting-run-dd7t4
2Are you sure you want to delete TaskRun(s) "task-greeting-run-dd7t4" (y/n): y
3TaskRuns deleted: "task-greeting-run-dd7t4"

TriggerBinding

エイリアス

  • tb
  • triggerbinding
  • triggerbindings

list

TriggerBindingの一覧を表示します。

1tkn tb list
1❯ tkn tb list
2NAME                              AGE
3hello-greeting-pipeline-binding   1 hour ago

describe

TriggerBindingの詳細を表示します。

1tkn tb describe <TriggerBinding>
1❯ tkn tb describe hello-greeting-pipeline-binding
2Name:        hello-greeting-pipeline-binding
3Namespace:   default
4
5⚓ Params
6
7 NAME        VALUE
8 ∙ my-name   $(body.name)
9 ∙ greet     $(body.greet)

delete

TriggerBindingを削除します。

1tkn tb delete <TriggerBinding>
1❯ tkn tb delete hello-greeting-pipeline-binding
2Are you sure you want to delete triggerbinding(s) "hello-greeting-pipeline-binding" (y/n): y
3TriggerBindings deleted: "hello-greeting-pipeline-binding"

TriggerTemplate

エイリアス

  • tt
  • triggertemplate
  • triggertemplates

list

TriggerTemplateの一覧を表示します。

1tkn tt list
1❯ tkn tt list
2NAME                               AGE
3hello-greeting-pipeline-template   1 hour ago

describe

TriggerTemplateの詳細を表示します。

1tkn tt describe <TriggerTemplate>
1❯ tkn tt describe hello-greeting-pipeline-template
2Name:        hello-greeting-pipeline-template
3Namespace:   default
4
5⚓ Params
6
7 NAME        DESCRIPTION              DEFAULT VALUE
8 ∙ my-name   My name which steps...   unknown
9 ∙ greet     Greeting                 Hello
10
11📦 ResourceTemplates
12
13 NAME    GENERATENAME          KIND          APIVERSION
14 ∙ ---   hello-greeting-run-   PipelineRun   tekton.dev/v1beta1

delete

TriggerTemplateを削除します。

1tkn tt delete <TriggerTemplate>
1❯ tkn tt delete hello-greeting-pipeline-template
2Are you sure you want to delete triggertemplate(s) "hello-greeting-pipeline-template" (y/n): y
3TriggerTemplates deleted: "hello-greeting-pipeline-template"

参考

Support

\ この記事が役に立ったと思ったら、サポートお願いします! /

buy me a coffee
Share

Profile

author

Masa

都内のIT企業で働くエンジニア
自分が学んだことをブログでわかりやすく発信していきながらスキルアップを目指していきます!

buy me a coffee