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
CircleCI & Argo CD による GitOps / GitOps with Cir...
Search
pm11 (Shinichiro Todaka)
August 05, 2019
Programming
3
670
CircleCI & Argo CD による GitOps / GitOps with CircleCI and Argo CD
2019/08/05 デプロイしNight in 福岡の LT 発表内容です
pm11 (Shinichiro Todaka)
August 05, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
イベント駆動で成長して委員会
happymana
1
320
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Quine, Polyglot, 良いコード
qnighy
4
640
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
距離関数を極める! / SESSIONS 2024
gam0022
0
280
Featured
See All Featured
Writing Fast Ruby
sferik
627
61k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Building Applications with DynamoDB
mza
90
6.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Statistics for Hackers
jakevdp
796
220k
4 Signs Your Business is Dying
shpigford
180
21k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
$JSDMF$*"SHP$%ʹΑΔ(JU0QT !QN σϓϩΠ͠/JHIUJOԬ
͡Ίʹ w ࠓ(JU0QTΛ$JSDMF$*ͱ"SHP$%Λ༻͍࣮ͯݱ͠ ͯΈ͍ͨͱࢥ͍·͢ w LVCFSOFUFTͷ֓೦͕ଟʑग़ͯ·͍Γ·͕͢ɺ͋·Γਂ͍ Ͱ͍͟͝·ͤΜ !2
ࣗݾհ w !QNʢ4IJOJDIJSP5PEBLBʣ w גࣜձࣾ"QSFOEFS w ϑϩϯτΤϯυΠϯϑϥΤϯδχΞ w ࡢɺؔ౦ԬҠॅ✈ w
ಘҙδϟϯϧϑϩϯτΤϯυʢ3FBDUʣٴͼɺ"84 ߏ ཧपΓͰ͢ w ࠷ۙLTपΓΛ͔͚͍ͬͯ·͢ w ͱ♨͕͖ !3
(JU0QT
(JU0QTͱ w 8FBWFXPSLT͕ఏএͨ͠$MPVE/BUJWF࣌ʹ͓͚Δ $%ͷ͋Γํ w IUUQTXXXXFBWFXPSLTUFDIOPMPHJFTHJUPQT w (JU3FQP͕ݱঢ়ΠϯϑϥΛө͍ͯ͠Δʢ4JOHMF4PVSDFPG5SVUIʣ w 1VMM3FRVFTUϕʔεͰөΛߦ͏
!5
(JU0QTͱ !6 https://www.slideshare.net/weaveworks/gitops-modern-best-practices-for-high-velocity-app-dev-using-cloud-native-tools
"SHP$%
"SHP$%ͱ w (JU0QTΛ࣮ݱ͢ΔͨΊͷπʔϧ w ,VCFSOFUFTͷͨΊͷએݴతͳ(JU0QTͷͨΊͷσϦόϦʔπʔϧ w ϦϙδτϦΛϙʔϦϯάͯ͠มԽΛݕग़͠·͢ w ଟػೳͰ͢ɻ·͍ͩ͜ͳ͍ͤͯ·ͤΜ !8
https://github.com/cncf/landscape
None
σϞߏங
࡞Δͷ w ߏ w ,VCFSOFUFTΫϥελ w &,4Ͱ࡞ w /HJOYͷJOEFYIUNMΛදࣔ͢ΔΞϓϦέʔγϣϯ w
"SHP$%ͷίϯϙʔωϯτ w (JU)VC w $JSDMF$* w ࢦఆͷλάͰΠϝʔδͷϏϧυ w ͦͷΠϝʔδλάͰNBOJGFTUΛஔ͖͑ɺ13Λ࡞ w 13࡞ʹIVCΛ༻ w ͪͳΈʹ(JU0QTͷຊ࣭Ͱ͋Γ·ͤΜ !12
ߏΠϝʔδ !13 https://www.slideshare.net/weaveworks/gitops-modern-best-practices-for-high-velocity-app-dev-using-cloud-native-tools
ΫϥελΛཱͯΔ $ brew install weaveworks/tap/eksctl $ eksctl version [ℹ] version.Info{BuiltAt:"",
GitCommit:"", GitTag:"0.2.1"} $ eksctl create cluster \ --name sample-cluster \ --region us-west-2 \ --nodes 2 \ --nodes-min 1 \ --nodes-max 2 \ --node-type t2.medium \ --version=1.13 \ --tags environment=test !14
ΞϓϦέʔγϣϯʢ/HJOYʣͷ࡞ $ cat Dockerfile FROM nginx:1.17.2 ADD index.html /usr/share/nginx/html/ EXPOSE
80 CMD nginx -g "daemon off;" $ cat index.html <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> </head> <body> Hello GitOps!! </body> </html> !15
ίϯςφϨδετϦͷ४උ $ aws ecr create-repository \ --repository-name gitops-sample \ --region
us-west-2 !16
$JSDMF$*ͷηοτΞοϓ $ cat .circleci/config.yml orbs: aws-ecr: circleci/
[email protected]
version: 2.1
workflows: build_and_push_image: jobs: - aws-ecr/build-and-push-image: repo: gitops-sample tag: 1.0.0 filters: branches: only: - master !17
$JSDMF$*ͷηοτΞοϓ create_pull_request: docker: - image: circleci/golang:1.11-stretch steps: - checkout
- run: name: Install hub command command: | curl -sSLf https://github.com/github/hub/releases/download/v2.12.3/hub-linux-amd64-2.12.3.tgz | \ tar zxf - --strip-components=1 -C /tmp/ && \ sudo mv /tmp/bin/hub /usr/local/bin/hub - run: name: Replace definition & create a pull request command: | cd /home/circleci/project sed -i -e 's/\(gitops-sample:\)[0-9\.]\+.*$/\11.0.0/g' infra/default/application.yaml export BRANCH=`date "+%Y%m%d-%H%M%S"` git config --global user.email "
[email protected]
" git config --global user.name "CIBot" git checkout --no-track -b ${BRANCH} git commit -am '[ci skip] bump version' hub push origin ${BRANCH} hub pull-request \ --message="Update Image" \ --base=${CIRCLE_PROJECT_USERNAME}:master \ --head=${CIRCLE_PROJECT_USERNAME}:${BRANCH} !18
$JSDMF$*ͷηοτΞοϓ $ cat .circleci/config.yml ... jobs: create_pull_request: ... workflows:
build_and_push_image: jobs: - aws-ecr/build-and-push-image: ... - create_pull_request: requires: - aws-ecr/build-and-push-image filters: branches: only: - master !19
$JSDMF$*ͷηοτΞοϓ AWS_ECR_ACCOUNT_URL=<<YOUR AWS_ACCOUNT_ID>>.dkr.ecr.us- west-2.amazonaws.com AWS_ACCESS_KEY_ID=<<YOUR ACCESS_KEY_ID>> AWS_SECRET_ACCESS_KEY=<<YOUR SECRET_ACCESS_KEY>> AWS_REGION=us-west-2
GITHUB_TOKEN=<<YOUR PERSONAL_ACCESS_KEY>> w ҎԼΛ$JSDMF$*ͷ&OWJSPONFOUఆ͓͖ٛͯ͠·͢ w ·ͨ8SJUFՄೳͳ伴ͷηοτΛ࡞͠ɺެ։伴Λ (JU)VCൿີ伴Λ$JSDMF$*ొ͓͖ͯ͠ɺ1FSTPOBM "DDFTT5PLFOొ͠·͢ !20
ΞϓϦέʔγϣϯͷNBOJGFTU࡞ $ cat infra/default/application.yaml apiVersion: apps/v1 kind: Deployment metadata: name:
nginx-deployment namespace: default labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: XXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/gitops-sample: 1.0.0 ports: - containerPort: 80 ... snip ... !21
ΞϓϦέʔγϣϯʢ/HJOYʣͷల։ # ద༻ʢk = kubectlʣ $ k apply -f infra/default/application.yaml
$ k get pods -n default NAME READY STATUS RESTARTS AGE nginx-deployment-76cfc87d8c-4jwsh 1/1 Running 0 4h23m nginx-deployment-76cfc87d8c-6fxp2 1/1 Running 0 4h23m $ curl <<Service Endpoint>> <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> </head> <body> Hello GitOps!! </body> </html> !22
"SHP$%ͷల։ʢʣ # Ϋϥελల։ʢk = kubectlʣ $ k create namespace argocd
$ k apply -n argocd -f https://raw.githubusercontent.com/ argoproj/argo-cd/stable/manifests/install.yaml # LB Λ͚ͭͯΞΫηεͰ͖ΔΑ͏ʹ $ k patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}' # CLI ͷΠϯετʔϧ $ brew tap argoproj/tap $ brew install argoproj/tap/argocd # ϩάΠϯʢadmin:{argocd-serverͷPod໊} ͰϩάΠϯՄೳʣ $ argocd login <<Service Endpoint>> !23
"SHP$%ͷల։ʢʣ # ΞϓϦέʔγϣϯΛ࡞ $ argocd app create gitops-sample \ --repo
https://github.com/pm11/argo-cd-example.git \ --path infra/default \ --dest-server https://kubernetes.default.svc \ --dest-namespace default # ϦϙδτϦΛඥ͚ͮΔ $ argocd repo add https://github.com/pm11/argo-cd- example.git !24
"SHP$%ϩάΠϯ w 4FSWJDFʹ$-#ͷ%/4ͰΞΫηε͢ΔͱҎԼͷը໘ʹ w $-*ͱಉ͡Ϣʔβ໊ύεϫʔυΛ͏ !25
"SHP$%μογϡϘʔυ !26
5SZ(JU0QT
ΞϓϦέʔγϣϯʢ/HJOYʣΛมߋ $ git diff index.html ... @@ -4,6 +4,6 @@
<title>Welcome to nginx!</title> </head> <body> -Hello GitOps!! +Hello GitOps with CircleCI!! </body> </html> !28
ΞϓϦέʔγϣϯʢ/HJOYʣΛมߋ $ git diff .circleci/config.yml ... @@ -17,7 +17,7 @@
jobs: cd /home/circleci/project - sed -i -e 's/\(gitops-sample:\)[0-9\.]\+.*$/\11.0.0/g' infra/ default/application.yaml + sed -i -e 's/\(gitops-sample:\)[0-9\.]\+.*$/\11.0.1/g' infra/ default/application.yaml export BRANCH=`date "+%Y%m%d-%H%M%S"` ... @@ -34,7 +34,7 @@ workflows: jobs: - aws-ecr/build-and-push-image: repo: gitops-sample - tag: 1.0.0 + tag: 1.0.1 filters: !29
$JSDMF$* !30
(JU)VCͰ13Λ֬ೝ w $JSDMF$*͔Β13͕ग़͞ΕΔͷͰ༰Λ֬ೝ͠ɺϚʔδ͠·͢ w ʢࠓݸਓͷ1FSTPOBM"DDFTT5PLFOΛར༻͍ͯ͠·͕͢ઐ༻ͷ ͷ͕ྑ͍Ͱ͢ʣ !31
"SHP$%Ͱ4ZODΛߦ͏ w "SHP$%ଆ͕0VU0G4ZODͱͳΔͷͰɺ4ZODΛߦ͍·͢ !32
"SHP$%ͰσϓϩΠத w ผͰ3FQMJDB4FU͕࡞͞Εͯͷ1PE͕ىಈ͠·͢ !33
ΞϓϦέʔγϣϯʢ/HJOYʣΛมߋ $ curl <<Service Endpoint>> <!DOCTYPE html> <html> <head> <title>Welcome
to nginx!</title> </head> <body> Hello GitOps with CircleCI!! </body> </html> !34
None
·ͱΊ w ؆୯Ͱ͋Γ·͕͢$JSDMF$*ͱ"SHP$%ΛΈ߹Θͤͨ (JU0QTΛ࣮ݱͯ͠Έ·ͨ͠ w (JU)VCͷ13ૢ࡞ͰΠϯϑϥΛཧͰ͖ΔࣄʹΑΓɺݖݶཧ ϫʔΫϑϩʔΛ៉ྷʹग़དྷͦ͏Ͱ͢ w σϓϩΠΛτϦΨʔ͍ͯͨ͠$*0QTͱൺΔͱ(JU0QTͰɺ $*ͱ$%͕໌֬ʹ͔ΕΔ࣮ͱͳΓͦ͏Ͱ͢
w ࠓճͰ͖ͳ͔ͬͨࣗಈద༻ΑΓྑ͍UBHཧͳͲҾ͖ଓ͖ ͬͯ·͍Γ·͢ !36
͋Γ͕ͱ͏͍͟͝·ͨ͠