Tekton 一个基于K8S的云原生的通用的 CI/CD 工具,最近闲来无事研究了一下,先说一下安装流程,由于使用的镜像都部署在国外服务器,按照官方的教程是没法正常安装的,所以我事先把使用的镜像都同步到阿里云的镜像服务器了。
使用的前提是已经有一个可用的k8s集群了,可以执行下面的脚本,事先把相关的镜像下载下来。
ocker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:pullrequest-init
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:git-init
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:entrypoint
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:imagedigestexporter
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:kubeconfigwriter
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:nop
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:webhook
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:controller
docker pull registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:dashboard
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:pullrequest-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:entrypoint gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:imagedigestexporter gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:git-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:kubeconfigwriter gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/kubeconfigwriter:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:nop gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:webhook gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:controller gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/controller:v0.27.2
docker tag registry.cn-hangzhou.aliyuncs.com/dushougudu/docker.dushougudu:dashboard gcr.io/tekton-releases/github.com/tektoncd/dashboard/cmd/dashboard:v0.20.0
请务必使用v0.27.2版本的安装yaml 文件,直接执行下面的安装命令,正常情况下就可以安装完成了。
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.27.2/release.yaml
安装完成可以看到tekton运行的pod
然后我们再安装一个tekton的dashbord,大家也可以把文件下载下来,修改一下service的端口映射,可以直接通过ip访问dashbord
kubectl apply -f https://storage.googleapis.com/tekton-releases/dashboard/previous/v0.20.0/tekton-dashboard-release.yaml
增加红色部分的配置
这样就可以直接通过http://nodeip:30097访问dashbord了
下面再给出一个镜像打包发布的完整流程配置,整个流程是从git仓库下载代码,通过kaniko执行相应的dockerfile进行程序的打包,然后把打包好的镜像发布到私有的harbor镜像仓库
kind: ConfigMap
apiVersion: v1
metadata:
name: docker-config
data:
config.json: |
{"auths":{"harbor地址":{"username":"xxx","password":"xxxxx"}}}
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: cnych-res
spec:
type: git
params:
- name: url
value: https://github.com/cnych/tekton-demo
- name: revision
value: master
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-and-push
spec:
resources:
inputs:
- name: repo
type: git
steps:
- name: build-and-push
image: daocloud.io/gcr-mirror/kaniko-project-executor:latest
args: [ "--dockerfile=/workspace/Dockerfile",
"--context=dir://workspace/repo",
"--insecure=true",
"--cache=false",
"--skip-tls-verify=true",
"--destination=harbor地址/项目/tekton-test:v1" ]
volumeMounts:
- name: docker-config
mountPath: /kaniko/.docker
volumes:
- name: docker-config
configMap:
name: docker-config
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: build-push-run
spec:
taskRef:
name: build-and-push
resources:
inputs:
- name: repo
resourceRef:
name: cnych-res
上面只需要把harbor的相关地址、用户名和密码配置成自己的就可以了,其他的不需要作修改。这样正常执行完成后,就能看到执行状态是成功的绿色状态。
,