Modern CI/CD with
Tekton and Prow
Automated via Jenkins
X
Kubernetes Meetup #20
@jyoshise
Slide:
https://static.sched.com/hosted_files/kccnceu1
9/98/Modern%20CI_CD%20with%20Tekton%
20and%20Prow%20Automated%20via%20Je
nkins%20X.pdf
Video:
https://www.youtube.com/watch?v=4EyTGYB
7GvA
whoami
3
• Junichi Yoshise / 吉瀬 淳一
• @jyoshise
• Chief Architect,
Cloud Native Computing
• Hewlett Packard Enterprise
4
私のふだんの仕事によくあるパターン
DevOpsの見積もりをください。
コンテナの。
( ゚Д゚)ざっくりしてんな!
「DevOpsがやりたい」とエンタープライズなお客さん(インフラ/
運用部門)が言ったとき
• だいたい以下のようなことを意味している
• インフラ構築の手間を減らしたい
→コンテナで解決するんでしょ?
• アプリケーションリリースの手間を減らしたい
→CI/CDで解決するんでしょ?(開発ベンダーはCIやってるみたいだけど)
• クラウドネイティブっぽいことがやりたい
→時代はクラウドネイティブなんでしょ?
• というわけで、「クラウド Kubernetesネイティブな、コンテナア
プリケーションのCI/CD」の検討が始まる
• やっぱ違うね、となることもしばしば
CI/CDのざっくりイメージ
Code Build/UT IT Deploy
Continuous
Stage
レガシーなCI/CD
さすがにGit
(SVNとかまだ
見るけど)
ビルドサーバー
でMavenとか
ステージング環
境でテスト実行
本番環境のアプ
リケーション
サーバーにデプ
ロイ
Code Build/UT IT Deploy
Continuous
Stage
ステージング環
境のアプリケー
ションサーバー
にデプロイ
• Artifact
• Trigger
Continuous Delivery Foundation
• The Linux Foundationの下位組織(CNCFと横並び)として2019年3月に発足
• 夢はCI/CDのAPI標準化
• https://cd.foundation
Continuous Delivery Summit
Presentations:
https://github.com/cdfoundation/present
ations/tree/master/2019-summit-
barcelona
Video:
https://www.youtube.com/watch?v=P7h
FpbAJNVY&list=PL2KXbZ9-
EY9RB8bVvmiSOqB39eNMs-fAe
CI/CDツールの生まれた時代
11
2011 2015 2018 2019
オンプレベアメタル/仮想マシン
クラウド仮想マシン
コンテナ
Kubernetes
Kubernetes Nativeであることとは
• あらゆるプロセスはコンテナとして実行できる
• オブジェクトはDeclarative(宣言的)に記述される
• 状態の変更は拡張可能なKubernetes APIを通じて行われる
レガシーなCI/CD
さすがにGit
(SVNとかまだ
見るけど)
ビルドサーバー
でMavenとか
ステージング環
境でテスト実行
本番環境のアプ
リケーション
サーバーにデプ
ロイ
Code Build/UT IT Deploy
Continuous
Stage
ステージング環
境のアプリケー
ションサーバー
にデプロイ
• Artifact
• Trigger
Kubernetes NativeなCI/CD
さすがにGit
(SVNとかまだ
見るけど)
ビルドサーバー
でMavenとか
ステージング環
境でテスト実行
本番環境のアプ
リケーション
サーバーにデプ
ロイ
Code Build/UT IT Deploy
Continuous
Stage
ステージング環
境のアプリケー
ションサーバー
にデプロイ
• Artifact
• Trigger
• Source Repo
• Dockerfile / Docker Image
• Kubernetes Manifest /
Template
• 各タスクをKubernetes上で(それぞれのタスクに特
化したコンテナとして)実行
• スケール、ログ、認証などはKubernetesエコシステ
ムを利用
• Eventing (webhook)
• Kube API
突然ですがGitOpsについて
• GitOps とは
• Desired Stateを全てコードとして、Git Repositoryで管理する
• Git Repository上の状態と実環境の状態は常に一致させる(Continuous
Deployment)
•そのためのツールは必要
• 変更はGit Repositoryに対するPull Request → Merge
• 実環境上でコマンドを叩くオペレーションは原則禁止
• 状態定義がDeclarativeにできることが前提
• Kubernetesに最適(みんな大好きYAML)
15
各レイヤーでのGitOpsが考えられる
• アプリのGitOps
• Pod, Service
• いわゆるCI/CD
• インフラのGitOps
• Ingress Controller, 共通の
Operator/CRD(Rook, Prometheus)など
• secretは除く
• そもそもKubernetes自体
• CI/CDパイプラインのGitOps
• Pipeline as Code
16
Kubernetes NativeなCI/CD
さすがにGit
(SVNとかまだ
見るけど)
ビルドサーバー
でMavenとか
ステージング環
境でテスト実行
本番環境のアプ
リケーション
サーバーにデプ
ロイ
Code Build/UT IT Deploy
Continuous
Stage
ステージング環
境のアプリケー
ションサーバー
にデプロイ
• Artifact
• Trigger
• 各タスクをKubernetes上で(それぞれのタスクに特
化したコンテナとして)実行
• スケール、ログ、認証などはKubernetesエコシステ
ムを利用
パイプライン定義も
Kubernetes Object
• Source Repo
• Dockerfile / Docker Image
• Kubernetes Manifest /
Template
• Eventing (webhook)
• Kube API
そこでTektonですよ
• 出身はKnative: Kubernetes上でのPaaS/Serverlessプラットフォームを実現するプロジェクト
18
Knative-build
Knative-serving
Knative-
eventing
Knative-build-
pipeline
https://github.com/tektoncd
tektoncd/pipelineの実体
• Deployment:
• controller
• webhook
• CRD:
• PipelineResource
• Task
• TaskRun
• Pipeline
• PipelineRun
• ClusterTask
19
$ kubectl apply -f https://storage.googleapis.com/tekton-releases/latest/release.yaml
その他サブプロジェクト:
• tektoncd/dashboard
• ダッシュボード(Web UI)
• tektoncd/cli
• tkn(CLI)
• tektoncd/catalog
Example(簡単なPipeline)
imag
e
build
source Dockerfile
Manifest
template
Deploy
Tekton
Manifests
GitHub Repo
Pipeline
DockerHub
kaniko
Manifest
加工
kubectl Kubernetes
Pipeline
Task
PipelineResource
Step
PipelineResource CRD
imag
e
build
source Dockerfile
Manifest
template
Deploy
Tekton
Manifests
GitHub Repo
Pipeline
DockerHub
kaniko
Manifest
加工
kubectl Kubernetes
Pipeline
Task
PipelineResource
Step
PipelineResource CRD
• TaskがInput/Outputとして使うリソース
を定義
• typeは現時点で以下の四つだけ
• git : Gitレポジトリ
• image : コンテナイメージのレジストリ
• cluster : Kubernetesクラスタ
• storage : GCS
22
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: git-tektondemo
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/jyoshise/tekton-
demo-app.git
Task CRD
imag
e
build
source Dockerfile
Manifest
template
Deploy
Tekton
Manifests
GitHub Repo
Pipeline
DockerHub
kaniko
Manifest
加工
kubectl Kubernetes
Pipeline
Task
PipelineResource
Step
Task CRD
• 実行するタスクを定義
• spec.inputs / spec.outputs でタスクの入
力/出力となるリソースの型を指定
• 実際にどのPipelineResourceを使うか
はPipelineRun/TaskRunで実行時に指定
する
• spec.stepsはコンテナのspec
• stepは複数指定可能。順番に実行される
24
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-using-kubectl
spec:
inputs:
resources:
- name: source
type: git
- name: image
type: image
params:
- name: path
description: Path to the manifest to apply
- name: yqArg
description: Arg passed to yq
- name: yamlPathToImage
description:
The path to the image to replace in the yaml manifest (arg
to yq)
steps:
- name: replace-image
image: mikefarah/yq
command: ["yq"]
args:
- "w"
- "-i"
- "${inputs.params.yqArg}"
- "${inputs.params.path}"
- "${inputs.params.yamlPathToImage}"
- "${inputs.resources.image.url}"
- name: run-kubectl
image: lachlanevenson/k8s-kubectl
command: ["kubectl"]
args:
- "apply"
- "-f"
- "${inputs.params.path}"
Catalog
• Taskの見本帳
• Knative-buildプロジェク
トもいずれこちらに統
合されるかも
25
Pipeline CRD
imag
e
build
source Dockerfile
Manifest
template
Deploy
Tekton
Manifests
GitHub Repo
Pipeline
DockerHub
kaniko
Manifest
加工
kubectl Kubernetes
Pipeline
Task
PipelineResource
Step
Pipeline CRD
• パイプラインを定義
• 複数のTaskを並べ、Taskごとにパラメー
ターとinputs/outputsを宣言する
• inputとして前のTaskのoutputを指定する
ことで依存関係が指定できる
27
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: demo-pipeline
spec:
resources:
- name: source-repo
type: git
- name: web-image
type: image
tasks:
- name: build-web
taskRef:
name: build-docker-image-from-git-source
params:
...
- name: deploy-web
taskRef:
name: deploy-using-kubectl
resources:
inputs:
- name: source
resource: source-repo
- name: image
resource: web-image
from:
- build-web
params:
- name: path
value: /workspace/source/manifests/deployment.yaml
- name: yqArg
value: "-d1"
- name: yamlPathToImage
value: "spec.template.spec.containers[0].image"
PipelineRun/TaskRun CRD
• PipelineやTaskを起動するためには、
PipelineRun/TaskRunのオブジェクトを
生成する必要がある
• Event Triggeringがまだ実装されていないた
め
• 権限を要するTaskを実行するには、ここ
でserviceAccountを指定する
• PipelineResourceはここで指定する
28
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: demo-pipeline-run-1
spec:
serviceAccount: build-bot
pipelineRef:
name: demo-pipeline
resources:
- name: source-repo
resourceRef:
name: git-tektondemo
- name: web-image
resourceRef:
name: image-tektondemo
いちおうDashboardもあります
29
Demo
30
Tektonに今のところ足りてないモノ
• Event Triggering
• Log Persistence
• SCM support
• Pipeline Resource / Taskの拡張性
31
Tektonの使い方いろいろ
32https://www.slideshare.net/ChristieWilson3/tekton-showcase-cdf-summit-kubecon-
barcelona-2019
Jenkins X + Prow + Tekton
• Prow https://github.com/kubernetes/test-infra/tree/master/prow
• Kubernetes自体のCI/CDのために開発された
• 各種プラグインによりGitHub上でChatOpsを実現する
• Jenkins X Pipelines (Tekton Mode) https://jenkins-x.io/getting-started/next-gen-
pipeline/
• まだearly work(隠しモード的な)。たぶんGKEでしか動かない
• PipelineはJenkinsfileではなくjenkins-x.yamlで記述される→Tekton Pipelineに内部で変換され
る
• Pipelineの実行はTektonのPipeline Controllerが行う。Jenkins Serverがいらない
• デモは動画見てください!
33
まとめ
34
まとめ
• Kubernetesを拡張してなんでも載せていく方向性としては、Tektonは筋
がいい、なぜなら
• Kubernetesの上で実行するCI/CDパイプラインをKubernetes Nativeに記述できる
• それによってCI/CDパイプラインも宣言的に管理できる
• とはいえ現時点では単体でCI/CDツールとして完結するものではない
• Jenkins Xのように、他ツールがTektonを利用する動きはこれから出てく
るのでは
• なのでTekton流のPipeline as Codeに親しんでおいて損はない
35
Thank You
36

Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes Meetup Tokyo #20