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

スポンサーリンク

はじめに

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

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

【KubernetesでCI/CD】Tektonとは
はじめにKubernetesでCI/CDができるTektonについてどんなものなのか、ローカルで使うために何をしたらいいのかまとめました。ローカル上でKubernetesが動いていることが前提となっています。今回はDocker Desk...

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

【KubernetesでCI/CD】Tekton Pipelineでビルドからデプロイまでやってみる
はじめにTekton PipelineでGithubからソースを取得して、ビルドしてデプロイするまでを試してみたいと思います。Tekton Pipelineを簡単な例で動かしてみるのは下記の記事でやってみましたが、今回はもう少し実例に近...
【KubernetesでCI/CD】Tektonのパラメーターを理解する
はじめにTektonでのパラメーターがどのように設定され、どのように受け渡しがされるのかを実際に動かしながら理解していきたいと思います。Tekton PipelineとTekton Triggerについては使える環境が前提となっています...

Tekton CLI

インストール

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

brew tap tektoncd/tools
brew install tektoncd/tools/tektoncd-cli
CLI
Command-Line Interface

バージョンの確認

tkn version

ヘルプの確認

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

tkn help

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

❯ tkn task create -h
Create a Task from ClusterTask

Usage:
tkn task create [flags]

Examples:
  Create a Task from ClusterTask 'foo' in namespace 'ns':
        tkn task create --from foo
or
        tkn task create foobar --from=foo -n ns

Flags:
      --from string   Create a ClusterTask from Task in a particular namespace
  -h, --help          help for create

Global Flags:
  -c, --context string      name of the kubeconfig context to use (default: kubectl config current-context)
  -k, --kubeconfig string   kubectl config file (default: $HOME/.kube/config)
  -n, --namespace string    namespace to use (default: from $KUBECONFIG)
  -C, --no-color            disable coloring (default: false)

EventListener

エイリアス

  • el
  • eventlistener
  • eventlisteners

list

EventListenerの一覧を表示します。

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

describe

EventListenerの詳細を表示します。

tkn el describe <EventListener>
❯ tkn el describe hello-greeting-listener
Name:                      hello-greeting-listener
Namespace:                 default
Service Account:           tekton-triggers-example-sa
URL:                       http://el-hello-greeting-listener.default.svc.cluster.local:8080
EventListnerServiceName:   el-hello-greeting-listener

EventListenerTriggers

 NAME
 ∙ hello-greeting-trigger

 BINDINGS

  REF                                 KIND             APIVERSION
  ∙ hello-greeting-pipeline-binding   TriggerBinding

 TEMPLATE REF                         APIVERSION
 ∙ hello-greeting-pipeline-template

logs

EventListenerのログを表示します。

tkn el logs <EventListener>
❯ tkn el logs hello-greeting-listener

[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."}
[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"}
[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"}
[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."}
[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."}
[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}"}
[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を削除します。

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

Pipeline

エイリアス

  • p
  • pipeline
  • pipelines

list

Pipelineの一覧を表示します。

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

describe

Pipelineの詳細を表示します。

tkn p describe <Pipeline>
❯ tkn p describe pipeline-hello-greeting
Name:        pipeline-hello-greeting
Namespace:   default

📦 Resources

 No resources

⚓ Params

 NAME        TYPE     DESCRIPTION   DEFAULT VALUE
 ∙ my-name   string                 ---
 ∙ greet     string                 ---

📝 Results

 No results

📂 Workspaces

 No workspaces

🗒  Tasks

 NAME              TASKREF         RUNAFTER   TIMEOUT   CONDITIONS   PARAMS
 ∙ task-hello      task-hello                 ---       ---          my-name: string
 ∙ task-greeting   task-greeting              ---       ---          my-name: string, greet: string

⛩  PipelineRuns

 No pipelineruns

logs

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

tkn p logs <Pipeline>
❯ tkn p logs pipeline-hello-greeting
Good morning masa

hello masa

start

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

tkn p start <Pipeline>
❯ tkn p start pipeline-hello-greeting
? Value for param `my-name` of type `string`?
? Value for param `greet` of type `string`?
PipelineRun started: pipeline-hello-greeting-run-z8np5

In order to track the PipelineRun progress run:
tkn pipelinerun logs pipeline-hello-greeting-run-z8np5 -f -n default

delete

Pipelineを削除します。

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

PipelineRun

エイリアス

  • pr
  • pipelinerun
  • pipelineruns

list

PipelineRunの一覧を表示します。

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

describe

PipelineRunの詳細を表示します。

tkn pr describe <PipelineRun>
❯ tkn pr describe pipeline-hello-greeting-run-z8np5
Name:              pipeline-hello-greeting-run-z8np5
Namespace:         default
Pipeline Ref:      pipeline-hello-greeting
Service Account:   default
Timeout:           1h0m0s
Labels:
 tekton.dev/pipeline=pipeline-hello-greeting

🌡️  Status

STARTED         DURATION    STATUS
5 minutes ago   8 seconds   Succeeded

📦 Resources

 No resources

⚓ Params

 NAME        VALUE
 ∙ greet
 ∙ my-name

📝 Results

 No results

📂 Workspaces

 No workspaces

🗂  Taskruns

 NAME                                                TASK NAME       STARTED         DURATION    STATUS
 ∙ pipeline-hello-greeting-run-z8np5-task-greeting   task-greeting   5 minutes ago   6 seconds   Succeeded
 ∙ pipeline-hello-greeting-run-z8np5-task-hello      task-hello      5 minutes ago   8 seconds   Succeeded

⏭️  Skipped Tasks

 No Skipped Tasks

logs

PipelineRunのログを出力します。

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

[task-hello : echo-hello-my-name] hello

cancel

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

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

delete

PipelineRunを削除します。

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

Resource

エイリアス

  • res
  • resource
  • resources

list

PipelineResourceの一覧を表示します。

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

describe

PipelineResourceの詳細を表示します。

tkn res describe <PipelineResource>
❯ tkn res describe goserver-source-github
Name:                    goserver-source-github
Namespace:               default
PipelineResource Type:   git

Params

 NAME         VALUE
 ∙ revision   main
 ∙ url        https://github.com/monda00/go-server

Secret Params

 No secret params

create

PipelineResourceを作成します。

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

delete

PipelineResourceを削除します。

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

Task

エイリアス

  • t
  • task
  • tasks

list

Taskの一覧を表示します。

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

describe

Taskの詳細を表示します。

tkn t describe <Task>
❯ tkn t describe task-greeting
Name:        task-greeting
Namespace:   default

📨 Input Resources

 No input resources

📡 Output Resources

 No output resources

⚓ Params

 NAME        TYPE     DESCRIPTION              DEFAULT VALUE
 ∙ my-name   string   My name which steps...   unknown
 ∙ greet     string   Greeting                 Hello

📝 Results

 No results

📂 Workspaces

 No workspaces

🦶 Steps

 ∙ echo-greeting-my-name

🗂  Taskruns

NAME                                              STARTED          DURATION     STATUS
pipeline-hello-greeting-run-zd6xt-task-greeting   14 minutes ago   9 seconds    Cancelled(TaskRunCancelled)
pipeline-hello-greeting-run-z8np5-task-greeting   23 minutes ago   6 seconds    Succeeded
hello-greeting-run-txvgl-task-greeting            28 minutes ago   26 seconds   Succeeded
hello-greeting-run-pkfr4-task-greeting            28 minutes ago   24 seconds   Succeeded
hello-greeting-run-z664z-task-greeting            28 minutes ago   18 seconds   Succeeded
hello-greeting-run-7wnhq-task-greeting            28 minutes ago   18 seconds   Succeeded
hello-greeting-run-spgd6-task-greeting            28 minutes ago   12 seconds   Succeeded
hello-greeting-run-t7hfq-task-greeting            29 minutes ago   15 seconds   Succeeded

logs

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

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

create

ClusterTaskからTaskを作成します。

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

start

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

tkn t start <Task>
❯ tkn t start task-greeting
? Value for param `my-name` of type `string`? (Default is `unknown`) unknown
? Value for param `greet` of type `string`? (Default is `Hello`) Hello
TaskRun started: task-greeting-run-dd7t4

In order to track the TaskRun progress run:
tkn taskrun logs task-greeting-run-dd7t4 -f -n default

delete

Taskを削除します。

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

TaskRun

エイリアス

  • tr
  • taskrun
  • taskruns

list

TaskRunの一覧を表示します。

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

describe

TaskRunの詳細を表示します。

tkn tr describe <TaskRun>
❯ tkn tr describe task-greeting-run-dd7t4
Name:              task-greeting-run-dd7t4
Namespace:         default
Task Ref:          task-greeting
Service Account:   default
Timeout:           1h0m0s
Labels:
 app.kubernetes.io/managed-by=tekton-pipelines
 tekton.dev/task=task-greeting

🌡️  Status

STARTED         DURATION    STATUS
4 minutes ago   6 seconds   Succeeded

📨 Input Resources

 No input resources

📡 Output Resources

 No output resources

⚓ Params

 NAME        VALUE
 ∙ greet     Hello
 ∙ my-name   unknown

📝 Results

 No results

📂 Workspaces

 No workspaces

🦶 Steps

 NAME                      STATUS
 ∙ echo-greeting-my-name   Completed

🚗 Sidecars

No sidecars

logs

TaskRunのログを出力します。

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

cancel

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

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

delete

TaskRunを削除します。

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

TriggerBinding

エイリアス

  • tb
  • triggerbinding
  • triggerbindings

list

TriggerBindingの一覧を表示します。

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

describe

TriggerBindingの詳細を表示します。

tkn tb describe <TriggerBinding>
❯ tkn tb describe hello-greeting-pipeline-binding
Name:        hello-greeting-pipeline-binding
Namespace:   default

⚓ Params

 NAME        VALUE
 ∙ my-name   $(body.name)
 ∙ greet     $(body.greet)

delete

TriggerBindingを削除します。

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

TriggerTemplate

エイリアス

  • tt
  • triggertemplate
  • triggertemplates

list

TriggerTemplateの一覧を表示します。

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

describe

TriggerTemplateの詳細を表示します。

tkn tt describe <TriggerTemplate>
❯ tkn tt describe hello-greeting-pipeline-template
Name:        hello-greeting-pipeline-template
Namespace:   default

⚓ Params

 NAME        DESCRIPTION              DEFAULT VALUE
 ∙ my-name   My name which steps...   unknown
 ∙ greet     Greeting                 Hello

📦 ResourceTemplates

 NAME    GENERATENAME          KIND          APIVERSION
 ∙ ---   hello-greeting-run-   PipelineRun   tekton.dev/v1beta1

delete

TriggerTemplateを削除します。

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

参考

タイトルとURLをコピーしました