Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kubernetes on AWS - Amazon EKSとそれを支えるServicesやTools -

Kubernetes on AWS - Amazon EKSとそれを支えるServicesやTools -

Developers Summit 2020 KANSAI 2020年8月27日(木)

はまーん

August 27, 2020
Tweet

More Decks by はまーん

Other Decks in Technology

Transcript

  1. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    on AWS - Amazon EKS とそれを支える Services や Tools - Shinichi Hama Solutions Architect Amazon Web Services Japan/ Solutions Architecture Developers Summit 2020 KANSAI
  2. © 2020, Amazon Web Services, Inc. or its Affiliates. 自己紹介

    Shinichi Hama Twitter/@track3jyo Solutions Architect Amazon Web Service Japan 西日本のお客様の支援 & Container のあれこれ <好きなAWSサービス> Amazon ECS Amazon EKS AWS Fargate Amazon DynamoDB
  3. © 2020, Amazon Web Services, Inc. or its Affiliates. このセッションについて

    • このセッションで話すこと • Kuberenets や Amazon EKS の概要について • Amazon EKS で Kubernetes 環境を実行する際に有益なサービス やツールについて • このセッションで話さないこと • コンテナとは? • Kubernetes の詳細なリソースについて #devsumi
  4. © 2020, Amazon Web Services, Inc. or its Affiliates. Agenda

    • Container on AWS 概要 • Kubernetes / Amazon EKS について • Amazon EKS の周りにある世界 #devsumi
  5. © 2020, Amazon Web Services, Inc. or its Affiliates. Agenda

    • Container on AWS 概要 • Kubernetes / Amazon EKS について • Amazon EKS の周りにある世界 #devsumi
  6. © 2020, Amazon Web Services, Inc. or its Affiliates. AWS

    コンテナサービスの歴史 2014.11 - AWSネイティブな コンテナオーケストレーションツール 2015.12 - プライベートな コンテナイメージレジストリ 2016 セキュリティ, ネットワーク, Windows コンテナ, … 2017.11 - AWSマネージドなコンテナ実行環境 - Kubernetes のマネージドサービス 2018.12 - サービスメッシュ - サービスディスカバリ 2019.05 - コンテナのためのモニタリング Amazon CloudWatch Container Insights 2019.12 - Fargate for EKS AWS Fargate AWS Fargate AWS Cloud Map #devsumi
  7. © 2020, Amazon Web Services, Inc. or its Affiliates. AWS

    コンテナサービスの歴史 2014.11 - AWSネイティブな コンテナオーケストレーションツール 2015.12 - イメージレジストリ 2016 セキュリティ, ネットワーク, Windows コンテナ, … 2017.11 - AWS マネージドなコンテナ実行環境 - Kubernetes のマネージドサービス 2018.12 - サービスメッシュ - サービスディスカバリ 2019.05 - コンテナのためのモニタリング Amazon CloudWatch Container Insights 2019.12 - Fargate for EKS AWS Fargate AWS Fargate AWS Cloud Map 90~95% お客様からいただいたご要望を基に構築された AWS のサービスや機能の割合 #devsumi
  8. © 2020, Amazon Web Services, Inc. or its Affiliates. AWSコンテナサービスを数字で見る

    80% クラウドのすべてのコンテナ化され た実⾏中のアプリケーションのうち AWS で実⾏されている割合 150% AWS コンテナサービスの 前年比の成長 10倍 1 年間の EKS 使⽤量の増加 3倍 1 年間の Fargate 使⽤量の増加 毎週 1 億タスクを実⾏ 20億以上 ECR を使⽤した毎週 Pull される Image の数 https://aws.amazon.com/jp/containers/ #devsumi
  9. © 2020, Amazon Web Services, Inc. or its Affiliates. Agenda

    • Container on AWS 概要 • Kubernetes / Amazon EKS について • Amazon EKS の周りにある世界 #devsumi
  10. © 2020, Amazon Web Services, Inc. or its Affiliates. コンテナ実⾏(RUN)時の課題

    ホスト ホスト ホスト ホスト ホスト ホスト ホスト ホスト ホスト ホスト #devsumi
  11. © 2020, Amazon Web Services, Inc. or its Affiliates. コンテナ実⾏(RUN)時の課題と要望

    • 耐障害性 • コンテナのホストが停⽌したらコンテナ全滅、機能停⽌ • 運⽤性 • コンテナはどのホストで動かす︖リソースは空いてる︖ • 通信したいコンテナはどこにいる︖(IPは︖名前は︖) • リソース制限を⼀括でかけたい • スケール • 負荷に応じて、コンテナをスケールしたい • 同種のコンテナ間でロードバランスしたい ホスト ホスト #devsumi
  12. © 2020, Amazon Web Services, Inc. or its Affiliates. Docker

    の責務 • Docker の責務は同⼀サーバ上のコンテナライフサイクル管理 • 複数サーバやコンテナを束ねた概念に対するオペレーションはスコープ外 #devsumi
  13. © 2020, Amazon Web Services, Inc. or its Affiliates. コンテナオーケストレーションツール

    コンテナオーケストレーションツール • 複雑なコンテナ運⽤の管理を⾏うツール • コンテナオーケストレーションツールの⼀つである OSS の Kubernetes #devsumi
  14. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    の概要 • 複数のホスト間でコンテナ化された アプリケーションを管理するオープン ソースシステム • Cloud Native Computing Foundation (CNCF) によって管理、推進 • “Pod”、”Deployment”、“Service”、 “Job” などのリソースに代表される⾼ い表現⼒ • オーケストレーションツールとして 拡張性が⾮常に⾼い #devsumi
  15. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    が提供する機能 https://kubernetes.io/ #devsumi
  16. © 2020, Amazon Web Services, Inc. or its Affiliates. 宣⾔的な構成管理の⾃動化

    Kubernetes は設定ファイルからクラスタ全体をあるべき状態に収束させる 定義ファイル 定義を適⽤ Kubernetes クラスタ 反映 • 起動する Pod の数 • アプリケーションの バージョン • ロードバランサの設定 • オートスケール の設定 ・ ・ ・ 障害などで宣⾔され た状態が崩れた場 合、⾃動であるべき 状態に復旧させる Client Pod を3つ起動する 設定 #devsumi
  17. © 2020, Amazon Web Services, Inc. or its Affiliates. 多種多様な

    OSS との連携 各種コミュニティにより開発された多種多様なエコシステムとの連携 • Kubernetes のパッケージマネージャ • 各 OSS のインストールやパッケージの展開が可能 Prometheus モニタリング CI/CD サービスメッシュ ネットワーキング CNI CoreDNS Argo CD #devsumi
  18. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    のアーキテクチャ • コントロールプレーンがクラスタ全体の統括を⾏う • データプレーンでは Worker Node (コンテナが動くノード)で コントロールプレー ンの指⽰通りにコンテナが起動する kubectl コマンド Client コントロールプレーン データプレーン Worker Node Worker Node Worker Node #devsumi
  19. © 2020, Amazon Web Services, Inc. or its Affiliates. kubectl

    コマンド • Kubernetes API を実⾏する為のコマンドラインインターフェイス • yaml ファイルで Worker Node 上で動作するリソースを定義し kubectl コマンドで反映される • Kubernetes Master の API Server と呼ばれるコンポーネントがコマンドを受け付けると、各 ワーカーノードに常駐するエージェント(kubelet)に適切にコンテナを維持するよう指⽰ Client Kubernetes master API Server kubectl コマンドを発⾏ データプレーン側で受 け取った命令を実⾏ $ kubectl apply –f kubenetes/pods.yml Worker Node Worker Node kubelet kubelet #devsumi
  20. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    コントロールプレーンのアーキテクチャ scheduler kubectl Worker Node kube- apiserver etcd etcd etcd Add on Controller-Manager Cloud Controller #devsumi
  21. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    on EC2の構成 VPC コントロールプレーン データプレーン Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 Amazon EC2 ELB #devsumi
  22. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    運⽤の悩み • Kubernetes コントロールプレーンの運⽤は「重労働」 • コントロールプレーンの冗⻑化は必須 • 運⽤中の Kubernetes のバージョンアップはたいへん • 運⽤責任はお客様 • もっとアプリケーションを実⾏する部分に集中したい︕ #devsumi
  23. © 2020, Amazon Web Services, Inc. or its Affiliates. A

    m a z o n E l a s t i c K u b e r n e t e s S e r v i ce #devsumi https://aws.amazon.com/jp/eks/
  24. © 2020, Amazon Web Services, Inc. or its Affiliates. Tenet

    1 EKS はプロダクションレベルのワー クロードを動かすための プラットフォームである Tenet 2 EKS はネイティブかつアップスト リームの Kubernetes 体験を提供する。 Tenet 3 EKS ユーザが追加の AWS サービス を使う際に、そのインテグレーショ ンを可能なかぎりシームレスにする Tenet 4 EKS チームは積極的に Kubernetesプ ロジェクトに貢献していくこと #devsumi
  25. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    EKS が提供する価値 “Undifferentiated Heavy Lifting” を削減し、 ビジネス価値の創出に集中できる #devsumi
  26. © 2020, Amazon Web Services, Inc. or its Affiliates. コントロールプレーンをマネージドサービスとして提供

    kubectl コマンド Client コントロールプレーン データプレーン Worker Node Worker Node Worker Node Amazon EKS Kubernetes API Server #devsumi
  27. © 2020, Amazon Web Services, Inc. or its Affiliates. マネージドノードグループにより

    データプレーンの管理も容易に EKS VPC Customer VPC AZ-1 AZ-2 AZ-3 Network Load Balancer EC2 EC2 EC2 EC2 EKS VPC Customer VPC AZ-1 AZ-2 AZ-3 Network Load Balancer managed node group managed node group EC2 EC2 EC2 EC2 #devsumi https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/managed-node-groups.html
  28. © 2020, Amazon Web Services, Inc. or its Affiliates. マネージドノードグループにより

    データプレーンの管理も容易に • マネージドノードグループにより、最新の EKS-optimized AMI から1コマン ドでノードのローリングアップデート可能 • 設定、運⽤が⼤変だったオートスケーリング設定を容易に • ノードを複数の AZ にまたがって展開 • Cluster Autoscaler Discovery ⽤タグ付け • ノードグループ設定のヘルスチェック • ⾃動的な cordon と drain • 8/18[⽇本時間] マネージドノードグループが起動テンプレートをサポート • カスタムセキュリティグループや、カスタム AMI、EC2 ユーザデー タ、EC2 インスタンスへの指定の Tag 付けなどが可能に︕ #devsumi NEW
  29. © 2020, Amazon Web Services, Inc. or its Affiliates. EKS

    アーキテクチャの全体像 EC2 Worker Nodes Network Load Balancer API Access Kubectl Exec/Logs TLS Static IPs ENI Attachment Customer VPC Auto Scaling group ENI EKS VPC コントロールプレーン データプレーン Kubernetes API Server #devsumi
  30. © 2020, Amazon Web Services, Inc. or its Affiliates. Kubernetes

    / EKS のバージョンの考え⽅ • Kubernetes はポリシー上最新 3 マイナーバージョンのみメンテナンスされる • 約3ヶ⽉に1度マイナーバージョンがリリース • EKSも(2020/8/21現在)3マイナーバージョンのみサポート • EKS チームによるテスト通過後に最新のコントロールプレーンのバージョンが⼀般利⽤ 可能になるため、EKS のバージョンは Kubernetes の latest から behind • 対象のバージョンが使用できなくなる場合は最低 2ヶ月前までに AWS よりアナウンス • このバージョンポリシーに従ってクラスターのアップグレードが必要 https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/kubernetes-versions.html • 1.17 <-- EKS の latest version • 1.18 <-- Kubernetes の latest version ※ 2020/8/21 現在 Kubernetes と EKS の最新バージョン差異の例
  31. © 2020, Amazon Web Services, Inc. or its Affiliates. Agenda

    • Container on AWS 概要 • Kubernetes / Amazon EKS について • Amazon EKS の周りにある世界 #devsumi
  32. © 2020, Amazon Web Services, Inc. or its Affiliates. eksctl

    • EKS クラスタを構築、運⽤するための CLI • EKS クラスタとノードグループを作成・スケール・削除することができる Go ⾔語で作成された AWS が公式にサポートする OSS の CLI ツール #devsumi https://eksctl.io/
  33. © 2020, Amazon Web Services, Inc. or its Affiliates. eksctl

    - Getting Started $ eksctl create cluster [i] using region us-west-2 [i] setting availability zones to [us-west-2a us-west-2c us-west-2b] ~ snip ~ [i] waiting for at least 2 node(s) to become ready in "ng-98b3b83a" [i] nodegroup "ng-98b3b83a" has 2 node(s) [i] node "ip-192-168-64-220.us-west-2.compute.internal" is ready [i] node "ip-192-168-8-135.us-west-2.compute.internal" is ready [i] kubectl command should work with “~/.kube/config”, try ‘kubectl get nodes’ [✔] EKS cluster “floral-unicorn-1540567338” in “us-west-2” region is ready $ kubectl apply -f ./your-k8s-manifests/ ~ snip ~ #devsumi
  34. © 2020, Amazon Web Services, Inc. or its Affiliates. eksctl

    - example configuration apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: my-cluster region: us-east-1 version: "1.17" vpc: id: "vpc-11111" cidr: "152.28.0.0/16" subnets: private: us-east-1d: id: "subnet-1111" cidr: "152.28.152.0/21" us-east-1c: id: "subnet-11112" cidr: "152.28.144.0/21" us-east-1a: id: "subnet-11113" cidr: "152.28.136.0/21” managedNodeGroups : - name: ng-1 instanceType: m5.large desiredCapacity: 3 iam: instanceProfileARN: "arn…/eks-nodes-base-role" instanceRoleARN: "arn…/eks-nodes-base-role" privateNetworking: true securityGroups: withShared: true withLocal: true attachIDs: ['sg-11111', 'sg-11112’] ssh: publicKeyName: 'my-instance-key’ tags: 'environment:basedomain': 'example.org' https://eksctl.io/usage/schema/ #devsumi
  35. © 2020, Amazon Web Services, Inc. or its Affiliates. EKS

    クラスター作成/管理における選択肢 • IaC スタイルの公式ツール • eksctl https://eksctl.io • AWS CDK (Cloud Development Kit) https://docs.aws.amazon.com/cdk/ • AWS CloudFormation https://docs.aws.amazon.com/cloudformation/ • その他の公式ツール • AWS SDK https://aws.amazon.com/tools/ • AWS CLI https://aws.amazon.com/cli/ • AWS Management Console https://console.aws.amazon.com/ • サードパーティ製ツール • Terraform • and more
  36. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    VPC CNI プラグイン CNIプラグインによる ネイティブVPC ネットワーキング 複数のPodはVPC内に存在 するようにPod内に同じ VPCアドレスを持つ シンプルでセキュアな ネットワーク GitHub上で 公開されている オープンソース … { } #devsumi
  37. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    VPC CNI プラグイン • VPCのネットワークとKubernetesのネット ワークがシームレスに統合される • VPC CNI により VPC から払い出された IP ア ドレスをホストの ENI に割り当てる • Kubernetes 上の Pod ⽤に対して VPC ネッ トワークから IP アドレスが払い出される #devsumi EC2 instance CNI VPC IPアドレスを要求 1 Secondary IPs: 10.0.0.1 10.0.0.2 ENIに割り当て 2 Veth IP: 10.0.0.1 Veth IP: 10.0.0.2 Podに割り当て 3 Pod Pod https://github.com/aws/amazon-vpc-cni-k8s
  38. © 2020, Amazon Web Services, Inc. or its Affiliates. apiVersion:

    extensions/v1beta1 kind: Ingress metadata: name: ”hama-ingress" namespace: ”hama-devsumi” annotations: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/security-groups: “sg-xxxxxxxxx” labels: app: hama-ingress spec: rules: - http: paths: - path: /* backend: serviceName: "service-hama" servicePort: 80 AWS ALB Ingress Controller • Ingress リソースとして、ALB や関連 する AWS リソースの作成や更新を⾃ 動でトリガーするカスタムコントロー ラー • AWS が公式サポートする OSS ツール • ALB を利⽤した L7 の負荷分散を Ingress リソースとして利⽤可能 #devsumi Pod Pod Pod Ingress L7 Application Load Balancer AWS Ingress Controller  https://github.com/kubernetes-sigs/aws-alb-ingress-controller
  39. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    CloudWatch Container Insights #devsumi
  40. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    CloudWatch Container Insights Agent Dashboards Events Logs Metrics AWS 上でコンテナ化されたアプリケーションに 特化した監視・トラブルシューティングおよび アラームのためのモニタリングサービス ü ⾃動ダッシュボードによる可視化、分析 ü Amazon ECS およびAmazon EKS、 Kubernetes on Amazon EC2にてご利⽤可能 Alarms #devsumi https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/deploy-container-insights-EKS.html
  41. © 2020, Amazon Web Services, Inc. or its Affiliates. •

    Container Insights のダッシュボードを起点により詳細な分析が可能 • CloudWatch Logs Insights や X-Ray Amazon CloudWatch Logs Insights AWS X-Ray • グラフのより詳細な値を⾒たい • ログに対し分析クエリを発⾏したい CloudWatch Logs Insights の要件の例 • タスク間の通信をトレースしたい X-Ray を使う要件の例 Amazon CloudWatch Container Insights #devsumi
  42. © 2020, Amazon Web Services, Inc. or its Affiliates. CloudWatch

    Container Insights Map 表⽰ β版 #devsumi
  43. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    ECR イメージスキャン #devsumi
  44. © 2020, Amazon Web Services, Inc. or its Affiliates. Amazon

    ECR のイメージスキャン機能 Client AWS Cloud ECR Repository Push Image • ECR ネイティブの機能として提供され る脆弱性 (CVEs) の静的スキャン機能 • OSS の CoreOS Clair を利⽤ • Scan on Push, or アドホック • スキャンにかかる費⽤は無料 #devsumi https://aws.amazon.com/jp/blogs/news/amazon-ecr-native-container-image-scanning/
  45. © 2020, Amazon Web Services, Inc. or its Affiliates. AWS

    Fargate for Amazon EKS #devsumi • OS やエージェント類へのパッチ当て・更新 • 実⾏中のコンテナ数に基づく、最適なリソース使⽤率を保つための EC2 インスタンス数のス ケーリング kubelet Docker Agent OS EC2 
  46. © 2020, Amazon Web Services, Inc. or its Affiliates. AWS

    Fargate for Amazon EKS #devsumi AWS Fargate
  47. Fargate for EKS アーキテクチャ Your EKS Cluster running Kubernetes Kubernetes

    API Server 1. Create Pod 2. Evaluate Fargate criteria 3. Set scheduler name on Pod EKS Fargate Profile etcd 4. Persist intent Default Scheduler Based on Scheduler Name Your VPC EC2 instances Fargate VPC Fargate EKS Agents 5. Acquire Capacity 7. Report Pod as Running EC2 instances 6. Launch Pod containers NEW NEW #devsumi
  48. © 2020, Amazon Web Services, Inc. or its Affiliates. etc…

    • CSIドライバー(EFS, EBS, FSx for Lustre ) •https://docs.aws.amazon.com/eks/latest/userguide/storage.htm • AWS App Mesh Controller For K8s •https://github.com/aws/aws-app-mesh-controller-for-k8s • IAM role for service accounts •https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/iam-roles-for-service-accounts.html • Cloud Development Kit for Kubernetes •https://cdk8s.io/ …etc #devsumi
  49. © 2020, Amazon Web Services, Inc. or its Affiliates. 最後に

    • EKS とその周りにある Services や OSS のツールを活⽤することで • アップストリームな Kubernetes の体験を損なうことなく • Kubernetes クラスターを運⽤していく上での 付加価値を生まない・競争力につながらない重労働を排除できる • EKS やその他コンテナに関するお悩みを持たれている⽅はぜひお近く の AWS のソリューションアーキテクトまで︕ #devsumi
  50. © 2020, Amazon Web Services, Inc. or its Affiliates. EKSを体験する

    Workshop を公開 https://eksworkshop.com/ #devsumi
  51. © 2020, Amazon Web Services, Inc. or its Affiliates. AWS

    Summit Online Japan 2020 #devsumi https://aws.amazon.com/jp/summits/2020/