Share
Embed
Transcript
58 slides
-
AKS 101 2020 / 05 / 26 Kubernetes Novice Meetup
on Youtube @URyo_0213 -
Who am I ? ry (@URyo_0213) Infrastructure Engineer ◦ Storage構築
◦ Kubernetes, Python, Ansible • Kubernetes歴: 1年ちょっと -
What can we use for practice? • kubeadm • Kind
(Kubernetes in Docker) • Kubernetes Services ◦ AKS (Azure) ◦ EKS (AWS) ◦ GKE (GCP) -
What I’ll talk about • kubeadm • Kind (Kubernetes in
Docker) • Managed Services ◦ AKS (Azure) ◦ EKS (AWS) ◦ GKE (GCP) -
Kubernetes Architecture in Azure • Cluster = Control Plane(Azure Managed)
+ Node (Customer Managed) • Versionが豊富 • 1ヶ月 $200 クレジット(Azure全体) • 1NodeのClusterで多くて1000円/day (放置するだけなら400円程度) • DefaultのNode Specは、Standard_DS2_v2 ◦ vCPU: 2, Ram: 7GiB, 一時storage(SSD): 14GiB (GiB = 1024^3 Byte) ※kubectl alpha debug はdisableになってます。 -
AKS Cluster • Control Plane (Master Node) ◦ AKS クラスターを作成時、自動的に作成される。
◦ 課金対象にはならない。 ◦ 特定の方法で構成したいとか、直接のアクセスが必要などの用件がある場 合は、aks-engine を使用する必要がある。 • Node (Worker Node) ◦ Serviceを動かす際に、1 つ以上のノードが必要。 ◦ CPU 数、メモリ量、ストレージのサイズと種類 (SSD, HDD など) を指定可 能。 ◦ 同じ構成のNodeは同一Node Poolに所属する。 -
Node Pool Node数1で作成したAKS Clusterの例は以下のようになる。 $ az aks nodepool list --resource-group
kubernetes --cluster-name aksCluster -o table Name OsType KubernetesVersion VmSize Count MaxPods ProvisioningState --------- -------- ------------------- --------------- ------- --------- ------------------- nodepool1 Linux 1.15.10 Standard_DS2_v2 1 110 Succeeded nodepool1に入るのは、 OS: Linux Kubernetes Version: 1.15.10 VM Size: Standard_DS2_v2 であるNodeのみ -
Node Pool $ az aks nodepool add --resource-group kubernetes --cluster-name
aksCluster --name nodepool2 --node-count 1 --node-vm-size Standard_DS1_v2 --kubernetes-version 1.15.7 $ az aks nodepool list --resource-group kubernetes --cluster-name aksCluster -o table Name OsType KubernetesVersion VmSize Count MaxPods ProvisioningState --------- -------- ------------------- --------------- ------- --------- ------------------- nodepool1 Linux 1.15.10 Standard_DS2_v2 1 110 Succeeded nodepool2 Linux 1.15.7 Standard_DS1_v1 1 110 Succeeded $ kubectl get nodes NAME STATUS ROLE AGE VERSION aks-nodepool1-23888308-vmss000000 Ready agent 77m v1.15.10 aks-nodepool2-23888308-vmss000000 Ready agent 8m50s v1.15.7 -
Contents • Set up AKS Cluster ◦ Step1. Create Resource
Group ◦ Step2. Deploy AKS Cluster ◦ Step3. Get Credential • Deploy Application ◦ Create nginx pod ◦ Create nginx pod with ACR • Monitoring -
Set up AKS Cluster • Step1. Create Resource Group •
Step2. Deploy AKS Cluster • Step3. Get Credential -
Step1: Create Resource Group Resource Group: 以下のコマンドにて作成。 $ az group
create -n kubernetes -l eastus2 ※terraformで作成する際は、作成はしないですすむ 。 -
Step2: Deploy AKS Cluster 3つの作成法を紹介 • Azure Portal (GUI) •
Azure ctl 以下は、Appendixを参照ください。 • Terraform ◦ tf files (https://github.com/ryojsb/AKS-Terraform) -
Azure Portal ~step2~ 「Next」を押して詳細に設定をしていく場合 • Node pools ◦ 追加のNode Pool設定
◦ Virtual Node (必要なときのみ立ち上げるノード ) ◦ VM Scale Sets (同一Nodeをグルーピングし、自動スケーリングを実施 ) • Authentication ◦ Service principals (Azure上でのアプリケーションがもつ ID) ◦ RBAC • Networking • Integrations ◦ ACR (Azure Container Registry) ◦ Azure Monitor • Tag -
Azure ctl $ az aks create -g kubernetes -n aksCluster
\ --kubernetes-version 1.15.10 --node-count 1 \ --generate-ssh-keys その他、optionは以下を参照。 https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-create -
Step3: Get Credential AKSが作成されたことを確認。 $ az aks list -o table
Name Location ResourceGroup KubernetesVersion ProvisioningState Fqdn ---------- ---------- --------------- ------------------- ------------------- ----------------------------------------------------------- aksCluster eastus2 kubernetes 1.15.10 Succeeded akscluster-kubernetes-cb54f9-9f418604.hcp.eastus2.azmk8s.io Contextの追加をする。 $ az aks get-credentials --resource-group kubernetes --name <aks cluster名> Cluster の確認をします。 $ kubectl get nodes NAME STATUS ROLES AGE VERSION aks-nodepool1-28971671-vmss000000 Ready agent 7m26s v1.15.10 -
Deploy Option • Deploy application with outside registry 以下はAppendixを参照ください。 •
Deploy application with ACR (Azure Container Registry) -
Create nginx pod ~ Apply Manifest ~ $ kubectl create
ns nginx $ kubectl apply -f deployment.yaml -n nginx $ kubectl get all NAME READY STATUS RESTARTS AGE pod/sample-nginx-75444db6d6-dv9pd 1/1 Running 0 87s pod/sample-nginx-75444db6d6-gbfz9 1/1 Running 0 87s pod/sample-nginx-75444db6d6-xrbxq 1/1 Running 0 87s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 27h service/nginx-service LoadBalancer 10.0.144.35 52.167.75.0 80:32552/TCP 87s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/sample-nginx 3/3 3 3 88s NAME DESIRED CURRENT READY AGE replicaset.apps/sample-nginx-75444db6d6 3 3 3 88s ※ LoadBalancer使用時は、切り出されたExternal IPが使用後も残ったままにならないようご注意ください -
http://<External IP of Load balancer for nginx>:80 Create nginx pod
~ Check the application ~ -
OSS - Prometheus ・Grafana (Metrics) - ELK (Logging) - etc
SaaS - DataDog - Sysdig - etc Azure Native - Azure Monitoring AKS Monitoring options -
OSS - Prometheus ・Grafana (Metrics) - ELK (Logging) - etc
SaaS - DataDog - Sysdig - etc Azure Native - Azure Monitoring AKS Monitoring options -
Azure Monitor for container Kubernetes クラスターのパフォーマンスと正常性、およびコンテナーのワークロード を把握できます。 • 設定 ◦
GUI: AKS Cluster作成時にdefaultでEnableになっています。 ◦ CLI: 「--enable-addons monitoring」オプション 主に以下を見ていく - Insight - Metric - Log Azure Monitoring -
Azure Monitoring ~ Insight ~ Insightでは、NodeやContainerの現状を可視化してくれます。 • Cluster ◦ Node
CPU utilization % ◦ Node memory utilization % ◦ Node count ◦ Active pod count • Health (Preview) ◦ Kubernetesのインフラ(API server, Core DNS, kube-proxy, etc…)等のStatusを確認可能 • Node ◦ Node毎のPodのStatusを確認可能 • Container ◦ 各ContainerのStatusを確認可能 • Deployment (Preview) ◦ 各DeploymentのStatusを確認可能 -
Azure Monitoring ~ Metric ~ 以下の項目を指定し、グラフを表示可能 • Scope: <Cluster名> •
Metric Namespace: Metricを取得する対象 ※ KubernetesのNamespaceではない • Metric: 取得したいMetric • Aggregation: Avg, Max, Min -
Terraform ~step5~ 4. 以下のコマンドを実施 $ az storage container create -n
tfstate \ --account-name <YourAzureStorageAccountName> \ --account-key <YourAzureStorageAccessKey> 5. 以下を実施し、出力の<appID> 及び <password> を記録する。 $ az ad sp create-for-rbac --skip-assignment --name <ServicePrincipal名> -
Terraform ~step6 (AKS 構築)~ あとは、以下のコマンドを実施して構築完了です。 $ terraform init -backend-config="storage_account_name=<YourAzureStorageAccountName>" \
-backend-config="container_name=tfstate" \ -backend-config="access_key=<YourStorageAccountAccessKey>" \ -backend-config="key=codelab.microsoft.tfstate" $ export TF_VAR_client_id=<service-principal-appid> $ export TF_VAR_client_secret=<service-principal-password> $ terraform plan -out out.plan $ terraform apply out.plan -
Step1. Create ACR Step2. Login to ACR Step3. Push an
image to ACR Step4. Establish authentication for ACR Step5. Deploy an application Create nginx pod with ACR (Azure Container Registry) -
以下のコマンドで、ACRを作成します。 $ az acr create --resource-group kubernetes --name rySampleACR --sku
Basic 確認をする。 $ az acr list -o table NAME RESOURCE GROUP LOCATION SKU LOGIN SERVER CREATION DATE ADMIN ENABLED ----------- ---------------- ---------- ----- ---------------------- -------------------- --------------- rySampleACR kubernetes eastus2 Basic rysampleacr.azurecr.io 2020-03-29T07:50:04Z ここの「LOGIN SERVER」を記録しておいてください。 Step1. Create ACR -
現在、何も入っていない状態である。 $ az acr repository list --name rySampleACR [] docker
tag コマンドでimage名を変えたものをpushします。 $ docker push rysampleacr.azurecr.io/nginx:1.17.5 確認してみます。 $ az acr repository list --name rySampleACR [ "nginx" ] Step3. Push an image to ACR -
AKSとACRとの間で認証が構成されている必要があります。 まず、AKS に対して構成されているサービス プリンシパルの IDとACRのリソースIDを取得します。 $ CLIENT_ID=`az aks
show --resource-group kubernetes --name aksCluster --query "servicePrincipalProfile.clientId" --output tsv` $ ACR_ID=`az acr show --name rySampleACR --resource-group kubernetes --query "id" --output tsv` その後、適切なアクセス権を付与するロールを作成します。 $ az role assignment create --assignee $CLIENT_ID --role Reader --scope $ACR_ID --output json > ./Create_Role-`date "+%Y%m%d_%H%M%S"`.json Step4. Establish authentication for ACR -
Step5. Deploy an application ~ Create manifest ~ • vi
deployment.yaml -
Step5. Deploy an application ~ Create manifest ~ $ kubectl
create ns nginx2 $ kubectl apply -f deployment.yaml -n nginx2 $ kubectl get all -n nginx2 NAME READY STATUS RESTARTS AGE pod/sample-nginx2-d96fc9f8-hf7jj 1/1 Running 0 52s pod/sample-nginx2-d96fc9f8-m6fsg 1/1 Running 0 52s pod/sample-nginx2-d96fc9f8-x5mhv 1/1 Running 0 52s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/nginx-service LoadBalancer 10.0.49.148 40.70.168.193 80:31531/TCP 52s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/sample-nginx2 3/3 3 3 53s NAME DESIRED CURRENT READY AGE replicaset.apps/sample-nginx2-d96fc9f8 3 3 3 53s -
http://<External IP of Load balancer for nginx>:80 Step5. Deploy an
application ~ Check the application ~