Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
KubernetesのマニフェストをそれなりにCIしたい
Search
stormcat24
December 10, 2019
Programming
4
1.5k
KubernetesのマニフェストをそれなりにCIしたい
CircleCI ユーザーコミュニティミートアップ #2
stormcat24
December 10, 2019
Tweet
Share
More Decks by stormcat24
See All by stormcat24
素早く賢く失敗するDeveloper Productivityの実現を目指して
stormcat24
4
5.2k
令和時代のSaaS開発
stormcat24
1
310
History in 5 years of CircleCI and CyberAgent
stormcat24
3
880
Kubernetes Handson Osaka
stormcat24
5
610
Kubernetes Handson
stormcat24
5
4.4k
DockerとKubernetesでアプリケーション開発にコンテナをフル活用!
stormcat24
0
360
Base Image Journey 2018
stormcat24
29
140k
kotlin-fest
stormcat24
13
18k
Kotlin/Native
stormcat24
0
1.1k
Other Decks in Programming
See All in Programming
SQL Server 2025 LT
odashinsuke
0
140
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.3k
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
130
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
4
690
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
2
280
GoLab2025 Recap
kuro_kurorrr
0
3.6k
Patterns of Patterns
denyspoltorak
0
430
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
150
CSC307 Lecture 03
javiergs
PRO
1
470
Cap'n Webについて
yusukebe
0
160
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
320
Deno Tunnel を使ってみた話
kamekyame
0
320
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
410
The Language of Interfaces
destraynor
162
26k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
190
Embracing the Ebb and Flow
colly
88
4.9k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
110
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
63
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
280
Become a Pro
speakerdeck
PRO
31
5.8k
My Coaching Mixtape
mlcsv
0
23
Design in an AI World
tapps
0
120
Transcript
Kubernetesのマニフェストを それなりにCIしたい CircleCI User Community Meetup #2 Osaka @stormcat24
whois ‣ CyberAgent, Inc. ‣ Backend Engineer ‣ OpenSaaS Studio
Tech Lead ‣ Docker/Kubernetes 実践コンテナ開発入門 Akinori Yamada stormcat24
book 1万部突破ベストセラー Docker/Kubernetes 実践コンテナ開発入門 (技術評論社) ※CircleCIについても触れています
この後、紀伊國屋書店へGo
場所提供をしたので 喋ることにしました
Kubernetesでの アプリケーション開発
予備知識:Pod Pod Dockerコンテナの集合体 nginx api
Podを複製 Deployment ReplicaSet Pod Pod Pod 予備知識:Deployment ReplicaSetの世代管理 基本的に、開発者はアプリケーションの デプロイ定義として、Deploymentリソースを定義・管理します
apiVersion: apps/v1 kind: Deployment metadata: name: echo labels: app: echo
spec: replicas: 3 selector: matchLabels: app: echo template: metadata: labels: app: echo spec: containers: - name: echo image: gcr.io/your-organization/your-service:v0.0.1-01-g39f376a env: - name: HOGE value: fuga ports: - containerPort: 8080 マニフェストファイル deployment.yaml ※マニフェストファイルを Kubernetesクラスタに適用=デプロイ
Kubernetesにおける CI/CD
CIとCDは明確に分離し、 GitOpsなスタイルが潮流 アプリケーション リポジトリ デリバリ用リポジトリ ※Kubernetesの マニフェストファイル群を置く
CDの手法は色々ある ‣ CircleCIからkubectl ‣ Spinnaker ‣ ArgoCD ‣ Flux CD
‣ ローカルから直接kubectl
GitOpsスタイルのCD デリバリ用リポジトリ ≒ リポジトリへの変更がクラスタへのデプロイ 事実上、クラスタ操作をPRで行うことになる
CI CD ユニットテスト アプリケーションビルド Dockerイメージビルド DockerレジストリへPush クラスタの状態をsync マニフェストをクラスタに反映
課題感
CI CD ユニットテスト アプリケーションビルド Dockerイメージビルド DockerレジストリへPush クラスタの状態をsync マニフェストをクラスタに反映 マニフェストの検証が なされずに反映
apiVersion: apps/v1 kind: Deployment metadata: name: echo labels: app: echo
spec: replicas: 3 selector: matchLabels: app: echo template: metadata: labels: app: echo spec: containers: - name: echo image: gcr.io/your-organization/your-service:v0.0.1-01-g39f376a env: - name: HOGE value: fuga ports: - containerPort: 8080 PRでの人力レビューには限界がある
アプリケーションは ユニットテストを含め検証の手法が豊富
マニフェストファイルもそうあるべきでは?
+
kind = Kubernetes in Docker CircleCI上に Kubernetesクラスタを構築できる
version: 2 jobs: kind: machine: image: circleci/classic:201808-01 steps: - checkout
- run: name: Install kubernetes cluster with kind command: | curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.6.1/kind- linux-amd64 chmod +x kind sudo mv kind /usr/local/bin - run: name: Start cluster command: | kind create cluster --name test-cluster --image kindest/node:v1.14.9 - run: name: Waiting for ready command: | READY="" while [ "$READY" != "True" ] do sleep 2 READY=`kubectl get node -o=jsonpath='{range .items[*]}{range @.status.conditions[? (@.type == "Ready")]}{@.status}{end}{end}'` done echo "Node is ready" echo "Current running pods are the follows:" kubectl get --all-namespaces pod machineモードで kindインストール クラスタ起動 クラスタ起動待ち
クラスタ起動
これでCircleCIの中で Kubernetesクラスタに いろいろできる
考えられるワークロード ‣ マニフェストの反映でエラーでないかチェック ‣ 実行時エラー確認 ‣ マニフェスト反映 → クラスタに対してE2Eテストの実行 ‣
マニフェストの妥当性のチェック ‣ Open Policy Agent(OPA) / gatekeeper ‣ 必須なlabelやannotationのチェック ‣ イメージや環境変数のチェック etc
CI (CDのCIと)CD ユニットテスト アプリケーションビルド Dockerイメージビルド DockerレジストリへPush クラスタの状態をsync マニフェストをクラスタに反映 マニフェスト妥当性チェック ※これからはCDのCIが大事
まとめ ‣ CircleCI + kindで気軽に揮発的なKubernetesクラスタが作れる ‣ OPAやgatekeeperで、制約を設けることでPRレビューで漏れがちなミ スをチェックしやすくなる ‣ GitOpsの推進と、デプロイの心理的安全性の確保
‣ アプリケーションが巨大(マイクロサービスとか)になると、CircleCI で全てのリソースを展開することが難しい
おわり