ããã«ã¡ã¯ã SRE ã® @suzuki-shunsuke ã§ãã
Docker Hub ãã Docker image ã Pull ããéã« Rate Limit ã«å¼ã£ããããªãããã«å¯¾å¿ãã話ã«ã¤ãã¦æ¸ãã¾ãã anonymous user ã«å¯¾ãã Docker Hub ã® Rate Limit ã¯æ®µéçã«å°å ¥ããã¦ãã¦ã 2020-11-02 9am Pacific Standard Time ã«å®å ¨ã«å°å ¥ãããããã§ãã
https://docs.docker.com/docker-hub/download-rate-limit/
ããã§äºåã«åé¡ãèµ·ããã¬ãã対å¿ãã¾ããã
対å¿æ¹é
対å¿æ¹éã«ã¤ãã¦ã¯å¤§ãã 3 ã¤ããã¾ãã
- åã image ã使ãã¤ã¤ãèªè¨¼ãããããã«ãã
- Docker Hub 以å¤ã§ãã¹ãã£ã³ã°ããã¦ããå¥ã® public ãªã¤ã¡ã¼ã¸ã使ã
- Docker Hub ã®ã¤ã¡ã¼ã¸ãå¥ã® registry ã«ãã©ã¼ããããã使ã
対å¿ãå§ããã®ã 2020-10-15 ã§ãã¾ãæéããªãã£ãã®ã§ãä¸çªæ¥½ãã㪠1 ãæ¡ç¨ãã¾ããã
主ã«ä»¥ä¸ã® 3 ã¤ã®ãã¿ã¼ã³ã«é¢ãã¦å¯¾å¿ãã¾ããã
- CircleCI ã® job ã§å©ç¨ãã¦ãã Docker image ã® pull
- Docker image ã build ããéã® base image ã® pull
- k8s ã® pod ã® Docker image ã® pull
CircleCI ã® job ã§å©ç¨ãã¦ãã Docker image ã® pull
å¼ç¤¾ã§ã¯ CI ã«ã¯ä¸»ã« CircleCI ã使ã£ã¦ãã¾ãã
https://circleci.com/docs/ja/2.0/private-images/
å
¬å¼ã®ããã¥ã¡ã³ãã®éããã²ããã auth
ãã¼ã追è¨ãã¾ããã
ãªãã¸ããªã®æ°ãå¤ãã£ãã®ã§å¤§å¤ã§ããã
ã³ã¡ã³ããç¶æã㦠YAML ãæ©æ¢°çã«ç·¨éããã®ããããã£ãããã¾ãããç¹ã«èªååã¯ããã«äººåã§é å¼µãã¾ããã
CircleCI ã§ã¯å½å Rate Limit ãããããªãããã
ãªãã CircleCI ãã Docker Hub ã® Docker image ã® pull ã«é¢ãã¦ã¯å½åº§ã®éä¸å®ã®æ¡ä»¶ä»ã㧠Rate Limit ãããããªãããã§ãã
https://twitter.com/CircleCIJapan/status/1319453337536720896
ã§ãããå°æ¥çã«ã¯ Rate Limit ãããããããããªãã®ã§å¯¾å¿ãããã¨ãå ¬å¼ã«æ¨å¥¨ããã¦ãã¾ãã
Docker image ã build ããéã® base image ã® pull
build ããã¤ã¡ã¼ã¸ã® push å ã Docker Hub 以å¤ã§ãã£ã¦ãã base image ã¨ã㦠Docker Hub ã® image ã使ã£ã¦ããã°èªè¨¼ããå¿ è¦ãããã¾ãã docker build ãå®è¡ããåã« docker login ãå®è¡ãã¦èªè¨¼ããããã«ãã¾ããã
k8s ã® pod ã® Docker image ã® pull
Podã§ImagePullSecretsãæå®ãã ã«æ¸ãã¦ããã¨ããã
- Docker Hub ã® Access Token ãå ã« k8s ã® Secret ãçæ
- Pod ãªãã ServiceAccount ã«
imagePullSecrets
ã追è¨
ããå¿ è¦ãããã¾ãã
å¼ç¤¾ã§ã¯ AWS Secrets Manager 㨠aws-secret-operator ãå©ç¨ã㦠Secret ã管çãã¦ãã¾ãã Docker Hub ã® Access Token ã«ã¤ãã¦ãåæ§ã®æ¹æ³ã§ç®¡çãããã¨ã«ãã¾ããã
Pod 㨠ServiceAccount ã®ã©ã£ã¡ã« imagePullSecrets ãè¨å®ããã
ã©ã¡ãã§ãçµæçã«ã¯åããã¨ã§ãããã©ã¡ãã§ãè¯ãã¨ããã°è¯ãã§ããã å人çã«ã¯ Pod ã«è¨å®ããã»ããè¯ãã®ããªã¨æã£ã¦ãã¾ãã
ã¨ããã®ã imagePullSecrets ã¯ã©ã® Docker image ã使ããã«ã®ã¿ä¾åãã Docker image ãæå®ããã¦ãã Pod ã®å®ç¾©å ã§ç®¡çããã»ãã管çããããããã§ãã ServiceAccount 㨠Pod ãå¥ã®ãã¡ã¤ã«ã§ç®¡çãã¦ã㦠Pod ã® Docker image ã Docker Hub 以å¤ã«å¤ããå ´åã ServiceAccount ã® imagePullSecrets ã®ä¿®æ£ãå¿ããå¯è½æ§ãé«ãã§ãã
ä¸æ¹ã§ ServiceAccount ãè¤æ°ã® Pod ã§ä½¿ãã¾ããã¦ããå ´åã ServiceAccount 㧠imagePullSecrets ãæå®ããã»ããä¿®æ£ã¯å°ãªãã¦æ¸ãã¨ããã¡ãªãããããã¾ãã
æããçµç¹ã«ãã£ã¦ ServiceAccount ã®ä½¿ããæ¹ã対象㮠Pod (Deployment, etc) ã®æ°ã¯å ¨ç¶éã£ããããã®ã§ãããã«ãã£ã¦ãå¤ãã£ã¦ããã§ãããã
å¼ç¤¾ã§ã¯ k8s ã®ãããã§ã¹ãã¯å¤§ããåã㦠2 種é¡ããã¾ãã
- åãããã¯ãç¨ã®ãããã§ã¹ã
- System Component
åãããã¯ãç¨ã®ãããã§ã¹ã
åºæ¬çã«åãããã¯ããã¼ã ããªã¼ãã¼ã·ãããæã¡ãèªåãã¡ã§ç®¡çãã¦ãããã®ã§ãã ãã ãã SRE ãä¿®æ£ããããããã¨ãããããã¾ãã
å¼ç¤¾ã§ã¯å
¨ãããã¯ãã®ã¢ããªã±ã¼ã·ã§ã³ã®ã½ã¼ã¹ã³ã¼ãåã³ k8s ã®ãããã§ã¹ãã 1 ã¤ã®ãªãã¸ããª(ã¢ãã¬ã) ã§ç®¡çãã¦ããã
åãã·ã§ã«ã¹ã¯ãªãã㧠kubectl apply
ãå®è¡ãã¦ãããã¤ãã¦ãã¾ãã
ãããã«é¢ãã¦ã¯ããã¾ãæéããªããã¨ãããããããã¤ã¹ã¯ãªããã§å ¨ã¦ã® ServiceAccount ã« imagePullSecrets ã patch ããããã«ãã¾ããã
kubectl get sa -o jsonpath --template '{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -n 1 -I{} kubectl patch sa "{}" -p '{"imagePullSecrets": [{"name": "docker-hub"}]}'
ãã®ããæ¹ã¯ãã¡ãã¡ãããã§ã¹ããä¿®æ£ããªãã¦è¯ããæ¼ããçããªãã¨ããã¡ãªãããããä¸æ¹ã ãããã¤ã宣è¨çã§ãªãæç¶ãçã«ãªã£ã¦ãã¾ãã®ã§ãå°æ¥çã«ã¯å¤ãã¦ããããã¨æãã¾ãã
System Component
DataDog Agent ã Ingress Controller ãªã©ãç¹å®ã®ãããã¯ãã«å±ããã cluster scope ã§åãããã®ã§ãã SRE ããªã¼ãã¼ã·ãããæã£ã¦ãã¦ãåãããã¯ãã¨ã¯å¥ã®ãªãã¸ããªã§ç®¡çãããå¥ã®ã·ã§ã«ã¹ã¯ãªããã§ãããã¤ããã¦ãã¾ãã ã¾ããæè¿ã§ã¯ä¸é¨ã®ãããã¤ã ArgoCD ã«ãã GitOps ã«ç§»è¡ãã¦ãã¾ãã
ãã¡ãã«é¢ãã¦ã¯å¯¾è±¡ãå ¨ãããã¯ãã«æ¯ã¹ãã°å°ãªããã¨ã¨ SRE ããªã¼ãã¼ã·ãããæã£ã¦ãããã¨ãã ä¸ã¤ä¸ã¤ç¢ºèªãã¦ã»ã¼ãããã§ã¹ãã«åæ ãããããã«ãã¾ããã
ä»å¾ã®èª²é¡
ç¾å¨å¼ç¤¾ã§ã¯ k8s ã®ãããã¤ã GitOps ã«ç§»è¡ãã¦ããæä¸ã§ãã ä»åã¯æéããã¾ããªãã£ããããä¸é¨ã§ãããã§ã¹ãã«åæ ããã kubectl ã«ãã£ã¦å¤æ´ãå ãã¦ããé¨åãããã¾ãã ãããæç¶ãçãªãããã¤ã¹ã¯ãªããã¯ã¡ã³ãã大å¤ã§ããã GitOps ã«ç§»è¡ããéã«ãåé¡ã«ãªãã¾ãã ãã®åé¡ã解決ããæ¹æ³ã¯ä¸»ã« 2 ã¤ããã¨æã£ã¦ãã¾ãã
- ãããã§ã¹ãã«åæ ããã
- admission webhook ãªã©ãå©ç¨ããèªå㧠imagePullSecrets ãªã©ãåæ ãããããã«ãã
ãããã§ã¹ãã«åæ ãããå ´åãå°æ¥çã«ãæ¼ããçããªãããã«ããããã CI ã§ã®ããªãã¼ã·ã§ã³ãå¿ è¦ã«ãªãã¨æã£ã¦ãã¾ãã Conftest ã«ãã£ã¦ Docker Hub ã®ã¤ã¡ã¼ã¸ã ã£ãã imagePullSecrets ãå¿ é ã¨ãããããªããªãã¼ã·ã§ã³ãèãããã¾ãã
å¾è 㯠k8s ã«é¢ããå¿ç¨çãªç¥èãå¿ è¦ã ã£ãããã¦é£æ度ãé«ããªã®ã§ãããä¸æãããã°æ¼ããªãèªè¨¼ã§ãããã¨ãä¿è¨¼ããã¾ããã admission webhook ã®éçºã«ææ¦ããè¯ãæ©ä¼ããªã¨æãã¾ãã