其他分享
首页 > 其他分享> > 部署Tekton

部署Tekton

作者:互联网

https://tekton.dev https://tekton.dev/docs/getting-started/ 环境要求   ◼ Tekton Pipelines 0.11.0及以上的版本,需要运行于Kubernetes v1.15以上的集群中;   ◼ 集群上要启用了RBAC鉴权插件;   ◼ 拥有管理员权限(绑定到了clusterrole/cluster-admin)的用户; 部署Tekton Pipelines   ◼ 根据Tekton Pipelines项目提供的配置文件完成部署     ◆kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml   ◼ Tekton Pipelines会部署两个controller和webhook两个应用     ◆kubectl get deployments -n tekton-pipelines   ◼ 客户端工具tkn     ◆下载页面:https://github.com/tektoncd/cli/releases     ◆curl -LO https://github.com/tektoncd/cli/releases/download/v0.22.0/tektoncd-cli-0.22.0_Linux-64bit.deb     ◆sudo dpkg -i ./tektoncd-cli-0.22.0_Linux-64bit.deb  
root@master01:~# cat release-image.yaml |grep chuan123
          image: gexuchuan123/tektoncd-pipeline-cmd-controller:v0.33.3
            "-kubeconfig-writer-image", "gexuchuan123/tektoncd-pipeline-cmd-kubeconfigwriter:v0.33.3", "-git-image", "gexuchuan123/tektoncd-pipeline-cmd-git-init:v0.33.3", "-entrypoint-image", "gexuchuan123/tektoncd-pipeline-cmd-entrypoint:v0.33.3", "-nop-image", "gexuchuan123/tektoncd-pipeline-cmd-nop:v0.33.3", "-imagedigest-exporter-image", "gexuchuan123/tektoncd-pipeline-cmd-imagedigestexporter:v0.33.3", "-pr-image", "gexuchuan123/tektoncd-pipeline-cmd-pullrequest-init:v0.33.3", "-workingdirinit-image", "gexuchuan123/tektoncd-pipeline-cmd-workingdirinit:v0.33.3",
            "-gsutil-image", "gexuchuan123/cloudsdktool-cloud-sdk:v1",
            "-shell-image", "gexuchuan123/distroless-base:v1",
          image: gexuchuan123/tektoncd-pipeline-cmd-webhook:v0.33.3

 

root@master01:~# kubectl get po  -ntekton-pipelines
NAME                                           READY   STATUS    RESTARTS   AGE
tekton-pipelines-controller-75c7f75c8d-4jlgx   1/1     Running   0          33s
tekton-pipelines-webhook-5d7b464584-b6gc5      1/1     Running   0          8m9s

 安装生成的资源文件

root@master01:~# kubectl api-resources --api-group=tekton.dev
NAME                SHORTNAMES   APIVERSION            NAMESPACED   KIND
clustertasks                     tekton.dev/v1beta1    false        ClusterTask
conditions                       tekton.dev/v1alpha1   true         Condition
pipelineresources                tekton.dev/v1alpha1   true         PipelineResource
pipelineruns        pr,prs       tekton.dev/v1beta1    true         PipelineRun
pipelines                        tekton.dev/v1beta1    true         Pipeline
runs                             tekton.dev/v1alpha1   true         Run
taskruns            tr,trs       tekton.dev/v1beta1    true         TaskRun
tasks                            tekton.dev/v1beta1    true         Task

tekton-dashboard部署

root@master01:~/aa# cat tekton-dashboard-release-image.yaml |grep chuan
image: gexuchuan123/tektoncd-dashboard-cmd-dashboard:v0.24.1

root@master01:~/aa# kubectl apply --filename tekton-dashboard-release-image.yaml 
kubectl get po -A
tekton-pipelines       tekton-dashboard-796d7f9d69-hngzn              1/1     Running   0          5m8s   10.200.59.200    192.168.80.203   <none>           <none>

 

kubectl edit svc tekton-dashboard     -ntekton-pipelines
  externalIPs:
  - 192.168.80.209
root@master01:~/aa# kubectl get svc -ntekton-pipelines
NAME                          TYPE        CLUSTER-IP       EXTERNAL-IP      PORT(S)                              AGE
tekton-dashboard              ClusterIP   10.100.19.127    192.168.80.209   9097/TCP                             7m

192.168.80.209:9097

部署cli

https://github.com/tektoncd/cli/releases  tektoncd-cli-0.23.0_Linux-64bit.deb  tektoncd-cli-0.23.0_Linux-64bit.rpm

dpkg -i ./tektoncd-cli-0.23.0_Linux-64bit.deb

root@master01:~/aa# tkn version
Client version: 0.23.0
Pipeline version: v0.33.3
Dashboard version: v0.24.1

 

https://tekton.dev/docs/pipelines/tasks/

Defining Steps

git clone https://github.com/iKubernetes/tekton-and-argocd-in-practise.git

root@master01:~/tekton-and-argocd-in-practise/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@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl apply -f 01-task-hello.yaml 
task.tekton.dev/hello created
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl get task
NAME    AGE
hello   8s

root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task --help

https://tekton.dev/docs/pipelines/taskruns/

示例一

root@master01:~/tekton-and-argocd-in-practise/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
docker pull gexuchuan123/tektoncd-pipeline-cmd-entrypoint:v0.33.3
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl get po
NAME                  READY   STATUS    RESTARTS   AGE
hello-run-00001-pod   1/1     Running   0          4s
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl get po
NAME                  READY   STATUS      RESTARTS   AGE
hello-run-00001-pod   0/1     Completed   0          49s
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task logs hello 
Hello World

 

root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start --showlog  hello 
TaskRun started: hello-run-68bm9
Waiting for logs to be available...
[say-hello] Hello World
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn taskrun list
NAME              STARTED          DURATION    STATUS
hello-run-68bm9   57 seconds ago   5 seconds   Succeeded
hello-run-00001   6 minutes ago    6 seconds   Succeeded

示例二

root@master01:~/tekton-and-argocd-in-practise/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: MageEdu.Com
  steps:
    - name: say-hello
      image: alpine:3.15
      command:
        - /bin/sh
      args: ['-c', 'echo Hello $(params.target)']
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start --showlog  hello-params -p target=magedu.com
TaskRun started: hello-params-run-bgc5k
Waiting for logs to be available...
[say-hello] Hello magedu.com
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start --showlog  hello-params -p target=World
TaskRun started: hello-params-run-l9m7s
Waiting for logs to be available...
[say-hello] Hello World
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl get task
NAME           AGE
hello          16m
hello-params   4m36s
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn taskrun list
NAME                     STARTED          DURATION    STATUS
hello-params-run-l9m7s   1 minute ago     5 seconds   Succeeded
hello-params-run-bgc5k   1 minute ago     4 seconds   Succeeded
hello-run-68bm9          11 minutes ago   5 seconds   Succeeded
hello-run-00001          16 minutes ago   6 seconds   Succeeded
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task logs hello-params
? Select taskrun:  [Use arrows to move, type to filter]
> hello-params-run-l9m7s started 2 minutes ago
  hello-params-run-bgc5k started 3 minutes ago

示例三

 

root@master01:~/tekton-and-argocd-in-practise/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@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start multiple

root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn taskrun logs multiple-run-rgf7b -f -n default
[first] First Step

[second] Second Step

示例四

在Step中运行脚本  需要在Step中执行复杂操作时,可以使用“script”直接指定要运行的脚本   ◼ 多行脚本,可以使用“|”启用   ◼ script同command互斥
root@master01:~/tekton-and-argocd-in-practise/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.magedu.com && echo "Success" || echo "Fail" 
        echo "All done!"
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start script --showlog
TaskRun started: script-run-ww6dj
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 (20211220-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-r0)
[step-with-script] (5/5) Installing curl (7.80.0-r0)
[step-with-script] Executing busybox-1.34.1-r3.trigger
[step-with-script] Executing ca-certificates-20211220-r0.trigger
[step-with-script] OK: 8 MiB in 19 packages
[step-with-script] Success
[step-with-script] All done!

示例五

root@master01:~/tekton-and-argocd-in-practise/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)
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn task start --showlog logger -p text="Something happend"
TaskRun started: logger-run-9kjs6
Waiting for logs to be available...
[log] [2022-03-  14:15:21] - Something happen

 示例六 Pipeline,引用两个pipeline

root@master01:~/tekton-and-argocd-in-practise/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@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# kubectl get Pipeline
NAME            AGE
pipeline-demo   74s
root@master01:~/tekton-and-argocd-in-practise/02-tekton-basics# tkn pipeline describe pipeline-demo
Name:        pipeline-demo
Namespace:   default

标签:02,task,tekton,部署,master01,Tekton,root,hello
来源: https://www.cnblogs.com/gxc888/p/16032999.html