task和taskrun示例
[root@master 02-tekton-basics]# cat 01-task-hello.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello
spec:
steps:
- name: say-hello
image: alpine:3.15
command: ['/bin/sh']
args: ['-c', 'echo Hello World']
[root@master 02-tekton-basics]# cat 01-taskrun-hello.yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: hello-run-00001
spec:
taskRef:
kind: Task
name: hello
[root@master 02-tekton-basics]# kubectl apply -f 01-task-hello.yaml -f 01-taskrun-hello.yaml
task.tekton.dev/hello configured
taskrun.tekton.dev/hello-run-00001 created
task和taskrun示例
[root@master 02-tekton-basics]# kubectl apply -f 02-task-with-params.yaml
task.tekton.dev/hello-params created
[root@master 02-tekton-basics]# cat 02-task-with-params.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello-params
spec:
params:
- name: target
type: string
description: Name of somebody or something to greet
default: Yang
steps:
- name: say-hello
image: alpine:3.15
command:
- /bin/sh
args: ['-c', 'echo Hello $(params.target)']
[root@master 02-tekton-basics]# tkn task start hello-params --showlog
? Value for param `target` of type `string`? (Default is `Yang`) Yang
TaskRun started: hello-params-run-lqnz5
Waiting for logs to be available...
[say-hello] Hello Yang
[root@master 02-tekton-basics]# tkn task start hello-params --showlog -p target=Tekton
TaskRun started: hello-params-run-l782c
Waiting for logs to be available...
[say-hello] Hello Tekton
task定义多个step方法
[root@master 02-tekton-basics]# kubectl apply -f 03-task-multi-steps.yaml
task.tekton.dev/multiple created
[root@master 02-tekton-basics]# cat 03-task-multi-steps.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: multiple
spec:
steps:
- name: first
image: alpine:3.15
command:
- /bin/sh
args: ['-c', 'echo First Step']
- name: second
image: alpine:3.15
command:
- /bin/sh
args: ['-c', 'echo Second Step']
[root@master 02-tekton-basics]# tkn task start multiple --showlog
TaskRun started: multiple-run-lghg2
Waiting for logs to be available...
[first] First Step
[second] Second Step
task step定义多行
[root@master 02-tekton-basics]# cat 04-task-step-with-script.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: script
spec:
steps:
- name: step-with-script
image: alpine:3.15
script: |
#!/bin/sh
echo "Step with Script..."
echo "Installing necessary tooling"
apk add curl
curl -s www.baidu.com && echo "Success" || echo "Fail"
echo "All done!"
[root@master 02-tekton-basics]# kubectl apply -f 04-task-step-with-script.yaml
task.tekton.dev/script created
[root@master 02-tekton-basics]# tkn task start script --showlog
TaskRun started: script-run-fflhs
Waiting for logs to be available...
[step-with-script] Step with Script...
[step-with-script] Installing necessary tooling
[step-with-script] fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
[step-with-script] fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
[step-with-script] (1/5) Installing ca-certificates (20220614-r0)
[step-with-script] (2/5) Installing brotli-libs (1.0.9-r5)
[step-with-script] (3/5) Installing nghttp2-libs (1.46.0-r0)
[step-with-script] (4/5) Installing libcurl (7.80.0-r3)
[step-with-script] (5/5) Installing curl (7.80.0-r3)
[step-with-script] Executing busybox-1.34.1-r7.trigger
[step-with-script] Executing ca-certificates-20220614-r0.trigger
[step-with-script] OK: 8 MiB in 19 packages
[step-with-script] <!DOCTYPE html>
[step-with-script] <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
[step-with-script] Success
[step-with-script] All done!
task脚本和参数结合使用
[root@master 02-tekton-basics]# tkn task start logger --showlog -p text="TaskRun finished"
TaskRun started: logger-run-mpjnr
Waiting for logs to be available...
[log] [2022-10-26 16:59:48] - TaskRun finished
[root@master 02-tekton-basics]# cat 05-task-script-and-parameters.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: logger
spec:
params:
- name: text
type: string
description: something to log
default: "-"
steps:
- name: log
image: alpine:3.15
script: |
apk add -q tzdata
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
DATETIME=$(date "+%F %T")
echo [$DATETIME] - $(params.text)
定义pipeline并引用task hello和multiple,runAfter会先运行,如果注释掉runAfter两个task会同时运行
[root@master 02-tekton-basics]# cat 06-pipeline-demo.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: pipeline-demo
spec:
tasks:
- name: first-task
taskRef:
name: hello
- name: second-task
taskRef:
name: multiple
runAfter:
- first-task
[root@master 02-tekton-basics]# kubectl apply -f 06-pipeline-demo.yaml
pipeline.tekton.dev/pipeline-demo created
[root@master 02-tekton-basics]# tkn pipeline start pipeline-demo --showlog
PipelineRun started: pipeline-demo-run-6l4v8
Waiting for logs to be available...
[first-task : say-hello] Hello World
[second-task : first] First Step
[second-task : second] Second Step
标签:task,name,script,基础,tekton,step,hello From: https://www.cnblogs.com/zyyang1993/p/16829030.html