Tekton安装及Hello world

准备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
# 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
runs tekton.dev true Run
taskruns tr,trs tekton.dev true TaskRun
tasks tekton.dev true Task

查看pod

1
2
3
4
# kubectl get pods --namespace tekton-pipelines
NAME READY STATUS RESTARTS AGE
tekton-pipelines-controller-5cdb46974f-lfnrs 1/1 Running 0 6d
tekton-pipelines-webhook-6479d769ff-7ct5g 1/1 Running 0 6d

安装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-64bit.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/v1alpha1
kind: Task
metadata:
name: echo-hello-world
spec:
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/v1alpha1
kind: TaskRun
metadata:
name: echo-hello-world-task-run
spec:
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 AGE
echo-hello-world 12s
# tkn task list
NAME DESCRIPTION AGE
echo-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 STATUS
echo-hello-world-task-run 25 seconds ago 6 seconds Succeeded
# kubectl get taskrun
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
echo-hello-world-task-run True Succeeded 37s 31s

# kubectl get pod
NAME READY STATUS RESTARTS AGE
echo-hello-world-task-run-pod-8xnvb 0/1 Completed 0 74s

可以看到有一个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: 1h0m0s
Labels:
app.kubernetes.io/managed-by=tekton-pipelines
tekton.dev/task=echo-hello-world

Status

STARTED DURATION STATUS
1 minute ago 6 seconds Succeeded

Input Resources

No input resources

Output Resources

No output resources

Params

No params

Results

No results

Workspaces

No workspaces

Steps

NAME STATUS
echo Completed

Sidecars

No sidecars

Succeeded状态表示task执行成功.

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

1
2
# tkn taskrun logs echo-hello-world-task-run
[echo] hello world

可以看到结果如下

1
[echo] hello world

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!