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
1.6k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
KubernetesのマニフェストをそれなりにCIしたい
CircleCI ユーザーコミュニティミートアップ #2
stormcat24
December 10, 2019
More Decks by stormcat24
See All by stormcat24
素早く賢く失敗するDeveloper Productivityの実現を目指して
stormcat24
4
5.4k
令和時代のSaaS開発
stormcat24
1
350
History in 5 years of CircleCI and CyberAgent
stormcat24
3
910
Kubernetes Handson Osaka
stormcat24
5
640
Kubernetes Handson
stormcat24
5
4.5k
DockerとKubernetesでアプリケーション開発にコンテナをフル活用!
stormcat24
0
390
Base Image Journey 2018
stormcat24
30
140k
kotlin-fest
stormcat24
13
19k
Kotlin/Native
stormcat24
0
1.1k
Other Decks in Programming
See All in Programming
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
スマートグラスで並列バイブコーディング
hyshu
0
230
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
110
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
720
Lessons from Spec-Driven Development
simas
PRO
0
210
RTSPクライアントを自作してみた話
simotin13
0
620
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.8k
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
150
CSC307 Lecture 17
javiergs
PRO
0
320
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Paper Plane (Part 1)
katiecoart
PRO
0
9.1k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
350
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Between Models and Reality
mayunak
4
340
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
720
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Statistics for Hackers
jakevdp
799
230k
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 で全てのリソースを展開することが難しい
おわり