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
680
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
Exploring: Partial and Independent Composables
blackbracken
0
100
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
140
return文におけるstd::moveについて
onihusube
1
1.2k
php-conference-japan-2024
tasuku43
0
330
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
良いユニットテストを書こう
mototakatsu
8
2.8k
たのしいparse.y
ydah
3
120
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
480
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
1
150
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Writing Fast Ruby
sferik
628
61k
Thoughts on Productivity
jonyablonski
67
4.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Optimizing for Happiness
mojombo
376
70k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Practical Orchestrator
shlominoach
186
10k
BBQ
matthewcrist
85
9.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
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
͋Γ͕ͱ͏͍͟͝·ͨ͠