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
Azureで学ぶ 実践Kubernetes
Search
shin5ok
April 10, 2018
Technology
3
2.4k
Azureで学ぶ 実践Kubernetes
Microsoft Azure上でマネージド型Kubernetesを構築し、
コンテナアプリケーションを展開し、運用します
実践的なノウハウに加えて、最新情報についても説明します
shin5ok
April 10, 2018
Tweet
Share
More Decks by shin5ok
See All by shin5ok
Amazon EKS Quick Dive
shin5ok
1
1k
Amazon EKS Overview and Updates
shin5ok
0
250
コンテナ実践入門
shin5ok
0
150
AWS Partner Champion Members コンテナ編
shin5ok
0
93
AKSでマイクロサービス Bootcamp
shin5ok
0
190
Kubernetes has come on Azure / デモでわかるAKS
shin5ok
0
440
Azureで学ぶ 実践Kubernetes ハンズオン用資料
shin5ok
2
160
Azure コンテナプラットフォーム クイックツアー
shin5ok
0
180
(Azure Antenna)AKSでコンテナアプリ DockerからKubernetesまで実践入門
shin5ok
4
2k
Other Decks in Technology
See All in Technology
What's new in OpenShift 4.20
redhatlivestreaming
0
300
RemoteFunctionを使ったコロケーション
mkazutaka
1
120
ラスベガスの歩き方 2025年版(re:Invent 事前勉強会)
junjikoide
0
340
serverless team topology
_kensh
3
240
東京大学「Agile-X」のFPGA AIデザインハッカソンを制したソニーのAI最適化
sony
0
100
激動の時代を爆速リチーミングで乗り越えろ
sansantech
PRO
1
120
あなたの知らない Linuxカーネル脆弱性の世界
recruitengineers
PRO
3
160
OSSで50の競合と戦うためにやったこと
yamadashy
3
1k
AI時代、“平均値”ではいられない
uhyo
8
2.6k
マルチエージェントのチームビルディング_2025-10-25
shinoyamada
0
190
QA業務を変える(!?)AIを併用した不具合分析の実践
ma2ri
0
150
[読書]AWSゲームブック〜GuardDuty魔神とインシデント対応の旅〜DevIO2025
cmusudakeisuke
0
200
Featured
See All Featured
How to Ace a Technical Interview
jacobian
280
24k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
A designer walks into a library…
pauljervisheath
209
24k
It's Worth the Effort
3n
187
28k
Reflections from 52 weeks, 52 projects
jeffersonlam
354
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Being A Developer After 40
akosma
91
590k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Writing Fast Ruby
sferik
630
62k
Transcript
None
Kubernetes on Azureの知識を持ち帰り、 (自社|自宅)で実践できるようになること
※5時間ではギリギリの内容なので、ハンズオンをスキップすることがあります あらかじめご了承ください!
None
None
None
None
None
※ 最新のDocker CEの利用について http://docs.docker.jp/engine/installation/docker-ce.html
None
None
None
None
# ubuntu最新版を実行して対話モードに入る > docker run –it ubuntu # exit でログアウト(コンテナ終了)
# Azure cli2.0最新版を取得してmycliという名前で起動、 # 対話モードに入る > docker run --name mycli -it azuresdk/azure-cli-python:2.0.20 # exit でログアウト(コンテナ終了) # apache 2.4.29を実行してデーモンモードで起動 # ホストの80番を、コンテナの80番に転送する > docker pull httpd:2.4.29 > docker inspect httpd:2.4.29 > docker run -d -p 80:80 httpd:2.4.29
None
# 'ubuntu'文字列を含むイメージの検索 > docker search ubuntu # ubuntuの14:10タグのイメージを取得(実行しない) > docker
pull ubuntu:14.10 # 現在起動中のコンテナの表示 > docker ps # コンテナの停止 > docker stop [コンテナID] # ローカルにあるコンテナイメージのリスト > docker images
None
None
None
FROM alpine:3.6 RUN apk update && apk add python2 py-pip
git openrc mongodb curl && mkdir -p /data/db RUN git clone https://
[email protected]
/shkawan/docker-appsample.git WORKDIR /docker-appsample RUN pip install -r requirements.txt USER nobody CMD [ "./entry.sh" ] localhost > docker build -t myappsample . localhost > docker tag myappsample shkawan/myappsample:v7.00 localhost > docker push shkawan/myappsample:v7.00 anotherhost > docker run -p 80:8000 -d --name myapache shkawan/myappsample:v7.00
None
None
None
None
None
None
None
None
None
None
bash > git clone https://
[email protected]
/shkawan/docker-appsample.git
FROM alpine:3.6 MAINTAINER
[email protected]
RUN apk update && apk add
python2 py-pip git openrc mongodb curl RUN mkdir -p /data/db COPY *.py ./ COPY entry.sh ./ COPY requirements.txt ./ COPY VERSION ./ RUN pip install -r requirements.txt USER nobody CMD [ "./entry.sh" ]
参考: Dockerコンテナで避けるべき10のこと https://developers.redhat.com/blog/2016/02/24/10-things-to-avoid-in-docker-containers/
None
version: '2' services: myappsample: # コンテナ名 image: shkawan/appsample:v7.00 # 取得するイメージ
environment: # 環境変数の設定 - MONGODB_PORT=27017 - MONGODB_HOST=mongodb ports: - 8000:8000 # ホストのポートをbind mymongodb: # コンテナ名 image: mongo:3.6.0 # DockerHub上のイメージを取得 volumes: # ホストのボリュームをマッピング - /tmp/mongodb:/data/db bash > docker-compose up -d
None
Dockerデーモン アプリ3 アプリ1 アプリ2
アプリ1 アプリ2 アプリ3 アプリ6 アプリ4 アプリ5 アプリ6 アプリ9 アプリ8 アプリ10
Dockerデーモン Dockerデーモン Dockerデーモン アプリ7
None
アプリ1 アプリ2 アプリ3 アプリ6 アプリ4 アプリ5 アプリ6 アプリ9 アプリ8 アプリ10
Dockerデーモン Dockerデーモン アプリ7
None
None
None
None
https://octoverse.github.com/
https://kubernetes.io/
None
None
None
None
# AKSが利用可能になっているか確認 shell > az provider show –n Microsoft.ContainerService –o
table Namespace RegistrationState -------------------------- ------------------- Microsoft.ContainerService Registered # 上記のように、’Registered’ でなかったら、registerを実行 shell > az provider register –n Microsoft.ContainerService # 再度、確認します shell > az provider show –n Microsoft.ContainerService –o table
# まず AKSの名前、リソースグループの名前、deployするリージョンを決めます shell > AKS_NAME=shkawan-aks shell > AKS_RESOURCE_GROUP=$AKS_NAME shell
> AKS_LOCATION=eastus # 準備 shell > az login shell > az group create -n $AKS_NAME -l $AKS_LOCATION # 1発 deploy shell > az aks create -n $AKS_NAME -g $AKS_RESOURCE_GROUP -l $AKS_LOCATION ¥ shell >> --generate-ssh-keys
# kubectlコマンドのインストール shell > az aks install-cli # 資格情報の取得 shell
> az aks get-credentials -g $AKS_RESOURCE_GROUP -n $AKS_NAME shell > kubectl version # 補完を有効に shell > echo "source <(kubectl completion bash)" >> ~/.bashrc shell > source ~/.bashrc
None
# なにも動いていないことを確認 shell > kubectl get pods # nginx公式1.13.5-alpineを取得して、mynginxという名前で実行 shell
> kubectl run mynginx --image=nginx:1.13.5-alpine # mynginxが動いていることを確認する shell > kubectl get pods NAME READY STATUS RESTARTS AGE mynginx-3071068301-pbvnz 1/1 Running 0 1h # IPを設定して公開、IPを確認する shell > kubectl expose deploy mynginx --port=80 --type=LoadBalancer shell > kubectl get services
None
None
https://Kubernetes.io/docs/tutorials/object-management-kubectl/object-management/ 管理手法 操作対象 推奨環境 学習コスト 主なツール 命令的コマンド 動作中のオブジェクト 開発 低い
kubectl 等 命令的設定ファイル ファイル プロダクション 普通 エディタ Git 宣言的設定ファイル ディレクトリ ファイル プロダクション 高い エディタ Git
None
None
None
None
None
None
None
None
None
# Dockerhub上のサンプルアプリを取得して実行 shell > kubectl run myappsample --image=shkawan/appsample:v7.00 --record #
サンプルアプリが動いていることを確認する shell > kubectl get pods # IPを設定して公開、IPを確認する shell > kubectl expose deploy myappsample --port=80 --type=LoadBalancer shell > kubectl get services
shell > kubectl scale --replicas=5 deployment myappsample # サンプルアプリのレプリカが増えていることを確認する shell
> kubectl get pods shell > kubectl set image deployment myappsample myappsample=shkawan/appsample:v5.11 # サンプルアプリのPodにローリングアップデートがかかっていることを確認する shell > kubectl get pods --watch
Deployment Service Replicaset Pods kube-system Pods User Namespace
None
None
None
shell > MONGODB_URI=外部のMONGODBを参照するURI shell > kubectl set env deploy myappsample
MONGODB_URI=$MONGODB_URI
None
None
None
None
SSL Gateway用 × 2 アプリ表示用 × 4 通知用 × 2
コメント用 × 2 Cosmos DB Log Analytics
None
SSL Gateway用 × 2 アプリ表示用 × 4 通知用 × 2
コメント用 × 2 Cosmos DB Log Analytics Immutable Immutable Immutable Immutable
SSL Gateway用 × 2 アプリ表示用 × 4 通知用 × 2
コメント用 × 2 Cosmos DB Log Analytics
None
管理手法 操作対象 推奨環境 学習コスト 主なツール 命令的コマンド 動作中のオブジェクト 開発 低い kubectl
等 命令的設定ファイル ファイル プロダクション 普通 エディタ Git 宣言的設定ファイル ディレクトリ ファイル プロダクション 高い エディタ Git
shell > cd k8s.demo/manifest/ # 値を編集します shell > vi ./1-configmap.yml
shell > vi ./2-secret.yml shell > kubectl apply -f ./0-namespace.yml shell > kubectl apply -f ./1-configmap.yml shell > kubectl apply -f ./2-secret.yml shell > kubectl apply -f ./3-deployment.yml shell > kubectl apply -f ./4-service.yml
SSL Gateway用 × 2 アプリ表示用 ×4 通知用 × 2 コメント用
× 2 Cosmos DB
None
shell > cd k8s.demo/manifest/ # 値を編集します shell > vi ./loganalytics/configmap.yml
shell > kubectl apply -f ./loganalytics/loganalytics.yml
SSL Gateway用 × 2 アプリ表示用 ×4 通知用 × 2 コメント用
× 2 Cosmos DB Log Analytics
None
shell > vim ./deployment.yml --- a/manifest/3-deployment.yml +++ b/manifest/3-deployment.yml @@ -7,7
+7,7 @@ metadata: name: myappsample namespace: myapp spec: - replicas: 2 + replicas: 4 strategy: rollingUpdate: maxSurge: 1 shell > kubectl apply -f ./3-deployment.yml
SSL Gateway用 × 2 アプリ表示用 ×4 通知用 × 2 Cosmos
DB Log Analytics コメント用 × 4
shell > vim ./deployment.yml --- a/manifest/3-deployment.yml +++ b/manifest/3-deployment.yml @@ -140,7
+140,7 @@ spec: value: myappsample - name: NOTIFY_URI value: http://mynotifypod/api/slack - image: shkawan/websample:v0.75 + image: shkawan/websample:v0.78 imagePullPolicy: IfNotPresent name: mywebsample dnsPolicy: ClusterFirst shell > kubectl apply -f ./3-deployment.yml
SSL証明書をsecretで管理 証明書更新時のコンテナbuildを不要に Ingressの導入
None
None
None
None
SHIP RUN AUTO TEST and BUILD RUN
None
# 現在のノード数を確認 # Azureで確認 shell > az aks show -n
$AKS_NAME -g $AKS_RESOURCE_GROUP | jq .properties.agentPoolProfiles # k8s上での確認 shell > kubectl get nodes # コマンド一発 shell > az aks scale -n $AKS_NAME -g $AKS_RESOURCE_GROUP --node-count 5 # Azure上、k8s上で確認
# 現在のバージョンと、アップグレード可能なバージョンを確認 shell > az aks get-versions -n $AKS_NAME -g
$AKS_RESOURCE_GROUP -o table shell > az aks upgrade --Kubernetes-version 1.8.1 -g $AKS_RESOURCE_GROUP -n $AKS_NAME
None
None
None
None
None
None
None
https://istio.io/docs/concepts/what-is-istio/overview.htm
None
PaaS型 サーバレス マネージド Kubernetes フル Kubenetes
None
None
None
None
$ az container create -n MyACI -g MyACI --ip-address Public
-l westus ¥ > --image shkawan/basicapi:v1
None
None
None
None
None
None