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

JAWS-UG コンテナ支部 #27 EKSワークショップ ハンズオン

Hidekazu Karino
July 29, 2024
370

JAWS-UG コンテナ支部 #27 EKSワークショップ ハンズオン

Hidekazu Karino

July 29, 2024
Tweet

Transcript

  1. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. JAWS-UG コンテナ支部 #27 EKSワークショップ&ハンズオン Hidekazu Karino 1 Solutions Architect Amazon Web Services Japan, G.K.
  2. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 苅野 秀和 (かりの ひでかず) https://bsky.app/profile/hkford.bsky.social https://x.com/hkford3 • ウェブ系企業担当で Rust とコンテナが好きな ソリューションアーキテクト • 昔は飛行機の研究をしていた • 時々 Zenn に記事を投稿しています https://zenn.dev/hkdord • 6 月の AWS Summit で Rust でコンテナを自作するセッションを やりました https://www.youtube.com/ live/aiQTCq7yVOs
  3. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. • EKS クラスターの構築(構築に時間がかかるのでクラスター作成を先に行います) • ハンズオン実施前に EKS についてちょっと解説 - Kubernetes の基礎 - EKS の基礎 - EKS 最近のサービスアップデート • そしてハンズオンへ 目次 3
  4. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. エラーでクラスターを作成できなかった方へ 4 https://us-west- 2.console.aws.amazon.com/cloudformation/home?region=us-west- 2#/stacks/quickcreate?templateURL=https://ws-assets-prod-iad-r-nrt- 2cb4b4649d0e0f94.s3.ap-northeast-1.amazonaws.com/a9b0eefd-f429- 4859-9881-ce3a7f1a4e5f/vscode-server.yaml&stackName=VSCodeServer
  5. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. エラーでクラスターを作成できなかった方へ 5 そのまま下にスクロール チェックを入れて Create stack
  6. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. エラーでクラスターを作成できなかった方へ 6 VSCodeServer stack の outputs に移動 URL のリンクをクリックして Password を入力し Submit
  7. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. エラーでクラスターを作成できなかった方へ 7 VSCode Server にログインできます Cloud9 の代わりにこれを使えます(要 kubectl & eksctl インストール)
  8. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. エラーでクラスターを作成できなかった方へ 8 kubectl のインストール: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/ • curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl • sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl • kubectl version --client eksctl のインストール: https://eksctl.io/installation/#for-unix • curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp • sudo mv /tmp/eksctl /usr/local/bin • eksctl version
  9. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes の基礎 9
  10. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes の概要 10 • 複数のホスト間でコンテナ化されたアプリケーションを 管理するオープンソースシステム • Cloud Native Computing Foundation (CNCF) によって管理、 推進されている • デプロイ、メンテナンス、スケーリング といった基本的な機能を提供している • “Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.” https://kubernetes.io/docs/concepts/overview/what-is- kubernetes/ より
  11. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Client Kubernetes のアーキテクチャ 11 • コントロールプレーンがクラスタ全体の統括を行う • データプレーンでは Worker Node (コンテナが動くノード)で コントロールプレーンの指示通りにコンテナが起動する kubectl コマンド API Server コントロールプレーン データプレーン Worker Node Worker Node Worker Node
  12. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. kubectl コマンド • Kubernetes API を実行する為のコマンドラインインターフェイス • yaml ファイルで Worker Node 上で動作するリソースを定義し kubectl コマンドで反映される • Kubernetes Master の API Server と呼ばれるコンポーネントがコマンドを 受け付けると、各ワーカーノードに常駐するエージェント(kubelet)に 適切にコンテナを維持するよう指示 Client コントロールプレーン API Server kubectl コマンドを発行 データプレーンに 対し命令を実行 $ kubectl apply –f kubenetes/pods.yml Worker Node Worker Node kubelet kubelet
  13. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes (Upstream) サポートポリシー 13 • Kubernetes ではセマンティックバージョニング (x.y.z) を採⽤ Ø x はメジャーバージョン、y はマイナーバージョン、z はパッチバージョン • 最新の 3つのマイナーバージョンリリースをサポート Ø (2024/07/29 時点) 1.30, 1.29, 1.28 • サポートバージョンにはバグフィックスやセキュリティパッチが適⽤ • Kubernetes 1.19 以降は約 1 年間のサポートを提供 (1.18 以前は 9 ヶ⽉) • 詳細はこちら: https://kubernetes.io/releases/version-skew-policy/#supported-versions
  14. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes のリソース 14
  15. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes のリソース(の一部) 15 コンテナのワークロードに関連するリソース • Pod • ReplicaSet • Deployment ネットワーキングに関連するリソース • Service • Ingress
  16. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Pod • 作成、スケジュール、管理できる最小のデプロイ可能な単位 • 1 Pod に複数のコンテナを含む事が可能 例) 1つの Pod にアプリケーションコンテナとログドライバのコンテナを配置 • 同じ Pod 内のコンテナは Volume や Network を共有可能 • Pod 内のコンテナは localhost で通信可能 Nginx PHP-FPMコンテナ Pod localhostで通信 Volumeを共有
  17. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. ReplicaSet • Pod のレプリカを作成し、Pod を指定された数に維持するリソース • Pod が実行中の Worker Node の障害時には、指定された Pod の数を 維持するために影響を受けた Pod を別の Node に再作成する ReplicaSet Pod Pod count=3 Pod Pod Pod
  18. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Deployment • 複数の ReplicaSet を管理し、Pod のローリングアップデートや ロールバックを実現する為のリソース • ReplicaSet で Pod のローリングアップデートなどの機能が 利用できないため、Deployment の利用が一般的 ReplicaSet Pod Pod Pod count=3 version=2 ReplicaSet Pod Pod Pod count=3 version=1 Deployment 例) version 1 → 2にローリングアップデートする
  19. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Service • 複数の Pod をネットワーク越しに公開するリソース • Pod に対してトラフィックを流す事ができる(L4ロードバランシング) • Service に IPアドレスを割り当てる事もできる Pod Pod Pod Service L4ロードバランシング
  20. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Ingress 20 • Pod に対して HTTP/HTTPS トラフィックを流す事ができる (L7ロードバランシング) • AWS Load Balancer Controller : AWSがサポートするコントローラー • https://github.com/kubernetes-sigs/aws-load-balancer-controller • Ingress リソースとして Application Load Balancer (ALB) を公開できる • ホスト名またはパスベースルーティングをサポートしたL7の負荷分散が可能 Pod Pod Pod Ingress L7ロードバランシング Application Load Balancer AWS Load Balancer Controller によって統合
  21. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. EKS の基礎 21
  22. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes のアーキテクチャ(再掲) 22 API Server コントロールプレーン データプレーン Worker Node Worker Node Worker Node コントロールプレーンって大袈裟に書いてるけどこれ is 何?
  23. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Kubernetes コントロールプレーンアーキテクチャ 23 scheduler kube- apiserver etcd etcd etcd Add on Controller- Manager Cloud Controller
  24. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Amazon Elastic Kubernetes Service (Amazon EKS) Kubernetes アプリケーションを AWS クラウドで実行 24 • 運⽤難易度の⾼い Kubernetes クラスターを マネージドサービスとして提供 • Kubernetes エコシステムの OSS やツールが そのまま動かせる • VPC や CloudWatch Logs といった AWSサービスとの連携 • EKSチームによる Kubernetes コミュニティへの貢献
  25. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. EKS Architecture 25 https://aws.github.io/aws-eks-best-practices/reliability/docs/controlplane/ API Server は 2 AZ, etcd は 3AZ に跨った auto scaling group 上に展開
  26. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. EKS における Pod 実⾏環境の選択肢 26 セルフマネージド型 ノード マネージド型 ノードグループ Fargate ユーザーが⾃⾝で EC2 インスタンス / Auto Scaling グループを管理 https://docs.aws.amazon.com/eks/latest/userguide/eks-compute.html EKS がプロビジョニングやライフサイクルを管理 ※ 時間の関係上今⽇はこちらを中⼼にご説明 サーバーレスのコンピューティングエンジン
  27. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. マネージド型ノードグループ 27 • EKSがお客様のアカウントにASGを 作成して管理 • EKSにキャパシティの増減を指⽰ • EKSがASGを操作 • Kubernetesのプラクティスを考慮 • 必要なAWSタグの付与 • 終了時にノードからPodを退避 • Spotインスタンスの リバランス・終了通知の ハンドリング • ライフサイクルの管理にフォーカス • AMIや起動テンプレートの指定は 可能 • デフォルトでは EKS Optimized AMI を利⽤ Customer Account Auto Scaling Group(ASG)の管理
  28. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. オートスケーリング • EKS のオートスケール には以下の3つがある • 1. Horizontal Pod Autoscaler (HPA): Pod のオートスケール • 2. Cluster Autoscaler(CA) : Worker Node のオートスケール • 3. Vertical Pod Autoscaler(VPA):Pod のメモリ、CPU を適切なサイズに更新
  29. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Horizontal Pod Autoscaler (HPA) によるオート スケール • CPU 負荷などメトリクスに応じて Pod のオートスケール を行う • HPA を行うには Kubernetes Metrics Server のインストールが必要 • Fargate の場合は WorkerNode を意識する必要がない WorkerNode AWS Fargate Pod Pod Pod Pod ・・・ Pod ・・・ スケールアウト スケールイン スケールアウト スケールイン
  30. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Cluster Autoscaler (CA) によるオートスケール • ノードのリソース不足により Pod が起動できない (Pending) → スケールアウト • ノードのリソースに余力があり、別のノードに Pod を再配置可能 Pod Pod Pod Pod Pod Pod Pod Pod Pod Pod
  31. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Vertical Pod Autoscaler (VPA) • Pod のメモリと CPU の予約サイズを適切なサイズに調整する • 実績に基づいたリソースの調整を自動で行うため、 あらかじめ適切なリソース量を推測しにくい場合に向く • VPA を行うには Kubernetes Metrics Server のインストールが必要 Pod Pod 過去の実績を分析 予約サイズを自動で調整 予約リソース 使用したリソース
  32. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Amazon EKS サポートポリシー 32 https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html https://aws.amazon.com/about-aws/whats-new/2024/07/amazon-eks-controls-kubernetes-version-support-policy/ • 少なくとも 4 つの Kubernetes バージョンをサポート Ø 2024/07/29 時点では 1.27 から 1.30 の 4 バージョンがサポート対象 • EKS での最初のリリース後から 14 ヶ⽉間は Standard Support を提供 Ø アップストリームのサポートが切れたあとも AWS によるサポートが継続 • Standard Support が切れたあと Extended Support を選択可能 Ø 期間は 12 ヶ⽉間 Ø 料⾦は $0.60 per cluster per hour Ø Extended Support 期間が終了すると サポートされている最も古いバージョンに⾃動でアップグレード
  33. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. EKS のサービスアップデート 33
  34. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 34 https://aws.amazon.com/new/?whats-new-content-all.sort- by=item.additionalFields.postDateTime&whats-new-content-all.sort-order=desc&awsf.whats- new-categories=marketing-marchitecture%23containers&whats-new-content- all.q=eks&whats-new-content-all.q_operator= から 2023/11/28 の recap 以降のアップデート をいくつかご紹介
  35. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Amazon EKS upgrade insights 35 EKS クラスターの audit log から deprecated となる Kubernetes API を利用するリソースを特定 する機能 クラスターアップグレードを 助けてくれる(アップグレード前 の調査の助けとなる機能で、 実際のアップグレード操作は ユーザーが行う) 無料で使える機能で デフォルト有効 https://aws.amazon.com/about-aws/whats-new/2023/12/amazon-eks-upgrade-insights/ https://aws.amazon.com/blogs/containers/accelerate-the-testing-and-verification-of-amazon-eks-upgrades-with-upgrade-insights/
  36. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. IAM を用いたクラスターアクセス管理 36 これまで Kubernetes のユーザー/ロールと AWS IAM のマッピングを 考える際に aws-auth ConfigMap を使用していた。このアップデートに より EKS API にアクセス管理用の機能が追加され、この API を通じて IAM プリンシパルによる Kubernetes の権限管理が可能になった。 AWS IAM Authenticator for Kubernetes をコントロールプレーンに インストールすることで実現している この機能がサポートされるプラットフォームバージョンに制限あり: https://docs.aws.amazon.com/eks/latest/userguide/access- entries.html#access-entries-prerequisites https://aws.amazon.com/about-aws/whats-new/2023/12/amazon-eks-controls-iam-cluster-access-management/ https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/
  37. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. Next step 37
  38. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. • アプリケーションの公開 • Auto scaling • Clean up (EKS cluster の削除だけでなく VSCode Server CloudFormation stack の削 除も忘れずに) 38 EKS に触ってみましょう