Creating and running a
Pipeline
Pipeline 是一组有序的 task,并且可以共享 inputs 和 outputs,例如 task1 的outputs 可以传递给 task2 作为 inputs
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: lizhe-pipeline
namespace: lizhe
spec:
resources:
- name: source-repo
type: git
- name: web-image
type: image
tasks:
- name: git-clone-and-build-image
taskRef:
name: build-docker-image-from-git-source
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: $(resources.inputs.docker-source.path)/
resources:
inputs:
- name: docker-source
resource: source-repo
outputs:
- name: builtImage
resource: web-image
在使用 run pipeline 之前,需要先给 service account 添加新的 role
在 Tekton Helloworld 中我们使用了名为 tutorial-service 的 service account,这里将继续使用它
如果你不记得我们做了什么也没有关系
来复习一下,首先创建了2个secrets,分别用于 git 和 docker
apiVersion: v1
kind: Secret
metadata:
name: basic-user-pass
namespace: lizhe
annotations:
tekton.dev/git-0: https://github.com # Described below
type: kubernetes.io/basic-auth
stringData:
username: <cleartext username>
password: <cleartext password>
------------------
kubectl create secret docker-registry regcred -n lizhe \
--docker-server=https://index.docker.io/v1/ \
--docker-username=<your-name> \
--docker-password=<your-pword> \
--docker-email=<your-email>
然后使用这两个 secrets 创建 service account
apiVersion: v1
kind: ServiceAccount
metadata:
name: tutorial-service
namespace: lizhe
secrets:
- name: regcred
- name: basic-user-pass
来给它添加新的 role
kubectl create clusterrole tutorial-role \
-n lizhe \
--verb=* \
--resource=deployments,deployments.apps
kubectl create clusterrolebinding tutorial-binding \
-n lizhe \
--clusterrole=tutorial-role \
--serviceaccount=default:tutorial-service
然后尝试 run pipeline
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: lizhe-pipeline-run-1
namespace: lizhe
spec:
serviceAccountName: tutorial-service
pipelineRef:
name: lizhe-pipeline
resources:
- name: source-repo
resourceRef:
name: tektongolang-git
- name: web-image
resourceRef:
name: lizhe-image
上面内容中,需要引用如下资源
启动
等待执行成功