准备k8s集群 1 2 3 4 5 6 7 [[email protected] ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready master 28d v1.19.4 k8s-node01 Ready <none> 28d v1.19.4 k8s-node02 Ready <none> 28d v1.19.4 k8s-node03 Ready <none> 28d v1.19.4 k8s-node04 Ready <none> 28d v1.19.4
安装 1 # kubectl apply --filename https ://storage .googleapis .com /tekton-releases /pipeline /latest /release .yaml
检查安装的tekton相关的CRD
1 2 3 4 5 6 7 8 9 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 runs tekton.dev true Run taskruns tr,trs tekton.dev true TaskRun tasks tekton.dev true Task
查看pod
1 2 3 4 NAME READY STATUS RESTARTS AGEtekton -pipelines-controller-5 cdb46974 f-lfnrs 1 /1 Running 0 6 dtekton -pipelines-webhook-6479 d769 ff-7 ct5 g 1 /1 Running 0 6 d
安装CLI CLI:https://github.com/tektoncd/cli#installing-tkn 我这是centos7操作系统
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # rpm -Uvh https: //github.com /tektoncd/cli/releases/download/v0.14.0 /tektoncd-cli-0.14 .0 _Linux-64 bit.rpm # tkn -h CLI for tekton pipelines Usage: tkn [flags] tkn [command ] Available Commands: clustertask Manage ClusterTasks clustertriggerbinding Manage ClusterTriggerBindings condition Manage Conditions eventlistener Manage EventListeners hub Interact with tekton hub pipeline Manage pipelines pipelinerun Manage PipelineRuns resource Manage pipeline resources task Manage Tasks taskrun Manage TaskRuns triggerbinding Manage TriggerBindings triggertemplate Manage TriggerTemplates Other Commands: completion Prints shell completion scripts version Prints version information Flags: -h, --help help for tkn Use "tkn [command] --help" for more information about a command . https: //github.com /tektoncd/cli#installing-tkn
Tekton:hello world 创建一个简单的Task, 只有一个step就是打印出”hello world”
1 2 3 4 5 6 7 8 9 10 11 12 13 # cat hello_task.yml apiVersion: tekton.dev/v1alpha1kind: Taskmetadata: name: echo-hello-worldspec: steps: - name: echo image: alpine command: - echo args: - "hello world"
创建一个TaskRun执行上面的Task
1 2 3 4 5 6 7 8 # cat hello_task_run.yml apiVersion: tekton.dev/v1alpha1kind: TaskRunmetadata: name: echo-hello-world-task-runspec: taskRef: name: echo-hello-world
运行task
1 2 3 4 5 6 7 8 # kubectl apply -f hello_task.yml task.tekton.dev/echo -hello-world created# kubectl get task NAME AGEecho -hello-world 12 s# tkn task list NAME DESCRIPTION AGEecho -hello-world 1 minute ago
运行一个taskrun
1 2 # kubectl apply -f hello_task_run .yml taskrun .tekton .dev /echo-hello-world-task-run created
检查TaskRun的输出, 执行命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 # tkn taskrun list NAME STARTED DURATION STATUSecho -hello-world-task-run 25 seconds ago 6 seconds Succeeded# kubectl get taskrun NAME SUCCEEDED REASON STARTTIME COMPLETIONTIMEecho -hello-world-task-run True Succeeded 37 s 31 s# kubectl get pod NAME READY STATUS RESTARTS AGEecho -hello-world-task-run-pod-8 xnvb 0 /1 Completed 0 74 s 可以看到有一个pod生成# tkn taskrun describe echo-hello-world-task-run Name : echo -hello-world-task-run Namespace: default Task Ref: echo -hello-world Service Account: default Timeout: 1 h0m0s Labels: app.kubernetes.io/managed-by=tekton-pipelines tekton.dev/task=echo -hello-world Status STARTED DURATION STATUS1 minute ago 6 seconds Succeeded Input Resources No input resources Output Resources No output resources Params No params Results No results Workspaces No workspaces StepsNAME STATUSecho Completed Sidecars No sidecars
Succeeded状态表示task执行成功.
查看实际的输出,执行命令
可以看到结果如下