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.2k
KubernetesのマニフェストをそれなりにCIしたい
CircleCI ユーザーコミュニティミートアップ #2
stormcat24
December 10, 2019
Tweet
Share
More Decks by stormcat24
See All by stormcat24
素早く賢く失敗するDeveloper Productivityの実現を目指して
stormcat24
4
4.4k
令和時代のSaaS開発
stormcat24
1
240
History in 5 years of CircleCI and CyberAgent
stormcat24
3
800
Kubernetes Handson Osaka
stormcat24
5
540
Kubernetes Handson
stormcat24
5
4.2k
DockerとKubernetesでアプリケーション開発にコンテナをフル活用!
stormcat24
0
290
Base Image Journey 2018
stormcat24
29
130k
kotlin-fest
stormcat24
13
17k
Kotlin/Native
stormcat24
0
940
Other Decks in Programming
See All in Programming
Debugging: A Few Things You Should Know
jmatsu
1
130
CSC509 Lecture 04
javiergs
PRO
0
160
【YAPC::Hakodate 2024】TypeScriptエンジニアが感じたPerlのここが面白い
kimitashoichi
1
460
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
200
Hi, have you met Kotlin Multiplatform? | DevFest Vienna 2024
prof18
0
220
自分だけの世界を創るクリエイティブコーディング / Creative Coding: Creating Your Own World
chobishiba
2
2k
CSC509 Lecture 07
javiergs
PRO
0
130
NEWTにおけるiOS18対応の進め方
ryu1sazae
0
330
rtcamp 10 (vk-illuminati)
yumcyawiz
1
210
(Deep|Web) Link support with expo-router
mrtry
0
190
2024-10-01 dev2next - Observability for Modern JVM Applications
jonatan_ivanov
1
140
データマイグレーションの成功戦略~サービスリニューアルで失敗しないための実践ガイド~
tkzwtks
8
840
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.6k
Music & Morning Musume
bryan
46
6.1k
Typedesign – Prime Four
hannesfritz
39
2.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.8k
Faster Mobile Websites
deanohume
304
30k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
330
Building Adaptive Systems
keathley
38
2.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
Side Projects
sachag
452
42k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
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 で全てのリソースを展開することが難しい
おわり