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
700
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめての CircleCI × EKS
enta0701
January 25, 2019
More Decks by enta0701
See All by enta0701
ミルクココアが好きです
endotakuya
0
72
Kubernetes 超入門
endotakuya
0
150
GKE と EKS について 理解した気分になる7分間
endotakuya
0
79
Go / Node.js で入門する gRPC
endotakuya
0
210
LINE Clova スキルの開発ハンズオンに enebular は最適だった話。
endotakuya
1
1.1k
LINE Clova と自由に会話をしよう
endotakuya
0
200
GoでClova Extension開発ができるようになりました
endotakuya
0
80
シンプルなテンプレートエンジンが欲しい
endotakuya
0
840
Alfred Workflows by Go
endotakuya
4
5.5k
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
370
Embracing the Ebb and Flow
colly
88
5.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Ethics towards AI in product and experience design
skipperchong
2
340
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Bash Introduction
62gerente
615
220k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
My Coaching Mixtape
mlcsv
0
200
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
650
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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 名を叩けば…
ね?簡単でしょ?