通過Operator準備Tekton環境
- 用戶管理員登錄查看operatorhub中的openshift-pipelines-operator
$ oc describe packagemanifest openshift-pipelines-operator -n openshift-marketplace
- 安裝pipelineoperator。
$ oc apply -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/operator/subscription.yaml
- 查看安裝後的狀態。
$ oc api-resources --api-group=tekton.dev
NAME SHORTNAMES APIGROUP NAMESPACED KIND
clustertasks tekton.dev false ClusterTask
conditions tekton.dev true Condition
eventlisteners el tekton.dev true EventListener
pipelineresources tekton.dev true PipelineResource
pipelineruns pr,prs tekton.dev true PipelineRun
pipelines tekton.dev true Pipeline
taskruns tr,trs tekton.dev true TaskRun
tasks tekton.dev true Task
triggerbindings tb tekton.dev true TriggerBinding
triggertemplates tt tekton.dev true TriggerTemplate
- 驗證當前用戶是否有以下創建資源的權限。
$ oc auth can-i create pipeline.tekton.dev
$ oc auth can-i create Pipeline
$ oc auth can-i create Task
$ oc auth can-i create PipelineResource
$ oc auth can-i create PipelineRun
- 驗證是否有名爲pipeline的serviceaccount
$ oc get serviceaccount pipeline
NAME SECRETS AGE
pipeline 2 4m11s
創建並運行Tekton Pipeline
- 創建一個lab-tekton項目。
$ oc new-project lab-tekton
- 查看項目中已有對象。由於Tekton是運行在集羣級別,因此每個項目都有供其運行的對象。
$ oc get all
NAME AGE
clustertask.tekton.dev/buildah 6m20s
clustertask.tekton.dev/buildah-v0-8-0 6m20s
clustertask.tekton.dev/openshift-client 6m20s
clustertask.tekton.dev/openshift-client-v0-8-0 6m20s
clustertask.tekton.dev/s2i 6m19s
clustertask.tekton.dev/s2i-go 6m18s
clustertask.tekton.dev/s2i-go-v0-8-0 6m18s
clustertask.tekton.dev/s2i-java-11 6m18s
clustertask.tekton.dev/s2i-java-11-v0-8-0 6m17s
clustertask.tekton.dev/s2i-java-8 6m17s
clustertask.tekton.dev/s2i-java-8-v0-8-0 6m16s
clustertask.tekton.dev/s2i-nodejs 6m16s
clustertask.tekton.dev/s2i-nodejs-v0-8-0 6m16s
clustertask.tekton.dev/s2i-python-3 6m15s
clustertask.tekton.dev/s2i-python-3-v0-8-0 6m15s
clustertask.tekton.dev/s2i-v0-8-0 6m19s
- 部署應用依賴的mongodb。
$ oc new-app centos/mongodb-36-centos7 -e MONGODB_USER=admin MONGODB_DATABASE=mongodb MONGODB_PASSWORD=secret MONGODB_ADMIN_PASSWORD=super-secret
- 創建應用所需的資源。
$ oc create -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/sampleapp/sampleapp.yaml
$ oc set env dc/nodejs-ex MONGO_URL="mongodb://admin:secret@mongodb-36-centos7:27017/mongodb"
- 查看應用相關service。
$ oc get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mongodb-36-centos7 ClusterIP 172.30.227.96 <none> 27017/TCP 32s
nodejs-ex ClusterIP 172.30.18.167 <none> 8080/TCP,8443/TCP,8778/TCP 6m54s
- 當前應用狀態
- 創建s2i-nodejs的task
$ oc create -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/tektontasks/s2i-nodejs-task.yaml
- 創建openshift-client的task
$ oc create -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/tektontasks/openshift-client-task.yaml
- 查看tekton的task列表
$ tkn task ls
NAME AGE
openshift-client 35 seconds ago
s2i-nodejs 1 minute ago
- 創建deploy-pipeline的pipeline
$ oc create -f https://github.com/liuxiaoyu-git/learn-katacoda/blob/master/middleware/pipelines/assets/pipeline/deploy-pipeline.yaml
- 查看pipeline列表
$ tkn pipeline ls
NAME AGE LAST RUN STARTED DURATION STATUS
deploy-pipeline 9 seconds ago --- --- --- ---
- 在OpenShift控制檯查看pipeline使用的相關Resources,其中deploy-pipeline會使用到Git和Image資源。
- 創建上面的git資源
$ oc create -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/resources/git-pipeline-resource.yaml
$ tkn resource describe nodejs-ex-git
Name: nodejs-ex-git
Namespace: lab-tekton
PipelineResource Type: git
Params
NAME VALUE
url https://github.com/sclorg/nodejs-ex
Secret Params
No secret params
- 創建image資源。
$ oc create -f https://raw.githubusercontent.com/liuxiaoyu-git/learn-katacoda/master/middleware/pipelines/assets/resources/image-pipeline-resource.yaml
$ tkn resource describe nodejs-ex-image
Name: nodejs-ex-image
Namespace: lab-tekton
PipelineResource Type: image
Params
NAME VALUE
url image-registry.openshift-image-registry.svc:5000/lab-tekton/nodejs-ex:latest
Secret Params
No secret params
- 查看resource列表。
$ tkn resource ls
NAME TYPE DETAILS
nodejs-ex-git git url: https://github.com/sclorg/nodejs-ex
nodejs-ex-image image url: image-registry.openshift-image-registry.svc:5000/lab-tekton/nodejs-ex:latest
- 運行deploy-pipeline,然後查看其運行日誌。
$ tkn pipeline start deploy-pipeline -r app-git=nodejs-ex-git -r app-image=nodejs-ex-image -s pipeline
Pipelinerun started: deploy-pipeline-run-hxvpn
Showing logs...
[build : create-dir-image-jmt46]
...
[build : generate]
...
[build : build]
...
[build : push]
...
[deploy : oc] deploymentconfig.apps.openshift.io/nodejs-ex rolled out
- 在OpenShift控制檯中查看名爲deploy-pipeline的Pipeline的日誌。
- 查看PipelineRun的執行情況。
$ tkn pr ls
NAME STARTED DURATION STATUS
deploy-pipeline-run-vw9vd 9 minutes ago 7 minutes Succeeded
- 在Pipeline完成運行後,可以在OpenShift控制檯的Developer視圖的Toploy中看到nodejs-ex應用是可以訪問的狀態了。