Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GitOpsで実現するPull Request毎のプレビュー環境/Preview enviro...

Takuma Kume
September 28, 2021

GitOpsで実現するPull Request毎のプレビュー環境/Preview environment for each Pull Request by GitOps

Takuma Kume

September 28, 2021
Tweet

More Decks by Takuma Kume

Other Decks in Technology

Transcript

  1. ࠓճ঺հ͢Δ΋ͷ ΞϓϦέʔγϣϯ ϦϙδτϦ LVCFSOFUFT Ϋϥελ Branch-A Branch-B Branch-A Branch-B 13࡞੒

    13࡞੒ branch-a.example.com branch-b.example.com (JU0QTͰ࣮ݱ͢Δ1VMM3FRVFTUຖͷϓϨϏϡʔ؀ڥ
  2. ϓϨϏϡʔ؀ڥͷղઆɿલఏ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS ιʔείʔυ LVCFSOFUFTNBOJGFTUT LVCFSOFUFTNBOJGFTUT "SHP$% ֤"QQ3FQPͷ"SHP$%$POpH

    *OHSFTT$POUSPMMFSʜ ArgoCD ΞϓϦͷίϯςφΠϝʔδ ArgoCD Image Updater "SHP$%ͰNBOJGFTUTͷ$%Λ͍ͯ͠Δ "SHP$%*NBHF6QEBUFSͰΠϝʔδͷ $%Λ͍ͯ͠Δ ϓϨϏϡʔ؀ڥͷղઆͷલʹɺϦϙδτϦͷߏ੒ͱ$%ʹ͍ͭͯ
  3. ϓϨϏϡʔ؀ڥͷղઆɿશମ૾ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI 13τϦΨʔͰΠϝʔδͷϏϧυͱ"SHP$%ͷઃఆΛੜ੒͢Δ CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ HJUDPNNJUQVTI
  4. ϓϨϏϡʔ؀ڥͷղઆɿશମ૾ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ "SHP$%͕ݕ஌͠ϒϥϯνͷ؀ڥΛσϓϩΠ͢Δ ArgoCD CSBODIBͷ؀ڥΛੜ੒ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ"QQMZ CSBODIBͷNBOJGFTUTͷಉظΛ։࢝ %FQMPZNFOU 4FSWJDFʜ มߋΛݕ஌ HJUDPNNJUQVTI
  5. ϓϨϏϡʔ؀ڥͷղઆɿશମ૾ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ "SHP$%*NBHF6QEBUFSͰ࠷৽ͷΠϝʔδΛద༻͢Δ ArgoCD มߋΛݕ஌ CSBODIBͷ؀ڥΛੜ੒ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ"QQMZ CSBODIBͷNBOJGFTUTͷಉظΛ։࢝ %FQMPZNFOU 4FSWJDFʜ ArgoCD Image Updater ࠷৽ͷΠϝʔδΛద༻͢Δ มߋΛݕ஌ ίϯςφΠϝʔδͷ#VJME1VTI ϒϥϯν΁1VTI͢Δ౓ʹ࣮ߦ HJUDPNNJUQVTI
  6. ϓϨϏϡʔ؀ڥͷղઆɿશମ૾ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ ArgoCD มߋΛݕ஌ CSBODIBͷ؀ڥΛੜ੒ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ"QQMZ CSBODIBͷNBOJGFTUTͷಉظΛ։࢝ %FQMPZNFOU 4FSWJDFʜ ArgoCD Image Updater ࠷৽ͷΠϝʔδΛద༻͢Δ มߋΛݕ஌ ίϯςφΠϝʔδͷ#VJME1VTI HJUDPNNJUQVTI
  7. "SHP$%ͷઃఆͷੜ੒ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ ArgoCD มߋΛݕ஌ CSBODIBͷ؀ڥΛੜ੒ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ"QQMZ CSBODIBͷNBOJGFTUTͷಉظΛ։࢝ %FQMPZNFOU 4FSWJDFʜ ArgoCD Image Updater ࠷৽ͷΠϝʔδΛద༻͢Δ มߋΛݕ஌ ίϯςφΠϝʔδͷ#VJME1VTI HJUDPNNJUQVTI
  8. "SHP$%ͷઃఆͷੜ੒ wBSHPDEBENJOBQQHFOFSBUFTQFDίϚϯυͰઃఆΛੜ੒ͯ͠Ϧ ϙδτϦʹ1VTI͍ͯ͠Δ $ argocd admin app generate-spec sample-app-pr-1 \

    --dest-server https://kubernetes.default.svc \ --dest-namespace sample-app-pr-1 \ --path manifests/preview \ --repo https://github.com/takumakume/sample-app \ --revision branch-1 \ --sync-policy auto \ --sync-option Prune=true \ --sync-option CreateNamespace=true apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: sample-app-pr-1 spec: destination: namespace: sample-app-pr-1 server: https://kubernetes.default.svc source: path: manifests/preview repoURL: https://github.com/takumakume/sample-app targetRevision: branch-1 syncPolicy: … wੜ੒ʹඞཁͳύϥϝʔλΛ(JUIVC"DUJPOͰ౉͍ͯ͠Δ sample-app-pr-1.yaml
  9. "SHP$%ͷઃఆͷੜ੒ apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: sample-app-pr-1 spec: source:

    path: manifests/preview repoURL: https://github.com/takumakume/sample-app targetRevision: branch-1 destination: namespace: sample-app-pr-1 server: https://kubernetes.default.svc syncPolicy: - CreateNamespace=true … ϓϨϏϡʔ؀ڥͷNBOJGFTUTͷσ ΟϨΫτϦΛ 13ຖͷ/BNFTQBDFʹల։ /BNFTQBDF͸ࣗಈੜ੒ w୯ҰͷNBOJGFTUTΛ࢖֤ͬͯ13ͷ؀ڥΛએݴతʹੜ੒Ͱ͖Δ sample-app-pr-1.yaml
  10. "QQ*NBHFͷߋ৽ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP $POUBJOFS3FHJTUSZ ,VCFSOFUFT$MVTUFS Github Actions branch-a Github Actions

    13࡞੒ App Image ίϯςφΠϝʔδͷ#VJME1VTI SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛੜ੒ ArgoCD มߋΛݕ஌ CSBODIBͷ؀ڥΛੜ੒ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ"QQMZ CSBODIBͷNBOJGFTUTͷಉظΛ։࢝ %FQMPZNFOU 4FSWJDFʜ ArgoCD Image Updater ࠷৽ͷΠϝʔδΛద༻͢Δ มߋΛݕ஌ ίϯςφΠϝʔδͷ#VJME1VTI HJUDPNNJUQVTI
  11. "QQ*NBHFͷߋ৽ wϒϥϯνʹHJUQVTI͢Δ౓ʹɺ13൪߸ͱίϛοτϋογϡͰߏ ੒͞ΕΔλάΛ෇༩ͯ͠ΠϝʔδΛQVTI͍ͯ͠Δ wTBNQMFBQQQSFDFE w"SHP$%ͷઃఆΛੜ੒͢Δஈ֊Ͱ*NBHF6QEBUFSͷઃఆΛ෇༩ apiVersion: argoproj.io/v1alpha1 kind: Application metadata:

    name: sample-app-pr-1 annotations: argocd-image-updater.argoproj.io/image-list: sample-app=takumakume/sample-app:^pr-1 argocd-image-updater.argoproj.io/sample-app.update-strategy: latest argocd-image-updater.argoproj.io/sample-app.ignore-tags: latest argocd-image-updater.argoproj.io/sample-app.allow-tags: regexp:^pr-1-[0-9a-f]{5,40}$ ... ࠷৽ͷlQSίϛοτϋογϡzͳΠϝʔδΛద༻͢Δ
  12. ϓϨϏϡʔ؀ڥͷղઆɿ؀ڥͷ࡟আ "QQ3FQP 4ZTUFN.BOJGFTUT3FQP ,VCFSOFUFT$MVTUFS Github Actions Pull Request Github Actions

    $MPTFPS.FSHF SFQPTJUPSZ@EJTQBUDI CSBODIB༻ͷ"SHP$%ͷઃఆΛ࡟আ ArgoCD ࡟আΛݕ஌ CSBODIBͷ؀ڥΛ࡟আ BQQCSBODIB CSBODIB༻ͷ"SHP$%ͷઃఆΛ࡟আ %FQMPZNFOU 4FSWJDFʜ HJUDPNNJUQVTI apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: sample-app-pr-1 finalizers: - resources-finalizer.argocd.argoproj.io … "QQMJDBUJPOϦιʔε࡟আ࣌ʹͦͷ؀ڥΛ࡟আ͢Δ
  13. ϓϨϏϡʔ؀ڥͷղઆɿ؀ڥ΁ͷΞΫηε apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: app-ingress namespace: app

    spec: rules: - host: staging-app.example.com http: paths: - backend: service: name: app-svc port: number: 8080 path: / pathType: Prefix tls: - hosts: - staging-app.example.com secretName: app-tls staging-app.example.com staging-app.example.com ίί ίί w*OHSFTTΛ࢖͏৔߹ͷ՝୊ w୯ҰͷNBOJGFTUTΛෳ਺ͷϓϨϏϡʔ ؀ڥʹར༻͢ΔͨΊɺ*OHSFTTIPTUͷ ॻ͖׵͕͑ඞཁ wNBOJGFTUTੜ੒࣌ʹεΫϦϓτ౳Ͱॻ ͖׵͑Δࣄ΋Ͱ͖Δ͕ɺ؅ཧ͕൥ࡶͱ ͳΔ
  14. apiVersion: service-expose.../v1alpha1 kind: ServiceExpose metadata: name: example namespace: ns1 spec:

    backend: service: name: example-svc port: number: 8080 domain: example.com path: / pathType: Prefix tlsEnable: true tlsSecretName: example-tls annotations: cert-manager.io/cluster-issuer: letsencrypt apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example namespace: ns1 annotations: cert-manager.io/cluster-issuer: letsencrypt spec: rules: - host: example-svc.ns1.example.com http: paths: - backend: service: name: example-svc port: number: 8080 path: / pathType: Prefix tls: - hosts: - example-svc.ns1.example.com secretName: example-tls backend: service: name: example-svc port: number: 8080 example-svc ns1 example.com example-svc ns1 example.com example-svc ns1 example.com ެ։͢Δ4FSWJDF αʔϏεσΟεΧόϦతͳ ϗετ໊ΛࣗಈͰ෇༩ αʔϏε໊ namespace υϝΠϯ UBLVNBLVNFTFSWJDFFYQPTFPQFSBUPS