Tekton安装及Hello World

Tekton安装及Hello world

安装

kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml

检查安装的tekton相关的CRD:

kubectl api-resources | grep tekton
clustertasks                                   tekton.dev                     false        ClusterTask
conditions                                     tekton.dev                     true         Condition
pipelineresources                              tekton.dev                     true         PipelineResource
pipelineruns                      pr,prs       tekton.dev                     true         PipelineRun
pipelines                                      tekton.dev                     true         Pipeline
taskruns                          tr,trs       tekton.dev                     true         TaskRun
tasks                                          tekton.dev                     true         Task

tekton的两个pod:

kubectl get pods --namespace tekton-pipelines
NAME                                           READY   STATUS    RESTARTS   AGE
tekton-pipelines-controller-556d8f4494-2qthv   1/1     Running   0          11m
tekton-pipelines-webhook-849cff5cf-8m5qq       1/1     Running   0          11m

安装CLI

cli: https://github.com/tektoncd/cli#installing-tkn

brew install tektoncd-cli

Tekton: hello world

创建一个简单的Task, 只有一个step就是打印出"hello world"

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: echo-hello-world
spec:
  steps:
    - name: echo
      image: alpine
      command:
        - echo
      args:
        - "hello world"

创建一个TaskRun执行上面的Task

apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  name: echo-hello-world-task-run
spec:
  taskRef:
    name: echo-hello-world

运行task:

kubectl apply -f <name-of-file.yaml>

检查TaskRun的输出, 执行命令:

tkn taskrun describe echo-hello-world-task-run
Name:        echo-hello-world-task-run
Namespace:   tekton-pipelines
Task Ref:    echo-hello-world

Status
STARTED          DURATION    STATUS
21 minutes ago   1 minute    Succeeded

Input Resources
No resources

Output Resources
No resources

Params
No params

Steps
NAME   STATUS
echo   Completed

Succeeded状态表示task执行成功.

查看实际的输出, 执行命令:

tkn taskrun logs echo-hello-world-task-run

结果:

[echo] hello world

(转载本站文章请注明作者和出处乱世浮生,请勿用于任何商业用途)

comments powered by Disqus