部署Tekton

官方文档

https://tekton.dev/docs/getting-started/tasks/

安装tekton pipelines,会有两个报错

[root@master ~]# kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
namespace/tekton-pipelines created
clusterrole.rbac.authorization.k8s.io/tekton-pipelines-controller-cluster-access created
clusterrole.rbac.authorization.k8s.io/tekton-pipelines-controller-tenant-access created
clusterrole.rbac.authorization.k8s.io/tekton-pipelines-webhook-cluster-access created
role.rbac.authorization.k8s.io/tekton-pipelines-controller created
role.rbac.authorization.k8s.io/tekton-pipelines-webhook created
role.rbac.authorization.k8s.io/tekton-pipelines-leader-election created
role.rbac.authorization.k8s.io/tekton-pipelines-info created
serviceaccount/tekton-pipelines-controller created
serviceaccount/tekton-pipelines-webhook created
clusterrolebinding.rbac.authorization.k8s.io/tekton-pipelines-controller-cluster-access created
clusterrolebinding.rbac.authorization.k8s.io/tekton-pipelines-controller-tenant-access created
clusterrolebinding.rbac.authorization.k8s.io/tekton-pipelines-webhook-cluster-access created
rolebinding.rbac.authorization.k8s.io/tekton-pipelines-controller created
rolebinding.rbac.authorization.k8s.io/tekton-pipelines-webhook created
rolebinding.rbac.authorization.k8s.io/tekton-pipelines-controller-leaderelection created
rolebinding.rbac.authorization.k8s.io/tekton-pipelines-webhook-leaderelection created
rolebinding.rbac.authorization.k8s.io/tekton-pipelines-info created
customresourcedefinition.apiextensions.k8s.io/clustertasks.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/pipelines.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/pipelineruns.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/resolutionrequests.resolution.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/pipelineresources.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/runs.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/tasks.tekton.dev created
customresourcedefinition.apiextensions.k8s.io/taskruns.tekton.dev created
secret/webhook-certs created
validatingwebhookconfiguration.admissionregistration.k8s.io/validation.webhook.pipeline.tekton.dev created
mutatingwebhookconfiguration.admissionregistration.k8s.io/webhook.pipeline.tekton.dev created
validatingwebhookconfiguration.admissionregistration.k8s.io/config.webhook.pipeline.tekton.dev created
clusterrole.rbac.authorization.k8s.io/tekton-aggregate-edit created
clusterrole.rbac.authorization.k8s.io/tekton-aggregate-view created
configmap/config-artifact-bucket created
configmap/config-artifact-pvc created
configmap/config-defaults created
configmap/feature-flags created
configmap/pipelines-info created
configmap/config-leader-election created
configmap/config-logging created
configmap/config-observability created
configmap/config-registry-cert created
deployment.apps/tekton-pipelines-controller created
service/tekton-pipelines-controller created
deployment.apps/tekton-pipelines-webhook created
service/tekton-pipelines-webhook created
resource mapping not found for name: "tekton-pipelines" namespace: "" from "https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml": no matches for kind "PodSecurityPolicy" in version "policy/v1beta1"
ensure CRDs are installed first
resource mapping not found for name: "tekton-pipelines-webhook" namespace: "tekton-pipelines" from "https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml": no matches for kind "HorizontalPodAutoscaler" in version "autoscaling/v2beta1"
ensure CRDs are installed first

 把文件下载到本地修改,apply之后还有一个错误先忽略

[root@master ~]# curl -OL https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
[root@master ~]# vim release.yaml
[root@master ~]# kubectl apply -f release.yaml

[root@master ~]# kubectl get pods --namespace tekton-pipelines --watch
NAME                                          READY   STATUS    RESTARTS   AGE
tekton-pipelines-controller-d98cb8d45-plhvv   1/1     Running   0          5m20s
tekton-pipelines-webhook-76ffbff7bf-9j5fw     1/1     Running   0          5m20s

测试

部署task

[root@master tmp]# cat task-hello-word.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: hello
spec:
  steps:
    - name: echo
      image: alpine:3.16
      script: |
        #!/bin/sh
        echo "Hello World"
[root@master tmp]# kubectl apply -f task-hello-word.yaml 
task.tekton.dev/hello created
[root@master tmp]# kubectl get tasks
NAME    AGE
hello   5s

部署taskrun,会启动一个pod

[root@master tmp]# cat taskrun-hello-word.yaml 
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: hello-task-run
spec:
  taskRef:
    name: hello
[root@master tmp]# kubectl apply -f taskrun-hello-word.yaml 

[root@master tmp]# kubectl get pods
NAME                 READY   STATUS            RESTARTS   AGE
hello-task-run-pod   0/1     PodInitializing   0          3s
[root@master tmp]# kubectl get pods
NAME                 READY   STATUS      RESTARTS   AGE
hello-task-run-pod   0/1     Completed   0          2s


[root@master tmp]# kubectl logs hello-task-run-pod
Defaulted container "step-echo" out of: step-echo, prepare (init), place-scripts (init)
Hello World

安装CLI

[root@master ~]# wget https://github.com/tektoncd/cli/releases/download/v0.27.0/tektoncd-cli-0.27.0_Linux-64bit.rpm
[root@master ~]# yum localinstall tektoncd-cli-0.27.0_Linux-64bit.rpm -y
[root@master ~]# tkn version
Client version: 0.27.0
Pipeline version: v0.40.2

部署goodbye task 

[root@master ~]# cat goodbye-task.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: goodbye
spec:
  params:
  - name: username
    type: string
  steps:
    - name: goodbye
      image: ubuntu
      script: |
        #!/bin/bash
        echo "Goodbye $(params.username)!" 
[root@master ~]# kubectl get tasks
NAME      AGE
goodbye   5s
hello     9m23s

部署goodbye pipeline

[root@master ~]# kubectl apply -f hello-goodbye-pipeline.yaml 
pipeline.tekton.dev/hello-goodbye created
[root@master ~]# kubectl get pipelines
NAME            AGE
hello-goodbye   17s
[root@master ~]# cat hello-goodbye-pipeline.yaml 
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: hello-goodbye
spec:
  params:
  - name: username
    type: string
  tasks:
    - name: hello
      taskRef:
        name: hello
    - name: goodbye
      runAfter:
        - hello
      taskRef:
        name: goodbye
      params:
      - name: username
        value: $(params.username)

部署goodbye-pipelinerun

[root@master ~]# cat hello-goodbye-pipeline-run.yaml 
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: hello-goodbye-run
spec:
  pipelineRef:
    name: hello-goodbye
  params:
  - name: username
    value: "Tekton"
[root@master ~]# kubectl apply -f hello-goodbye-pipeline-run.yaml
[root@master ~]# kubectl get pods
NAME                            READY   STATUS      RESTARTS   AGE
hello-goodbye-run-goodbye-pod   0/1     Completed   0          19s
hello-goodbye-run-hello-pod     0/1     Completed   0          24s
hello-task-run-pod              0/1     Completed   0          15m

[root@master ~]# tkn pipelinerun logs hello-goodbye-run -f -n default
[hello : echo] Hello World

[goodbye : goodbye] Goodbye Tekton!

[root@master ~]# kubectl get pipelinerun
NAME                SUCCEEDED   REASON      STARTTIME   COMPLETIONTIME
hello-goodbye-run   True        Succeeded   3m          2m42s

tkn命令

[root@master ~]# tkn --help
CLI for tekton pipelines

Usage:
tkn [flags]
tkn [command]

Available Commands:
  bundle                Manage Tekton Bundles
  chain                 Manage Chains
  clustertask           Manage ClusterTasks
  clustertriggerbinding Manage ClusterTriggerBindings
  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.
[root@master ~]# tkn task list
NAME      DESCRIPTION   AGE
goodbye                 9 minutes ago
hello                   19 minutes ago
[root@master ~]# tkn taskrun list
NAME                        STARTED          DURATION   STATUS
hello-goodbye-run-goodbye   3 minutes ago    12s        Succeeded
hello-goodbye-run-hello     3 minutes ago    5s         Succeeded
hello-task-run              19 minutes ago   1s         Succeeded
[root@master ~]# tkn pipeline list
NAME            AGE             LAST RUN            STARTED         DURATION   STATUS
hello-goodbye   7 minutes ago   hello-goodbye-run   4 minutes ago   18s        Succeeded
[root@master ~]# tkn pipelinerun list
NAME                STARTED         DURATION   STATUS
hello-goodbye-run   4 minutes ago   18s        Succeeded
[root@master ~]# tkn taskrun logs hello-goodbye-run-hello 
[echo] Hello World

以交互的方式创建并运行一个新的task

[root@master ~]# tkn task start goodbye --showlog
? Value for param `username` of type `string`? yang
TaskRun started: goodbye-run-6slwq
Waiting for logs to be available...
[goodbye] Goodbye yang!

[root@master ~]# tkn task start goodbye --showlog -p username='Yang.com'
TaskRun started: goodbye-run-vg7j4
Waiting for logs to be available...
[goodbye] Goodbye Yang.com!

[root@master ~]# tkn task list
NAME      DESCRIPTION   AGE
goodbye                 21 minutes ago
hello                   30 minutes ago
[root@master ~]# tkn taskrun list
NAME                        STARTED          DURATION   STATUS
goodbye-run-vg7j4           29 seconds ago   8s         Succeeded
goodbye-run-6slwq           2 minutes ago    8s         Succeeded
hello-goodbye-run-goodbye   15 minutes ago   12s        Succeeded
hello-goodbye-run-hello     15 minutes ago   5s         Succeeded
hello-task-run              30 minutes ago   1s         Succeeded

 部署Dashboard

[root@master ~]# kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/tekton-dashboard-release.yaml
customresourcedefinition.apiextensions.k8s.io/extensions.dashboard.tekton.dev created
serviceaccount/tekton-dashboard created
role.rbac.authorization.k8s.io/tekton-dashboard-info created
clusterrole.rbac.authorization.k8s.io/tekton-dashboard-backend created
clusterrole.rbac.authorization.k8s.io/tekton-dashboard-tenant created
rolebinding.rbac.authorization.k8s.io/tekton-dashboard-info created
clusterrolebinding.rbac.authorization.k8s.io/tekton-dashboard-backend created
configmap/dashboard-info created
service/tekton-dashboard created
deployment.apps/tekton-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/tekton-dashboard-tenant created

[root@master ~]# kubectl get pods -n tekton-pipelines
NAME                                          READY   STATUS    RESTARTS      AGE
tekton-dashboard-7c46cd79d8-rpz22             1/1     Running   0             39s
tekton-pipelines-controller-d98cb8d45-plhvv   1/1     Running   1 (43m ago)   161m
tekton-pipelines-webhook-76ffbff7bf-9j5fw     1/1     Running   1 (43m ago)   161m

[root@master ~]# kubectl get svc -n tekton-pipelines
NAME                          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                              AGE
tekton-dashboard              ClusterIP   10.99.155.210   <none>        9097/TCP                             55s
tekton-pipelines-controller   ClusterIP   10.99.199.216   <none>        9090/TCP,8008/TCP,8080/TCP           162m
tekton-pipelines-webhook      ClusterIP   10.105.229.58   <none>        9090/TCP,8008/TCP,443/TCP,8080/TCP   162m
[root@master ~]# git clone https://github.com/iKubernetes/tekton-and-argocd-in-practise.git
Cloning into 'tekton-and-argocd-in-practise'...
remote: Enumerating objects: 240, done.
remote: Counting objects: 100% (240/240), done.
remote: Compressing objects: 100% (146/146), done.
remote: Total 240 (delta 130), reused 196 (delta 89), pack-reused 0
Receiving objects: 100% (240/240), 121.85 KiB | 0 bytes/s, done.
Resolving deltas: 100% (130/130), done.
[root@master ~]# cd tekton-and-argocd-in-practise/
[root@master tekton-and-argocd-in-practise]# ls
01-deploy-tekton  03-tekton-advanced              05-tekton-triggers  07-argocd-basics  LICENSE         README.md
02-tekton-basics  04-tekton-pipeline-in-practise  06-deploy-argocd    08-argo-rollouts  nfs-csi-driver
[root@master tekton-and-argocd-in-practise]# cd 01-deploy-tekton/
[root@master 01-deploy-tekton]# kubectl get svc -n istio-system
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)                                      AGE
istio-ingressgateway   LoadBalancer   10.110.219.229   10.211.55.30   15021:30657/TCP,80:30216/TCP,443:30877/TCP   58m
istiod                 ClusterIP      10.105.252.240   <none>         15010/TCP,15012/TCP,443/TCP,15014/TCP        58m
[root@master 01-deploy-tekton]# kubectl apply -f 03-virtualservice-tekton-dashboard.yaml 
destinationrule.networking.istio.io/tekton-dashboard created
gateway.networking.istio.io/tekton-dashboard-gateway created
virtualservice.networking.istio.io/tekton-dashboard-virtualservice created
[root@master 01-deploy-tekton]# cat 03-virtualservice-tekton-dashboard.yaml 
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: tekton-dashboard
  namespace: tekton-pipelines
spec:
  host: tekton-dashboard
  trafficPolicy:
    tls:
      mode: DISABLE
---
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: tekton-dashboard-gateway
  namespace: istio-system
spec:
  selector:
    app: istio-ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "tekton.yang.com"
    - "ci.yang.com"
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: tekton-dashboard-virtualservice
  namespace: tekton-pipelines
spec:
  hosts:
  - "tekton.yang.com"
  - "ci.yang.com"
  gateways:
  - istio-system/tekton-dashboard-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: tekton-dashboard
        port:
          number: 9097
---

做好域名解析直接访问

 

posted @ 2022-10-26 16:34  Maniana  阅读(367)  评论(0编辑  收藏  举报