Tekton Dashboard
先給大家看下部署完之後的儀表盤頁面:
Tekton儀表板是Tekton Pipelines基於Web的通用UI。它允許用戶管理和查看Tekton PipelineRun和TaskRun,以及在tekton中創建,執行和完成過程中涉及的資源。它還允許按標籤過濾PipelineRun和TaskRun。本篇將簡單介紹dashboard及其安裝,當然也會將下該工具在開發中的使用。
安裝dashboard
1、所需環境
k8s 1.15以上版本的集羣,我用的1.17,公衆號(南君手記)中有部署k8s集羣的傻瓜教程。
裝好了tekton/pipeline 0.11.3了。
使用的dashboard版本是v0.6.1
2、開始安裝
官方的第一步是:
kubectl apply --filename https://github.com/tektoncd/dashboard/releases/download/v0.6.1/tekton-dashboard-release.yaml
但是裏面的dashboard鏡像是谷歌的,沒翻牆的話拉不下來,建議先把文件下載下來,然後改鏡像爲:
registry.cn-hangzhou.aliyuncs.com/launcher/tektoncd-dashboard:latest
然後因爲我這邊需要前端訪問,最好將裏面service改成nortport。以免麻煩,我直接把yaml寫在下面,你直接運行kubectl apply -f 命令就行
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: extensions.dashboard.tekton.dev
spec:
group: dashboard.tekton.dev
names:
categories:
- tekton
- tekton-dashboard
kind: Extension
plural: extensions
scope: Namespaced
subresources:
status: {}
version: v1alpha1
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: tekton-dashboard
name: tekton-dashboard
namespace: tekton-pipelines
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: tekton-dashboard-minimal
namespace: tekton-pipelines
rules:
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- update
- patch
- apiGroups:
- ""
resources:
- pods
- services
verbs:
- create
- update
- delete
- patch
- apiGroups:
- ""
resources:
- secrets
- configmaps
verbs:
- create
- update
- delete
- apiGroups:
- extensions
- apps
resources:
- deployments
verbs:
- create
- update
- delete
- patch
- apiGroups:
- tekton.dev
resources:
- tasks
- clustertasks
- taskruns
- pipelines
- pipelineruns
- pipelineresources
- conditions
verbs:
- create
- update
- delete
- patch
- apiGroups:
- tekton.dev
resources:
- taskruns/finalizers
- pipelineruns/finalizers
verbs:
- create
- update
- delete
- patch
- apiGroups:
- tekton.dev
resources:
- tasks/status
- clustertasks/status
- taskruns/status
- pipelines/status
- pipelineruns/status
verbs:
- create
- update
- delete
- patch
- apiGroups:
- dashboard.tekton.dev
resources:
- extensions
verbs:
- create
- update
- delete
- patch
- apiGroups:
- triggers.tekton.dev
resources:
- clustertriggerbindings
- eventlisteners
- triggerbindings
- triggertemplates
verbs:
- create
- update
- delete
- patch
- add
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
verbs:
- use
- apiGroups:
- route.openshift.io
resources:
- routes
verbs:
- get
- list
- apiGroups:
- extensions
- apps
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods
- services
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods/log
- namespaces
- events
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- secrets
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- apps
resources:
- deployments
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- tasks
- clustertasks
- taskruns
- pipelines
- pipelineruns
- pipelineresources
- conditions
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- taskruns/finalizers
- pipelineruns/finalizers
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- tasks/status
- clustertasks/status
- taskruns/status
- pipelines/status
- pipelineruns/status
verbs:
- get
- list
- watch
- apiGroups:
- dashboard.tekton.dev
resources:
- extensions
verbs:
- get
- list
- watch
- apiGroups:
- triggers.tekton.dev
resources:
- clustertriggerbindings
- eventlisteners
- triggerbindings
- triggertemplates
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tekton-dashboard-minimal
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tekton-dashboard-minimal
subjects:
- kind: ServiceAccount
name: tekton-dashboard
namespace: tekton-pipelines
---
apiVersion: v1
kind: Service
metadata:
labels:
app: tekton-dashboard
dashboard.tekton.dev/release: v0.6.1
version: v0.6.1
name: tekton-dashboard
namespace: tekton-pipelines
spec:
type: NodePort #不需要暴露服務的話,這行刪去
ports:
- name: http
port: 9097
protocol: TCP
targetPort: 9097
nodePort: 30097 #不需要暴露服務的話,這行刪去
selector:
app: tekton-dashboard
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tekton-dashboard
dashboard.tekton.dev/release: v0.6.1
version: v0.6.1
name: tekton-dashboard
namespace: tekton-pipelines
spec:
replicas: 1
selector:
matchLabels:
app: tekton-dashboard
template:
metadata:
labels:
app: tekton-dashboard
name: tekton-dashboard
spec:
containers:
- env:
- name: PORT
value: "9097"
- name: READ_ONLY
value: "false"
- name: WEB_RESOURCES_DIR
value: /var/run/ko/web
- name: PIPELINE_RUN_SERVICE_ACCOUNT
value: ""
- name: TRIGGERS_NAMESPACE
value: tekton-pipelines
- name: PIPELINE_NAMESPACE
value: tekton-pipelines
- name: INSTALLED_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: seandragon/tekton-dashboard:v0.6.1
livenessProbe:
httpGet:
path: /health
port: 9097
name: tekton-dashboard
ports:
- containerPort: 9097
readinessProbe:
httpGet:
path: /readiness
port: 9097
serviceAccountName: tekton-dashboard
---
運行完後,去看下pod運行,要都是running的就算成功了。
kubectl get po -n tekton-pipelines
NAME READY STATUS RESTARTS AGE
tekton-dashboard-6cc7c565d9-zhd8x 1/1 Running 0 75m
tekton-pipelines-controller-7cf5f4f87f-xk72r 1/1 Running 0 5h27m
tekton-pipelines-webhook-7bc6fc7d4b-j92lc 1/1 Running 0 5h27m
瀏覽器訪問http://masterIp:30097/
就有頁面彈出來的。安裝到此結束
介紹
儀表盤主要功能就是爲taskRun和pipelineRuns提供視圖管理界面,同時,你可以看到與taskRun和pipelineRuns相關聯的資源的創建和執行過程。你可以看到所有命名空間下的資源。在我看來最主要的一個用途就是可以看到task的執行結果,哪個步驟報了什麼錯都能一目瞭然。
下面我運行一個簡單的例子,看一下效果;
下面跑個taskrun看下:(這個taskrun只是做一些簡單的打印任務)
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: step-scripti
spec:
taskSpec:
params:
- name: PARAM
default: param-value
steps:
- name: noshebang
image: ubuntu
script: echo "no shebang"
- name: bash
image: ubuntu
env:
- name: FOO
value: foooooooo
script: |
#!/usr/bin/env bash
set -euxo pipefail
echo "Hello from Bash!"
echo FOO is ${FOO}
echo substring is ${FOO:2:4}
for i in {1..10}; do
echo line $i
done
- name: place-file
image: ubuntu
script: |
#!/usr/bin/env bash
echo "echo Hello from script file" > /workspace/hello
chmod +x /workspace/hello
- name: run-file
image: ubuntu
script: |
#!/usr/bin/env bash
/workspace/hello
- name: contains-eof
image: ubuntu
script: |
#!/usr/bin/env bash
cat > file << EOF
this file has some contents
EOF
cat file
- name: node
image: node
script: |
#!/usr/bin/env node
console.log("Hello from Node!")
- name: python
image: python
script: |
#!/usr/bin/env python3
print("Hello from Python!")
- name: perl
image: perl
script: |
#!/usr/bin/perl
print "Hello from Perl!"
# Test that param values are replaced.
- name: params-applied
image: python
script: |
#!/usr/bin/env python3
v = '$(params.PARAM)'
if v != 'param-value':
print('Param values not applied')
print('Got: ', v)
exit(1)
# Test that args are allowed and passed to the script as expected.
- name: args-allowed
image: ubuntu
args: ['hello', 'world']
script: |
#!/usr/bin/env bash
[[ $# == 2 ]]
[[ $1 == "hello" ]]
[[ $2 == "world" ]]
運行結果如下:
開發使用
對於dashboard的使用場景,我覺得除了展示一些tekton中的資源外,還可以用於獲取任務的狀態、日誌信息,有些私有云中搭建自己的流水線,也是需要執行過程的信息輸出的,和dashboard是一樣的,這邊人家已經封裝好數據了使用起來會比較方便。