Task
Pipeline
containing your Tasks
TaskRun
to instantiate and execute a Task
outside of a Pipeline
PipelineRun
to instantiate and run a Pipeline
containing your Tasks
Task
defines a series of steps
that run in a desired order and complete a set amount of build work. Every Task
runs as a Pod on your Kubernetes cluster with each step
as its own container. For example, the following Task
outputs “Hello World”:Tekton Pipelines is a Kubernetes extension that installs and runs on your Kubernetes cluster. It defines a set of Kubernetes Custom Resources that act as building blocks from which you can assemble CI/CD pipelines. Once installed, Tekton Pipelines becomes available via the Kubernetes CLI (kubectl) and API calls, just like pods and other resources.
Step-task-pipeline
Pipeline Run
Pipeline
Tasks
Steps
Resources
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: git
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/javajon/node-js-tekton
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: build-image-from-source
spec:
inputs:
resources:
- name: git-source
type: git
params:
- name: pathToContext
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: pathToDockerfile
description: The path to the Dockerfile to build
default: Dockerfile
- name: imageUrl
description: value should be like - us.icr.io/test_namespace/builtImageApp
- name: imageTag
description: Tag to apply to the built image
steps:
- name: list-src
image: alpine
command:
- "ls"
args:
- "$(inputs.resources.git-source.path)"
- name: build-and-push
image: gcr.io/kaniko-project/executor
command:
- /kaniko/executor
args:
- "--dockerfile=$(inputs.params.pathToDockerfile)"
- "--destination=$(inputs.params.imageUrl):$(inputs.params.imageTag)"
- "--context=$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/"
- "--insecure"
- "--insecure-pull"
- "--skip-tls-verify"
- "--skip-tls-verify-pull"
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-application
spec:
inputs:
resources:
- name: git-source
type: git
params:
- name: pathToContext
description: The path to the build context, used by Kaniko - within the workspace
default: .
- name: pathToYamlFile
description: The path to the yaml file to deploy within the git source
default: deploy.yaml
- name: imageUrl
description: Url of image repository
default: url
- name: imageTag
description: Tag of the images to be used.
default: "latest"
steps:
- name: update-yaml
image: alpine
command: ["sed"]
args:
- "-i"
- "-e"
- "s;IMAGE;$(inputs.params.imageUrl):$(inputs.params.imageTag);g"
- "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)"
- name: deploy-app
image: lachlanevenson/k8s-kubectl
command: ["kubectl"]
args:
- "apply"
- "-f"
- "$(inputs.resources.git-source.path)/$(inputs.params.pathToContext)/$(inputs.params.pathToYamlFile)"
kubectl apply -f task-test.yaml
kubectl apply -f pipelineresource.yaml
kubectl apply -f taskrun.yaml
查看 TaskRun 资源对象的状态来查看构建状态
kubectl get taskrun
查看pods状态
kubectl get pods
来查看任务运行的过程
kubectl describe pod testrun-pod-mw9bt
查看容器的日志信息来了解任务的执行结果信息
kubectl logs testrun-pod-mw9bt --all-containers
一款功能强大而灵活的 CI/CD 开源的云原生框架
Tekton 的前身是 Knative 项目的 build-pipeline 项目,这个项目是为了给 build 模块增加 pipeline 的功能,但是随着不同的功能加入到 Knative build 模块中,build 模块越来越变得像一个通用的 CI/CD 系统,于是,索性将 build-pipeline 剥离出 Knative,就变成了现在的 Tekton,而 Tekton 也从此致力于提供全功能、标准化的云原生 CI/CD 解决方案
创建一个构建流水线,在流水线中将运行应用程序的单元测试、构建 Docker 镜像然后推送到 Docker Hub
准备:可用的K8S集群,tekton安装
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.14.2/release.yaml
brew install tektoncd-cli
kubectl apply --filename https://storage.googleapis.com/knative-releases/serving/latest/istio.yaml
kubectl label namespace default istio-injection=enabled
kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
这五个概念每一个都是以 CRD 的形式提供服务的
RBAC
工作空间是一种为执行中的管道及其任务提供可用的共享卷的方法。
在pipeline中定义worksapce作为共享卷传递个相关的task。在tekton中定义workspace的用途有以下几点:
piple中可以使用task的运行结果作为其他Task的输入,即task可在执行过程中生成一些result,这些result可用作pipeline后续task中的参数值,此外Tekton将根据输入参数来推断tasks的执行顺序,以确保生成result的task在那些消耗其结果的task之前运行。
EventListener
resource