ãã®è¨äºã¯ã¯ã¦ãªã¨ã³ã¸ãã¢ã®ã«ã¬ã³ãã¼ | Advent Calendar 2022 - Qiitaã®14æ¥ç®ã®ã¨ã³ããªã§ãã
èæ¯
ç§ã®ãã¼ã ã§éç¨ãã¦ããEKSã¯ã©ã¹ã¿ã¼ã§ãããã¢ããã°ã¬ã¼ãã¯BlueGreenã¢ããã°ã¬ã¼ãããæ¹éãã¨ã£ã¦ãã¾ãã B/Gã¢ããã°ã¬ã¼ããæ¡ç¨ãã¦ãã主ãªçç±ã¯åãæ¿ãæã«åé¡ãçºçããå ´åã«ç´ æ©ãåãæ»ããè¡ãããããã§ãã
詳細ã¯ä»¥ä¸ã®ããã°ãåç §ãã ããã
B/Gã¢ããã°ã¬ã¼ãã®ããã¾ããªæµãã¯ä»¥ä¸ã®éãã§ãã
- æ°ãã¼ã¸ã§ã³ã®EKSã¯ã©ã¹ã¿ã¼ãæ§ç¯ãã
- ArgoCDã«æ°ã¯ã©ã¹ã¿ã¼ç¨ã®ãããã¤è¨å®ãæåã§ä½æãã¦ã¢ããªã±ã¼ã·ã§ã³ããããã¤ãã
- Route53ãAWS Global Acceleratorã®è¨å®ãå¤æ´ãã¦æ§ã¯ã©ã¹ã¿ããæ°ã¯ã©ã¹ã¿ã«ãªã¯ã¨ã¹ããåãæ¿ãã
ä¸è¨ã®2ã¨3ã®å·¥ç¨ã«ã¯ä»¥ä¸ã®ãããªèª²é¡ãæãã¦ãã¾ãã
- ãµã¼ãã¹ãå¢ãããã¨ã§æ°ã¯ã©ã¹ã¿ã¼ã«å¯¾ãããããã¤è¨å®ã®ä½æ¥è² è·ãé«ããªã£ã¦ãã¦ãã
- ããæ軽ã«ãã°ããåãæ¿ããåãæ»ããè¡ããããã«ããã
ä¸è¨ã«ã¤ãã¦æ¹åãè¡ã£ã¦ããã®ã§ç´¹ä»ãããã¨æãã¾ãã
å®ç¾ããããã¨
ä¸è¨ã®èª²é¡ããç§éãå®ç¾ããããã¨ã¯ä»¥ä¸ã®éãã§ãã
- ã¯ã©ã¹ã¿ã®ãã¼ã¸ã§ã³ã¢ããæãªã©ããããã¤å ã®ã¯ã©ã¹ã¿ãå¢ããå ´åã§ããã¢ããªã±ã¼ã·ã§ã³ãå¹çãããããã¤ã§ããããã«ãã
- æ§ã¯ã©ã¹ã¿ã¼ããæ°ã¯ã©ã¹ã¿ã¼ã«ãªã¯ã¨ã¹ããæ軽ã«ç´ æ©ãåãæ¿ããããããã«ãã
解決ã¸ã®ã¢ããã¼ã
ArgoCDã®ApplicationSetãå©ç¨ãã
ArgoCDã¯ãããã¤è¨å®ãApplicationã¨ããã«ã¹ã¿ã ãªã½ã¼ã¹ã§ç®¡çãã¦ãã¾ããApplicationã«ä¸»ã«å®ç¾©ãã¦ããå 容ã¯ä»¥ä¸ã®éãã§ãã
- Manifestãåå¾ãããªãã¸ããªã¨ãã©ã³ãããªãã¸ã§ã³
- ãããã¤å ã®ã¯ã©ã¹ã¿ã¼
- Namespace
B/Gã¢ããã°ã¬ã¼ãæã«ã¯ãããã¤å ã®ã¯ã©ã¹ã¿ã¼ãç°ãªãã2ã¤ã®Applicationãä½æããå¿ è¦ãããã¾ãããããã¤ããã¢ããªã±ã¼ã·ã§ã³ãå¤ãã»ã©ç®¡çãç ©éã«ãªã£ã¦ããã¾ãã
ApplicationSetã¯Applicationã®ç®¡çãã¾ã¨ãããã¨ãã§ãã¾ãã ãããå©ç¨ãããã¨ã§è¤æ°ã®ã¯ã©ã¹ã¿ã¼åã®Applicationãªã½ã¼ã¹ãèªåçã«ä½æãããã¨ãã§ãã¾ãã
ããã«Generatorã¨ãããã©ã¡ã¼ã¿ãå©ç¨ãããã¨ã§ãArgoCDã«ç»é²ããã¦ããã¯ã©ã¹ã¿ã¼ãæå®ããã¯ã©ã¹ã¿ã¼ã®ãªã¹ãåã ãApplicationãä½æãããã¨ãå¯è½ã§ãã
ApplicationSetãå©ç¨ãããã¨ã§æ°æ§ã¯ã©ã¹ã¿ã¼ç¨ã®ãããã¤è¨å®ããå¹çãã管çã§ããããã«ãªãã¨èãã¦ãã¾ãã
AWS Loadbalancer Controllerã®TargetGroupBindingãå©ç¨ãã
AWS Loadbalancer Controllerã¯Kubernetesã®ã¢ããªã³ã§ãã Kubernetesã®Ingressãªã½ã¼ã¹ãä½æããã¨ALBããããã¸ã§ãã³ã°ããã¾ãã
ã¤ã¾ã以ä¸ã®å³ã®ããã«ã¯ã©ã¹ã¿ã¼æ¯ã«ALBãä½æããã¾ãã
ãã®æ¹æ³ã ã¨åºæ¬çã«ã¯DNSã®åãæ¿ãã§ã¯ã©ã¹ã¿ã¼ç§»è¡ãããã¨ã«ãªãã¾ããããã§ãåé¡ã¯ãªãã®ã§ãããDNSããã£ãã·ã¥ãã¦ããã¯ã©ã¤ã¢ã³ãããã£ãå ´åã«å®å ¨ã«åãæ¿ããã®ãå¾ ã¤å¿ è¦ãããã¾ãã
AWS Loadbalancer Controllerã«ã¯TargetGroupBindingã¨ããã«ã¹ã¿ã ãªã½ã¼ã¹ãããã¾ãããããå©ç¨ããã¨æ¢åã®TargetGroupãå©ç¨ãã¦Podãå ¬éãããã¨ãã§ãã¾ãã
ã¤ã¾ãIngressãä½æããªãããALBã¯IaCãªã©Kubernetesã®ã©ã¤ããµã¤ã¯ã«ã®å¤ã§ç®¡çã§ãã¾ãã
TargetGroupBindingãå©ç¨ããã¨ä»¥ä¸ã®å³ã®ããã«ãæ°æ§ã¯ã©ã¹ã¿ã¼ã§åãALBãå©ç¨ãã¦ãç°ãªãTargetGroupã«ã¶ãä¸ããæ§æã¨ãªãã¾ãã
ããã«ããALBã®WeightedRoutingããå©ç¨ã§ããæ°ã¯ã©ã¹ã¿ã¼ã«ãªã¯ã¨ã¹ããå°ããã¤ç§»è¡ãããã¨ãå¯è½ã¨ãªãã¾ãã
ã¯ã©ã¹ã¿å¥ã®ãªã½ã¼ã¹å®ç¾©ã®æ¸ãæããã©ãããã
ããã¾ã§ç´¹ä»ããå 容ã®æ¹åãè¡ã£ã¦æ¥ãçµæãä¸é¨åé¡ãçãã¾ããã TargetGroupBindingãå©ç¨ããã¨ãã¯ã©ã¹ã¿ã¼å¥ã§ç°ãªãTargetGroupã®ARNãManifestã«è¨è¿°ããå¿ è¦ãããã¾ãã ãã®ARNãã©ã®ããã«ãã¦æ¸ãæãããã¨ããåé¡ãçãã¾ããã
ç§éã¯Kustomizeãå©ç¨ãã¦ç°å¢æ¯(Dev/Stg/Prd)ã®Manifestã®ç®¡çãè¡ã£ã¦ãã¾ãããã®ããæ°æ§ã¯ã©ã¹ã¿ã¼æ¯ã«ãã£ã¬ã¯ããªãåãã¦kustomization.yamlãä½æãã¾ãããApplicationSet ã«ããã¦ã¯ãã¯ã©ã¹ã¿ã¼å¥ã«ãã¼ããããã¹ãåãããã¨ã§å¯¾å¿ãã¾ãããå ·ä½çãªãã¡ã¤ã«æ§æã以ä¸ã«è¨è¿°ãã¾ãã
ãã£ã¬ã¯ããªããªã¼
âââ production â  âââ kustomization.yaml â  âââ ... âââ production-blue-cluster â  âââ kustomization.yaml â  âââ patches â  âââ targetgroupbinding.yaml âââ production-green-cluster   âââ kustomization.yaml   âââ patches   âââ targetgroupbinding.yaml
ä¸è¨ã®./production
é
ä¸ã®ãã¡ã¤ã«ç¾¤ã¯ããã¾ã§ãããã¤ã«å©ç¨ãã¦ããæ¢åã®ãã¡ã¤ã«ã§ãã
production-[blue|green]-cluster
ãæ°è¦è¿½å ãããã£ã¬ã¯ããªã¨kustomization.yamlã«ãªãã¾ãã
production-[blue|green]-cluster/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../production patches: - patches/targetgroupbinding.yml
æ¢åã®kustomizeã®æ§æã«ã¯æãå ¥ããTargetGroupBindingã«é¢ããè¨è¿°ã®ã¿patchããã¦ããããªæ§æã«ãã¦ãã¾ãã
patches
--- apiVersion: elbv2.k8s.aws/v1alpha1 kind: TargetGroupBinding metadata: name: my-tgb spec: targetGroupARN: 'arn://hogefugapiyo' networking: ingress: - from: - securityGroup: groupID: 'sg-hogefugapiyo'
patchã«ã¯æ°æ§ã¯ã©ã¹ã¿ã¼ã§ç°ãªãTargetGroupã®ARNã¨ALBã®ã»ãã¥ãªãã£ã°ã«ã¼ãIDãè¨è¿°ãã¾ãã
ArgoCD ApplicationSet
apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: my-app namespace: my-service spec: generators: - clusters: {} # Automatically use all clusters defined within Argo CD template: spec: source: path: k8s-manifest/project/production-{{cluster}} ...
ArgoCDã®ApplicationSetã§ã¯Generatorãå©ç¨ãã¦{{cluster}}
é¨åãå¤æ°åãããã¨ã§ãèªåçã«B/Gã¯ã©ã¹ã¿ã¼ç¨ã®ãããã¤è¨å®(Applicationãªã½ã¼ã¹)ãä½æãããã¨ãã§ãã¾ãã
ãããã«
EKSã¯ã©ã¹ã¿ã¼ã®ãã¼ã¸ã§ã³ã¢ããä½æ¥ãå¹çåããããã®åãçµã¿ã«ã¤ãã¦ç´¹ä»ãã¾ããã TargetGroupBindingãå©ç¨ããã¯ã©ã¹ã¿ã¼ã®B/Gã¢ããã°ã¬ã¼ãã¯ããè³ã«ãã¾ããå®éã«ç§éã®ç°å¢ã§å®è·µãã¦ã¿ãã¨èª²é¡ãããæ§ã ãªè§£æ±ºæ¹æ³ããããã¨ãç¥ãã¾ããã
ä»åãç§éã¯ãã®ããã°ã«æ¸ããæ¹éã§å¯¾å¿ãã¨ãã¾ããããä»å¾éç¨ãé²ããã¨ããããæ¹æ³ããã¼ã«ãç¥ããã¨ã«ãªãã¨æãã®ã§ããã®ãããªæ¹åã¯ç¶ç¶ãã¦ã©ããã§å ¬éã§ããã°ã¨æãã¾ãã
ææ¥ã®ã¯ã¦ãªã¨ã³ã¸ãã¢Advent Calendar㯠id:kouki_dan ããã§ãã