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 × EKS
Search
enta0701
January 25, 2019
1
650
はじめての CircleCI × EKS
enta0701
January 25, 2019
Tweet
Share
More Decks by enta0701
See All by enta0701
ミルクココアが好きです
endotakuya
0
31
Kubernetes 超入門
endotakuya
0
130
GKE と EKS について 理解した気分になる7分間
endotakuya
0
61
Go / Node.js で入門する gRPC
endotakuya
0
180
LINE Clova スキルの開発ハンズオンに enebular は最適だった話。
endotakuya
1
1k
LINE Clova と自由に会話をしよう
endotakuya
0
180
GoでClova Extension開発ができるようになりました
endotakuya
0
69
シンプルなテンプレートエンジンが欲しい
endotakuya
0
780
Alfred Workflows by Go
endotakuya
4
3.1k
Featured
See All Featured
Building an army of robots
kneath
306
45k
Done Done
chrislema
184
16k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
GitHub's CSS Performance
jonrohan
1031
460k
Rails Girls Zürich Keynote
gr2m
94
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Stop Working from a Prison Cell
hatefulcrawdad
269
20k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
A Modern Web Designer's Workflow
chriscoyier
693
190k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Agile that works and the tools we love
rasmusluckow
329
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.4k
Transcript
はじめての CircleCI × EKS Created by @endotakuya
話すこと CircleCI 経由 で EKS へデプロイする方法 環境変数の取り扱い ALB の DNS
名でアクセスする設定
話さないこと Kubernetes の概念や用語 Kubernetes の各種設定 CircleCI v2 の 詳細設定 ECR
の使い方
CircleCI 経由 で EKS へデプロイ
前提 / 準備 Rails Application MySQL Nginx 各コンテナの Docker イメージが作れる(Build
できる)こと。
CirlceCI AWS の各リソースへの操作は awscli を使用 ... deploy: &deploy <<: *defaults
docker: - image: circleci/python:3.5 - run: name: Install the AWS CLI command: | sudo pip install --upgrade pip sudo pip install awscli==1.16.89 - run: # build / push - run: # deploy ...
CirlceCI ― Docker イメージ の Build/Push shell script でごりごり。 #
Docker Login eval $(aws ecr get-login --region ap-northeast-1 --no-include-email) # Docker image # app app=xxxx.dkr.ecr.ap-northeast-1.amazonaws.com/example/app:$CIRCLE_SHA1 docker build -t $app -f .docker/app/Dockerfile . docker push $app # web ...
CirlceCI ― Deploy 1. 必要なコマンドをインストール 2. 対象のクラスタをセット # Install kubectl
... # Install aws-iam-authenticator ... # Set cluster aws eks update-kubeconfig --name $AWS_EKS_CLUSTER_NAME kubectl config use-context $AWS_EKS_CLUSTER_ARN
CirlceCI ― Deploy envsubst により、環境変数を設定ファイルの k8s の yaml に埋め込む #
Deploy sudo apt-get update && sudo apt-get install -y gettext-base k8s_resource_path=./.docker/.k8s for file in $k8s_resource_path/*.yaml; do envsubst < $file | kubectl apply -f - done これで、External IP が発行されればOK ※ k8s の設定ファイルは BananaCI の設定とほとんど同じです
環境変数の取り扱い
CirlceCI での環境変数 恐らくリポジトリで設定してるはず
本番 / ステージングはどうする?
CircleCI Contexts Organization や Account 単位で環境変数郡を作成することができる
CircleCI Contexts (ex.) example-production AWS_EKS_CLUSTER_NAME RAILS_ENV MYSQL_HOST example-staging AWS_EKS_CLUSTER_NAME RAILS_ENV
MYSQL_HOST
CircleCI Contexts の呼び出し方 work ow の job 呼び出し時に指定する workflows: version:
2 build_and_deploy: jobs: - deploy-staging: context: example-staging - deploy-production: context: example-production filters: branches: only: - release
ALB の DNS 名でアクセスする設定
Ingress L7 層レベル(http/https のパスベースで負荷分散ができる)で Service を介して、クラスタを外部とつなぐ apiVersion: extensions/v1beta1 kind: Ingress
metadata: name: example-ingress spec: rules: - http: paths: - path: /* backend: serviceName: example-svc # Service 名 servicePort: 80
ALB Ingress Controller kubernetes-sigs/aws-alb-ingress-controller ingress を作成したタイミングで ALB やターゲットグループを作成 セキュリティグループやサブネットを自動検出して関連付け 対象クラスタやアクセキーを設定するだけ
$ kubectl apply -f alb-rbac-role.yaml
RBAC Role-Based Access Control クラスタの操作権限や内部の Kubernetes API の操作ユーザーを限定 alb-ingress-controller は、一般ユーザが容易に触れないほうがいいの
で、操作を限定したユーザーを作成 https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress- controller/v1.0.0/docs/examples/rbac-role.yaml $ kubectl apply -f alb-rbac-role.yaml
ALB の DNS 名を叩けば…
ね?簡単でしょ?