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

ECSからEKSへの移行への移行事例の紹介

Masato Oshima
November 20, 2020

 ECSからEKSへの移行への移行事例の紹介

発表資料の中に出てくるURLです。

* [Amazon EKSでのArgoCDを使ったGitOps CD](https://tech.recruit-mp.co.jp/infrastructure/gitops-cd-by-using-argo-cd-at-eks/)
* [EnvoyとAmazon ECS Service Discoveryを利用したgRPCの負荷分散](https://tech.recruit-mp.co.jp/infrastructure/post-17098/)
* [Amazon EKSでAWS App Meshを利用してgRPCサーバーを運用する](https://tech.recruit-mp.co.jp/infrastructure/post-20765/)
* [https://tech.recruit-mp.co.jp/infrastructure/post-19364/](https://tech.recruit-mp.co.jp/infrastructure/post-19364/)
* [JenkinsのJobを CronJobに移した話](https://speakerdeck.com/yutachaos/the-story-of-moving-jenkins-job-to-cronjob)
* [EKS クラスタの CronJob を Fargate 上で実行する方法](https://tech.recruit-mp.co.jp/infrastructure/post-20631/)

Masato Oshima

November 20, 2020
Tweet

More Decks by Masato Oshima

Other Decks in Technology

Transcript

  1. AGENDA ➤ ελσΟαϓϦENGLISHʹ͍ͭͯ ➤ ୈҰ෦: ECS͔ΒEKS΁Ҡߦͷഎܠ ➤ ՝୊1: ؀ڥ૿΍͢ͷ͕ਏ͔ͬͨ ➤

    ՝୊2: Ͳ͜ʹԿ͕σϓϩΠ͞ΕͯΔ͔೺Ѳ͠ʹ͔ͬͨ͘ ➤ ՝୊3: gRPCͷෛՙ෼ࢄ ➤ ୈೋ෦: EKSҠߦޙͷߏ੒ʹ͍ͭͯ ➤ Spot OceanΛ࢖ͬͨΫϥελʔ؅ཧ ➤ JenkinsͷJobΛCronJobʹҠߦʢFargateͷ࿩΋͋ΔΑʣ ➤ ·ͱΊɿίϯςφ͸͍͍ͧ
  2. ECSͷͱ͖ͷߏ੒؅ཧํ๏ ෼ྨ ίϯϙʔωϯτ ઃఆํ๏ Ծ૝Ϋϥελʔ ECS Cluster Terraform Πϯελϯε Autoscaling

    Group Terraform αʔϏεεέδϡʔϥ ECS Service Terraform αʔϏεσΟεΧόϦ Cloud Map Terraform ίϯςφఆٛ ECS Task Definition Terraform + ಠࣗπʔϧ ϩʔυόϥϯαʔ ALB Terraform αʔϏεͻ΋͚ͮ ALB Target Group Terraform ϧʔςΟϯά ALB Listenr Rule Terraform
  3. ECSͰ؀ڥΛͨ͘͞Μ૿΍͢ʹ͸ʁ ➤ TerraformͰECS ClusterɺECS ServiceɺALBͳͲ৭ʑ࡞Δ ➤ Task Definitionʢಠࣗπʔϧͷ࢓༷ͷYAMLʣΛେྔʹίϐʔ ➤ ςϯϓϨʔτͷػೳ͕ͳ͘؀ڥ͝ͱʹ؀ڥݻ༗ͷ஋ʹॻ͖׵͑Δ

    ➤ ؀ڥ૿΍͢ͷʹTerraformͰΠϯελϯε΍ALBΛ૿΍͞ͳ͍ͱ͍͚ͳ͍ ➤ Terraform͸ModuleԽ͸͚ͨ͠Ͳɺ͋ͱ͔ΒมߋೖΕΔͱޓ׵ੑอͭͷ ʹେมͳ͜ͱ͕͋ͬͯؾܰʹmoduleΛมߋͰ͖ͳ͍ ➤ σϓϩΠͰมߋ͕ى͖Δ΋ͷΛTerraformͰ؅ཧͯ͠͠·͍ͬͯͨͷͰ ignore_changesͰແཧ΍Γແࢹ ➤ ϥΠϑαΠΫϧͷҧ͍ΛݟۃΊΒΕ͍ͯͳ͔ͬͨɾɾ
  4. EKSͷߏ੒؅ཧํ๏ ෼ྨ ίϯϙʔωϯτ ઃఆํ๏ Ծ૝Ϋϥελʔ Namespace YAML(k8s) Πϯελϯε EC2Πϯελϯε Terraform

    + Spot Ocean αʔϏεεέδϡʔϥ Deployment YAML(k8s) αʔϏεσΟεΧόϦ Service YAML(k8s) ίϯςφఆٛ Pod YAML(k8s) ϩʔυόϥϯαʔ Ingress YAML(k8s) αʔϏεͻ΋͚ͮ Ingress YAML(k8s) ϧʔςΟϯά Ingress YAML(k8s)
  5. EKSͰ؀ڥΛͨ͘͞Μ૿΍͢ʹ͸ʁ ➤ Terraformͷग़൪͸EKS ClusterΛ࠷ॳʹ࡞Δ͚ͩͰ؀ڥ૿΍͢ͱ ͖ʹ͸͍Βͳ͍ ➤ ؀ڥ૿΍͢৔߹͸NamespaceΛ૿΍͢ ➤ KustomizeΛ࢖ͬͯ؀ڥ͝ͱʹมΘΔ෦෼͚ͩΛ௥Ճ ➤

    ֎෦͔ΒͷϦΫΤετͷϚοϐϯά͸Ingress ➤ ಺෦௨৴͸ServiceΦϒδΣΫτͰ؆୯αʔϏεσΟεΧόϦɺ CoreDNS͕͋ΔͷͰRoute53ͳ͠Ͱ΋಺෦ͰDNS͕༻ҙ ➤ ΄ͱΜͲKubernetesͷΦϒδΣΫτͰ׬݁͢ΔͷͰએݴతʹ؅ཧ ͠΍͍͢
  6. ΫϥελʔΛ࿦ཧతʹ෼ׂͰ͖Δ Namespace dev1 EC2 EC2 EC2 Cluster EC2 EC2 EC2

    Namespace dev2 Namespace dev3 ➤ Kubernetesʹ͸Namespace ͱ͍͏ΦϒδΣΫτ͕͋Δ ➤ Cluster͑͞࡞ͬͯ͠·͑͹ ͋ͱ͸NamespaceΛ૿΍͢ ͚ͩͰ؀ڥ͕૿΍ͤΔ ➤ Namespace͝ͱͷDNSΤϯ τϦ΋࡞੒͞ΕΔ ➤ ͜Μͳ୯७ͳYAMLͰOK
  7. ECSͷͱ͖ʹײ͍ͯͨ͡՝୊ ➤ hoge؀ڥͷfugaαʔϏεͬͯࠓσϓϩΠ͞ΕͯΔͷ͸Ͳͷϒϥϯνʁ ➤ ίϯςφͷ؀ڥม਺͸Կ͕ઃఆ͞ΕͯΔʁ ➤ aws ecs list-servicesͱ͔ͰҰൃͰͲͷtag͕σϓϩΠ͞ΕͯΔ͔೺ѲͰ͖ ͳ͍ͷͰࣗ࡞πʔϧ࡞͙ͬͯ྇

    ➤ σϓϩΠͷઃఆʢJenkinsfileʣʹઃఆ͕ͲΜͲΜ૿͍͑ͯͬͯΧΦεʹ ͳ͖ͬͯͨ ➤ Α͘σϓϩΠ͢ΔAPIͳͲͷαʔόʔΞϓϦέʔγϣϯͱ୯ͳΔnginxͱ ͔ͷσϓϩΠ͸σϓϩΠํ๏͕ผʑʹ༻ҙͯ͠ϝϯς͍ͯͨ͠ ➤ gitϦϙδτϦΛݟΕ͹Կ͕σϓϩΠ͞ΕͯΔ͔෼͔ΔΑ͏ʹ͍ͨ͠ ➤ gitops͍ͨ͠
  8. Clusterʹඞཁͳresource΋gitopsͰ ➤ Ingress Controller΍ Datadog AgentͳͲ΋؅ཧ Ͱ͖Δ ➤ Helm Chart

    Repositoriesͷ ػೳ͕͋ΔͷͰArgo CDͰ Helm ChartΛιʔεʹ؅ཧ Մೳ ➤ ArgoCD ApplicationΛ࡞੒ ͢Ε͹ߏங׬ྃ
  9. σϓϩΠ࣌ʹϦΫΤετ͕མͪΔ໰୊ Blue gRPC Green gRPC Blue gRPC Green gRPC blue.grpc.internal

    green.grpc.internal Cloud Map lb.grpc.internal ➤ grpcαʔόʔΛRolling Update͢Δ ͱSTOPࡁΈͷίϯςφͷIP͕ฦͬ ͖ͯͯϦΫΤετ͕མͪͯ͠·͏ ➤ JenkinsͷpipelineͱshΛ૊Έ߹Θ ͤͯBlue/GreenσϓϩΠ ➤ ECS Task Definitionͷ؀ڥม਺Λ sedͰBlue->Greenʹॻ͖׵͑ͯ envoyΛRolloing Update ➤ Sleep 30͔ͯ͠ΒBlueΛ࡟আ ➤ ϫʔΫΞϥ΢ϯυײຬࡌͳͷͰͳ Μͱ͔͔ͨͬͨ͠
  10. App Meshͷߏ੒؅ཧ ➤ AWS App Mesh Controller for k8s͕༻ҙ͞Ε͍ͯΔ ➤

    APIͷίϯςφͷYAMLΛ͍ ͡Δ͜ͱͳ͘envoyΛInject ͯ͘͠ΕΔ ➤ k8sͷCRDͱͯ͠؅ཧͰ͖ ΔͷͰgitopsͰ͖Δ ➤ ։ൃ؀ڥΛ૿΍͢ͷ΋؆୯
  11. Pod-Driven Scaling ➤ Pod͕UnscheduleʹͳΒͳ͍Α͏ʹ NodeΛΦʔτεέʔϦϯάͯ͘͠ ΕΔ ➤ PodʹׂΓ౰ͯΔrequests͚ͩΛߟ ͑Ε͹OK ➤

    Node͸ҙࣝ͠ͳͯ͘Α͍ͷͰ FargateͷΑ͏ͳ࢖͍উख ➤ Spot Instance͔Β࠷దͳΠϯελϯ εΛબΜͰ͘ΕΔ ➤ ΦϯσϚϯυͰಈ͍ͯཉ͍͠podʹ ͸annotation෇༩͢Δ͚ͩͰOK
  12. Sidecarίϯςφͷఀࢭ͕೉͍͠ ➤ Datadog Agent΍FluentdͳͲΛ Sidecarʹ͓͔͘͠ͳ͍ ➤ JobͷϝΠϯͷίϯςφ͕ఀࢭͯ͠΋ sidecarίϯςφ͸ఀࢭ͠ͳ͍ͷͰJob ͕ऴྃ͠ͳ͍ʂʂ ➤

    ऴྃ࣌ʹsidecarίϯςφΛఀࢭͤ͞ ΔͳͲͷ޻෉͕ඞཁ ➤ ECSͰ͍͏essential:trueͷػೳ͕ͳ͍ ➤ Sidecar Containers͕Kubernetes v1.19ʹೖΔ༧ఆ͕ͩͬͨະఆʹͳͬ ͯ͠·ͬͨʁ
  13. ·ͱΊͱࡶஊ ➤ ECS͔ΒEKSϔҠߦͨ͠࿩Λ͠·ͨ͠ ➤ ͋͘·Ͱ΋զʑͷ৔߹ͷ࿩ ➤ gitops΍KubernetesͷΤίγεςϜͰಠࣗ࢓༷Λͳͯ࣋͘͠ଓੑͷ͋ΔγεςϜ΁ ➤ App Mesh͸ຊ൪ར༻΋໰୊ͳ͠

    ➤ ECS͸ࠓͳΒFargate Spot΋͋Δ͠ALB͕gRPCαϙʔτͨ͠͠࠶ߟͯ͠Έ͍ͨ ➤ ecspressoΛ࢖͑͹ϥΠϑαΠΫϧͱςϯϓϨʔτͱ͔΋ͬͱ͏·͘Ͱ͖͔ͨ΋ ➤ ECSͰɺALBͱͷͻ΋͚ͮɺECS ServiceɺTask Definitionͱ͔Λ౷Ұతʹѻ͑Δπʔϧ ͕͋Ε͹͍͍ͷ͔΋ ➤ copilot͕ͦ͏ͳͷ͔ʁ ➤ ίϯςφ͸͍͍ͧ ➤ ͨͩ͠ɺRDSɺClodwatch LogsɺS3ͳͲϚωʔδυαʔϏε͕͋ͬͯͦ͜