Skip to content

Amazon EKS コスト最適化クイズ ​

このクイズでは、Amazon EKS cluster のコストを最適化するための戦略、ツール、ベストプラクティスに関する理解を確認します。

クイズ概要 ​

  • Compute resource の最適化
  • Storage コストの最適化
  • Networking コストの最適化
  • Cluster 管理コストの最適化
  • コストの監視と分析
  • コスト最適化ツールとベストプラクティス

多肢選択問題 ​

1. Amazon EKS で compute コストを最適化するために最も効果的な戦略は何ですか? ​

A. 常に最大の instance type を使用する B. すべての workload に on-demand instance のみを使用する C. Spot Instances、right-sizing、auto-scaling を組み合わせる D. すべての workload を単一の node group に集約する

回答を表示

回答: C. Spot Instances、right-sizing、auto-scaling を組み合わせる

解説: Amazon EKS で compute コストを最適化するために最も効果的な戦略は、Spot Instances、right-sizing、auto-scaling を組み合わせることです。この統合的なアプローチにより、performance 要件を満たしながら workload の特性に合った、コスト効率の高い computing resource を提供できます。

主要な Compute 最適化戦略:

  1. Spot Instance の活用:

    • on-demand と比較して最大 90% のコスト削減
    • fault-tolerant な workload に適している
    • interruption 処理メカニズムを実装する
  2. Right-sizing:

    • 実際の resource 使用量に基づいて instance を選択する
    • 過剰に provision された resource を排除する
    • resource requests と limits を最適化する
  3. Auto-scaling の実装:

    • Cluster Autoscaler または Karpenter による node-level scaling
    • Horizontal Pod Autoscaler による Pod-level scaling
    • 需要に基づく resource 調整

実装方法:

  1. Spot Instances を使用した Node Group の作成:

    bash
    # Create Spot Instance node group using eksctl
    eksctl create nodegroup \
      --cluster my-cluster \
      --name spot-ng \
      --node-type m5.large \
      --nodes-min 2 \
      --nodes-max 10 \
      --spot \
      --asg-access
  2. Karpenter の Deploy と設定:

    yaml
    # Karpenter NodePool
    apiVersion: karpenter.sh/v1
    kind: NodePool
    metadata:
      name: default
    spec:
      template:
        spec:
          requirements:
            - key: "karpenter.sh/capacity-type"
              operator: In
              values: ["spot"]
            - key: "kubernetes.io/arch"
              operator: In
              values: ["amd64"]
            - key: "kubernetes.io/os"
              operator: In
              values: ["linux"]
            - key: "node.kubernetes.io/instance-type"
              operator: In
              values: ["m5.large", "m5a.large", "m5d.large", "m5ad.large", "m4.large"]
          nodeClassRef:
            name: default
      limits:
        resources:
          cpu: 1000
          memory: 1000Gi
      disruption:
        consolidationPolicy: WhenEmpty
        consolidateAfter: 30s
    ---
    # Karpenter NodeClass
    apiVersion: karpenter.k8s.aws/v1
    kind: EC2NodeClass
    metadata:
      name: default
    spec:
      amiFamily: AL2
      role: KarpenterNodeRole
      subnetSelector:
        karpenter.sh/discovery: my-cluster
      securityGroupSelector:
        karpenter.sh/discovery: my-cluster
      tags:
        karpenter.sh/discovery: my-cluster
  3. Horizontal Pod Autoscaler の設定:

    yaml
    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      name: web-app
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: web-app
      minReplicas: 2
      maxReplicas: 10
      metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 70
      - type: Resource
        resource:
          name: memory
          target:
            type: Utilization
            averageUtilization: 80
  4. Vertical Pod Autoscaler の設定:

    yaml
    apiVersion: autoscaling.k8s.io/v1
    kind: VerticalPodAutoscaler
    metadata:
      name: web-app-vpa
    spec:
      targetRef:
        apiVersion: "apps/v1"
        kind: Deployment
        name: web-app
      updatePolicy:
        updateMode: "Auto"
      resourcePolicy:
        containerPolicies:
        - containerName: '*'
          minAllowed:
            cpu: 50m
            memory: 100Mi
          maxAllowed:
            cpu: 1
            memory: 1Gi
          controlledResources: ["cpu", "memory"]

Workload Type 別の最適化戦略:

  1. Stateless Applications:

    • Spot Instances を優先する
    • horizontal scaling を実装する
    • 複数の Availability Zones にまたがって Deploy する
  2. Stateful Applications:

    • on-demand と Spot Instances を組み合わせる
    • 適切な instance type を選択する
    • storage performance とコストのバランスを取る
  3. Batch Jobs:

    • Spot Instance の使用を最大化する
    • job retry メカニズムを実装する
    • コスト効率の高い時間帯に実行する

ベストプラクティス:

  1. Resource Requests と Limits の最適化:

    yaml
    # Resource requests and limits example
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web-app
    spec:
      replicas: 3
      template:
        spec:
          containers:
          - name: web-app
            image: web-app:1.0
            resources:
              requests:
                cpu: 100m
                memory: 256Mi
              limits:
                cpu: 500m
                memory: 512Mi
  2. Node Affinity と Pod 分散の最適化:

    yaml
    # Node affinity and pod distribution example
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web-app
    spec:
      replicas: 3
      template:
        spec:
          affinity:
            nodeAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 1
                preference:
                  matchExpressions:
                  - key: node.kubernetes.io/instance-type
                    operator: In
                    values:
                    - m5.large
                    - m5a.large
            podAntiAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 100
                podAffinityTerm:
                  labelSelector:
                    matchExpressions:
                    - key: app
                      operator: In
                      values:
                      - web-app
                  topologyKey: "kubernetes.io/hostname"
  3. Spot Instance Interruptions への対応:

    yaml
    # Spot Instance interruption handling example
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web-app
    spec:
      replicas: 3
      template:
        spec:
          terminationGracePeriodSeconds: 60
          containers:
          - name: web-app
            image: web-app:1.0
            lifecycle:
              preStop:
                exec:
                  command: ["/bin/sh", "-c", "sleep 10; /app/cleanup.sh"]

その他の選択肢の問題点:

  • A. 常に最大の instance type を使用する: これは不要なコストを伴う過剰 provision につながり、workload 要件に合わない可能性があります。
  • B. すべての workload に on-demand instance のみを使用する: on-demand instance は Spot Instances よりもコストが高く、多くの workload は Spot Instances 上で効果的に実行できます。
  • D. すべての workload を単一の node group に集約する: これにより多様な workload 要件を満たすことが難しくなり、resource isolation が不足し、コスト配分と最適化が困難になります。

2. Amazon EKS で storage コストを最適化するために最も効果的なアプローチは何ですか? ​

A. すべての workload に最も安価な storage type を使用する B. すべてのデータを S3 に移行する C. workload 要件に合った storage type を選択し、lifecycle management を実装する D. すべての volume size を最小化する

回答を表示

回答: C. workload 要件に合った storage type を選択し、lifecycle management を実装する

解説: Amazon EKS で storage コストを最適化するために最も効果的なアプローチは、workload 要件に合った storage type を選択し、lifecycle management を実装することです。このアプローチは、performance 要件を満たしながらコストを最小化し、データの価値と access pattern に基づいて適切な storage tier を活用します。

主要な Storage 最適化戦略:

  1. Workload に適した Storage Type の選択:

    • 高い performance が必要な場合: io2、gp3 (EBS)
    • shared access が必要な場合: EFS
    • 大規模 data processing: FSx for Lustre
    • archive data: S3、S3 Glacier
  2. Storage Lifecycle Management:

    • 頻繁に access されるデータ: High-performance storage
    • ときどき access されるデータ: Standard storage
    • まれに access されるデータ: Low-cost archive storage
  3. 効率的な Volume Management:

    • 適切な volume size を設定する
    • 未使用の volume を特定して削除する
    • snapshot lifecycle を管理する

実装方法:

  1. EBS Volume Optimization:

    yaml
    # gp3 StorageClass configuration
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: ebs-gp3
    provisioner: ebs.csi.aws.com
    parameters:
      type: gp3
      iops: "3000"
      throughput: "125"
    allowVolumeExpansion: true
  2. EFS Lifecycle Management:

    bash
    # Set lifecycle policy when creating EFS file system
    aws efs create-file-system \
      --creation-token eks-efs \
      --performance-mode generalPurpose \
      --throughput-mode bursting \
      --lifecycle-policies '[{"TransitionToIA":"AFTER_30_DAYS"}]'
  3. S3 Lifecycle Policy:

    json
    {
      "Rules": [
        {
          "ID": "Move to IA after 30 days, Glacier after 90 days",
          "Status": "Enabled",
          "Prefix": "eks-backups/",
          "Transitions": [
            {
              "Days": 30,
              "StorageClass": "STANDARD_IA"
            },
            {
              "Days": 90,
              "StorageClass": "GLACIER"
            }
          ],
          "Expiration": {
            "Days": 365
          }
        }
      ]
    }
  4. EBS Snapshot Lifecycle Management:

    yaml
    # VolumeSnapshotClass configuration
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshotClass
    metadata:
      name: ebs-snapshot
      annotations:
        snapshot.storage.kubernetes.io/is-default-class: "true"
    driver: ebs.csi.aws.com
    deletionPolicy: Delete

その他の選択肢の問題点:

  • A. すべての workload に最も安価な storage type を使用する: 最も安価な storage は performance 要件を満たさない可能性があり、application performance の低下やビジネス影響を引き起こす可能性があります。
  • B. すべてのデータを S3 に移行する: S3 は一部の data type には適していますが、latency-sensitive な workload や block storage を必要とする application には適していません。
  • D. すべての volume size を最小化する: volume size を過度に最小化すると容量不足の問題が発生する可能性があり、一部の volume type(例: gp2)では performance が size によって決まります。

3. Amazon EKS で networking コストを最適化するために最も効果的な戦略は何ですか? ​

A. すべての traffic に最も高価な network bandwidth を使用する B. すべての service を単一の Availability Zone に配置する C. traffic pattern を最適化し、data transfer コストを最小化し、VPC endpoints を活用する D. すべての network traffic をブロックする

回答を表示

回答: C. traffic pattern を最適化し、data transfer コストを最小化し、VPC endpoints を活用する

解説: Amazon EKS で networking コストを最適化するために最も効果的な戦略は、traffic pattern を最適化し、data transfer コストを最小化し、VPC endpoints を活用することです。このアプローチは、AWS の network cost model を考慮して network traffic の効率を高め、不要なコストを削減します。

主要な Networking コスト最適化戦略:

  1. Traffic Pattern Optimization:

    • Availability Zone 間の traffic を最小化する
    • region 間の traffic を最小化する
    • locality-aware routing を実装する
  2. Data Transfer コストの最小化:

    • compression と効率的な data format を使用する
    • caching strategy を実装する
    • 不要な data transfer を排除する
  3. VPC Endpoint の活用:

    • AWS services への private connection
    • internet gateway を迂回する
    • data transfer コストを削減する

実装方法:

  1. Availability Zone を考慮した Pod 配置:

    yaml
    # Deployment with topology spread constraints
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web-app
    spec:
      replicas: 6
      template:
        spec:
          topologySpreadConstraints:
          - maxSkew: 1
            topologyKey: topology.kubernetes.io/zone
            whenUnsatisfiable: DoNotSchedule
            labelSelector:
              matchLabels:
                app: web-app
  2. Service Topology Routing:

    yaml
    # Topology-aware service configuration
    apiVersion: v1
    kind: Service
    metadata:
      name: web-app
    spec:
      selector:
        app: web-app
      ports:
      - port: 80
        targetPort: 8080
      topologyKeys:
      - "kubernetes.io/hostname"
      - "topology.kubernetes.io/zone"
      - "*"
  3. VPC Endpoint Configuration:

    bash
    # Create S3 VPC endpoint
    aws ec2 create-vpc-endpoint \
      --vpc-id vpc-12345678 \
      --service-name com.amazonaws.us-west-2.s3 \
      --route-table-ids rtb-12345678
    
    # Create DynamoDB VPC endpoint
    aws ec2 create-vpc-endpoint \
      --vpc-id vpc-12345678 \
      --service-name com.amazonaws.us-west-2.dynamodb \
      --route-table-ids rtb-12345678
    
    # Create ECR API VPC endpoint
    aws ec2 create-vpc-endpoint \
      --vpc-id vpc-12345678 \
      --service-name com.amazonaws.us-west-2.ecr.api \
      --vpc-endpoint-type Interface \
      --subnet-ids subnet-12345678 subnet-87654321 \
      --security-group-ids sg-12345678
  4. Istio による Locality Routing:

    yaml
    # Istio locality routing configuration
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: web-app
    spec:
      host: web-app
      trafficPolicy:
        loadBalancer:
          localityLbSetting:
            enabled: true
            failover:
            - from: us-west-2a
              to: us-west-2b
            - from: us-west-2b
              to: us-west-2c
            - from: us-west-2c
              to: us-west-2a

その他の選択肢の問題点:

  • A. すべての traffic に最も高価な network bandwidth を使用する: これは不要なコストを発生させ、すべての workload が高い bandwidth を必要とするわけではありません。
  • B. すべての service を単一の Availability Zone に配置する: これは availability と fault tolerance を大幅に低下させ、AWS の高可用性設計原則に反します。
  • D. すべての network traffic をブロックする: これは実用的ではなく、application の機能を大きく制限します。

4. Amazon EKS cluster 管理コストを最適化するために最も効果的なアプローチは何ですか? ​

A. 可能な限り多くの cluster を作成する B. すべての workload を単一の cluster に集約する C. workload 要件に基づいて cluster 数を最適化し、management overhead を最小化する D. cluster を手動で管理する

回答を表示

回答: C. workload 要件に基づいて cluster 数を最適化し、management overhead を最小化する

解説: Amazon EKS cluster 管理コストを最適化するために最も効果的なアプローチは、workload 要件に基づいて cluster 数を最適化し、management overhead を最小化することです。このアプローチは、workload isolation と security 要件を満たしながら、cluster 管理コストと operational complexity のバランスを取ります。

主要な Cluster 管理コスト最適化戦略:

  1. 適切な Cluster 数の維持:

    • business 要件に基づく cluster 分離
    • environment に基づく cluster 分離(development、staging、production)
    • security と compliance 要件を考慮する
  2. Management Overhead の最小化:

    • 自動化された cluster 管理ツールを活用する
    • Infrastructure as Code (IaC) を実装する
    • monitoring と logging の一元化
  3. Cluster Resources の最適化:

    • 適切な control plane 設定
    • 効率的な node group 管理
    • shared services を活用する

実装方法:

  1. 最適化された EKS Cluster Configuration:

    bash
    # Create optimized cluster using eksctl
    eksctl create cluster \
      --name optimized-cluster \
      --region us-west-2 \
      --version 1.28 \
      --nodegroup-name standard-workers \
      --node-type m5.large \
      --nodes-min 2 \
      --nodes-max 10 \
      --managed \
      --asg-access \
      --external-dns-access \
      --full-ecr-access \
      --appmesh-access \
      --alb-ingress-access
  2. Terraform による Cluster Management Automation:

    hcl
    module "eks" {
      source  = "terraform-aws-modules/eks/aws"
      version = "~> 19.0"
    
      cluster_name    = "optimized-cluster"
      cluster_version = "1.28"
    
      cluster_endpoint_public_access  = true
      cluster_endpoint_private_access = true
    
      cluster_addons = {
        coredns = {
          most_recent = true
        }
        kube-proxy = {
          most_recent = true
        }
        vpc-cni = {
          most_recent = true
        }
      }
    
      vpc_id     = module.vpc.vpc_id
      subnet_ids = module.vpc.private_subnets
    
      eks_managed_node_groups = {
        general = {
          min_size     = 1
          max_size     = 10
          desired_size = 2
    
          instance_types = ["m5.large"]
          capacity_type  = "ON_DEMAND"
        }
    
        spot = {
          min_size     = 1
          max_size     = 10
          desired_size = 2
    
          instance_types = ["m5.large", "m5a.large", "m5d.large", "m4.large"]
          capacity_type  = "SPOT"
        }
      }
    
      tags = {
        Environment = "production"
        Terraform   = "true"
      }
    }
  3. GitOps による Cluster Configuration Management:

    yaml
    # ArgoCD Application example
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: cluster-config
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: https://github.com/myorg/cluster-config.git
        targetRevision: HEAD
        path: configs
      destination:
        server: https://kubernetes.default.svc
        namespace: default
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true
  4. Multi-tenant Cluster Configuration:

    yaml
    # Namespace resource quota
    apiVersion: v1
    kind: ResourceQuota
    metadata:
      name: team-a-quota
      namespace: team-a
    spec:
      hard:
        requests.cpu: "10"
        requests.memory: 20Gi
        limits.cpu: "20"
        limits.memory: 40Gi
        pods: "50"
        services: "20"
        persistentvolumeclaims: "30"

その他の選択肢の問題点:

  • A. 可能な限り多くの cluster を作成する: これは各 cluster の control plane コストと management overhead を増加させ、resource utilization を低下させます。
  • B. すべての workload を単一の cluster に集約する: 一部の環境では適している可能性がありますが、security 要件、workload isolation、failure blast radius を考慮していません。
  • D. cluster を手動で管理する: 手動管理は error potential を高め、一貫性を低下させ、operational overhead を増加させます。

5. Amazon EKS における cost monitoring と allocation に最も効果的なアプローチは何ですか? ​

A. AWS bills のみを確認する B. tagging strategy、cost allocation tools、continuous monitoring を実装する C. すべての resource に同じコストを割り当てる D. cost monitoring なしで resource を使用する

回答を表示

回答: B. tagging strategy、cost allocation tools、continuous monitoring を実装する

解説: Amazon EKS における cost monitoring と allocation に最も効果的なアプローチは、tagging strategy、cost allocation tools、continuous monitoring を実装することです。このアプローチは、コストを正確に追跡し、team や project ごとに配分し、コスト最適化の機会を特定するのに役立ちます。

主要な Cost Monitoring と Allocation 戦略:

  1. 包括的な Tagging Strategy:

    • business unit、team、project、environment ごとの tag
    • 一貫した tagging rule を適用する
    • 自動 tagging を実装する
  2. Cost Allocation Tool の活用:

    • AWS Cost Explorer と AWS Budgets
    • Kubecost や CloudHealth などの specialized tools
    • custom dashboard と report
  3. Continuous Monitoring と Optimization:

    • 定期的なコスト review と analysis
    • anomaly detection と alert
    • optimization recommendation を実装する

実装方法:

  1. Tagging Strategy の実装:

    yaml
    # Namespace tagging
    apiVersion: v1
    kind: Namespace
    metadata:
      name: team-a
      labels:
        team: team-a
        cost-center: cc-123
        environment: production
        project: project-x
    
    # Deployment tagging
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web-app
      namespace: team-a
      labels:
        app: web-app
        team: team-a
        cost-center: cc-123
        environment: production
        project: project-x
  2. AWS Tag Policy Configuration:

    json
    {
      "tags": {
        "team": {
          "tag_key": {
            "@@assign": "team"
          },
          "tag_value": {
            "@@assign": [
              "team-a",
              "team-b",
              "platform"
            ]
          },
          "enforced_for": {
            "@@assign": [
              "ec2:instance",
              "ec2:volume",
              "eks:cluster"
            ]
          }
        },
        "cost-center": {
          "tag_key": {
            "@@assign": "cost-center"
          },
          "enforced_for": {
            "@@assign": [
              "ec2:instance",
              "ec2:volume",
              "eks:cluster"
            ]
          }
        },
        "environment": {
          "tag_key": {
            "@@assign": "environment"
          },
          "tag_value": {
            "@@assign": [
              "production",
              "staging",
              "development"
            ]
          },
          "enforced_for": {
            "@@assign": [
              "ec2:instance",
              "ec2:volume",
              "eks:cluster"
            ]
          }
        }
      }
    }
  3. Kubecost Installation and Configuration:

    bash
    # Install Kubecost using Helm
    helm repo add kubecost https://kubecost.github.io/cost-analyzer/
    helm install kubecost kubecost/cost-analyzer \
      --namespace kubecost \
      --create-namespace \
      --set kubecostToken="<YOUR_KUBECOST_TOKEN>" \
      --set prometheus.server.persistentVolume.size=100Gi \
      --set prometheus.nodeExporter.enabled=true \
      --set serviceMonitor.enabled=true
  4. AWS Cost Explorer Report Setup:

    bash
    # Create cost and usage report
    aws cur put-report-definition \
      --report-definition '{
        "ReportName": "eks-cost-report",
        "TimeUnit": "HOURLY",
        "Format": "Parquet",
        "Compression": "Parquet",
        "AdditionalSchemaElements": ["RESOURCES"],
        "S3Bucket": "my-cost-reports",
        "S3Prefix": "eks-costs",
        "S3Region": "us-east-1",
        "AdditionalArtifacts": ["ATHENA"],
        "RefreshClosedReports": true,
        "ReportVersioning": "OVERWRITE_REPORT"
      }'

その他の選択肢の問題点:

  • A. AWS bills のみを確認する: AWS bills は high-level の cost information しか提供しないため、詳細な cost allocation や optimization opportunity を特定することが困難です。
  • C. すべての resource に同じコストを割り当てる: これは実際の resource usage と cost generation を正確に反映せず、team や project ごとの cost responsibility を明確にできません。
  • D. cost monitoring なしで resource を使用する: cost monitoring がないと、コスト増加を早期に検出したり optimization opportunity を特定したりできず、budget management が困難になります。

6. Amazon EKS で cost optimization を行うために最も効果的なツールの組み合わせは何ですか? ​

A. 手動の resource management のみを使用する B. AWS Cost Explorer のみを使用する C. Kubecost、Karpenter、AWS Cost Explorer、Kubernetes auto-scaling tools を統合する D. third-party cost management tools のみを使用する

回答を表示

回答: C. Kubecost、Karpenter、AWS Cost Explorer、Kubernetes auto-scaling tools を統合する

解説: Amazon EKS で cost optimization を行うために最も効果的なツールの組み合わせは、Kubecost、Karpenter、AWS Cost Explorer、Kubernetes auto-scaling tools を統合することです。この統合的なアプローチは、cluster、workload、infrastructure の各レベルでコストを最適化し、可視性を提供し、自動化された最適化を可能にします。

主要な Cost Optimization Tools と Features:

  1. Kubecost:

    • Kubernetes resource cost の可視性
    • namespace、deployment、service ごとの cost allocation
    • cost optimization recommendations
    • cost forecasting と budget management
  2. Karpenter:

    • intelligent node provisioning と management
    • workload 要件に合った optimal instance selection
    • 高速 scaling と効率的な resource utilization
    • Spot Instance utilization optimization
  3. AWS Cost Explorer:

    • AWS services 全体の cost analysis
    • tag-based cost allocation
    • cost trend と forecasting
    • Reserved Instance と Savings Plans の recommendations
  4. Kubernetes Auto-scaling Tools:

    • Horizontal Pod Autoscaler (HPA)
    • Vertical Pod Autoscaler (VPA)
    • Cluster Autoscaler
    • Cluster Proportional Autoscaler

実装方法:

  1. Kubecost Installation and Configuration:

    bash
    # Install Kubecost using Helm
    helm repo add kubecost https://kubecost.github.io/cost-analyzer/
    helm install kubecost kubecost/cost-analyzer \
      --namespace kubecost \
      --create-namespace \
      --set kubecostToken="<YOUR_KUBECOST_TOKEN>" \
      --set prometheus.server.persistentVolume.size=100Gi \
      --set prometheus.nodeExporter.enabled=true \
      --set serviceMonitor.enabled=true
  2. Karpenter Installation and Configuration:

    bash
    # Install Karpenter
    helm repo add karpenter https://charts.karpenter.sh
    helm upgrade --install karpenter karpenter/karpenter \
      --namespace karpenter \
      --create-namespace \
      --set serviceAccount.create=true \
      --set serviceAccount.name=karpenter \
      --set serviceAccount.annotations."eks\.amazonaws\.com/role-arn"="arn:aws:iam::123456789012:role/KarpenterControllerRole" \
      --set controller.clusterName=my-cluster \
      --set controller.clusterEndpoint=$(aws eks describe-cluster --name my-cluster --query "cluster.endpoint" --output text)
    yaml
    # Karpenter NodePool and NodeClass configuration
    apiVersion: karpenter.sh/v1
    kind: NodePool
    metadata:
      name: default
    spec:
      template:
        spec:
          requirements:
            - key: "karpenter.sh/capacity-type"
              operator: In
              values: ["spot", "on-demand"]
            - key: "kubernetes.io/arch"
              operator: In
              values: ["amd64"]
            - key: "kubernetes.io/os"
              operator: In
              values: ["linux"]
            - key: "node.kubernetes.io/instance-type"
              operator: In
              values: ["m5.large", "m5a.large", "m5d.large", "m4.large", "t3.large", "t3a.large"]
          nodeClassRef:
            name: default
      limits:
        resources:
          cpu: 1000
          memory: 1000Gi
      disruption:
        consolidationPolicy: WhenEmpty
        consolidateAfter: 30s
    ---
    apiVersion: karpenter.k8s.aws/v1
    kind: EC2NodeClass
    metadata:
      name: default
    spec:
      amiFamily: AL2
      role: KarpenterNodeRole
      subnetSelector:
        karpenter.sh/discovery: my-cluster
      securityGroupSelector:
        karpenter.sh/discovery: my-cluster
      tags:
        karpenter.sh/discovery: my-cluster
  3. Horizontal Pod Autoscaler の設定:

    yaml
    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      name: web-app
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: web-app
      minReplicas: 2
      maxReplicas: 10
      metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 70
      - type: Resource
        resource:
          name: memory
          target:
            type: Utilization
            averageUtilization: 80
  4. Vertical Pod Autoscaler の設定:

    yaml
    apiVersion: autoscaling.k8s.io/v1
    kind: VerticalPodAutoscaler
    metadata:
      name: web-app-vpa
    spec:
      targetRef:
        apiVersion: "apps/v1"
        kind: Deployment
        name: web-app
      updatePolicy:
        updateMode: "Auto"
      resourcePolicy:
        containerPolicies:
        - containerName: '*'
          minAllowed:
            cpu: 50m
            memory: 100Mi
          maxAllowed:
            cpu: 1
            memory: 1Gi
          controlledResources: ["cpu", "memory"]

Tool Integration と Workflow:

  1. Cost Visibility と Analysis:

    • Kubecost: in-cluster resource cost analysis
    • AWS Cost Explorer: AWS services 全体の cost analysis
    • integrated dashboards: 全体的な cost overview と trends
  2. Automated Resource Optimization:

    • Karpenter: optimal node provisioning と management
    • HPA/VPA: workload-level resource optimization
    • Spot Instance utilization: コスト効率の高い computing resources
  3. Cost Allocation と Responsibility:

    • tag-based cost allocation
    • namespace と label ごとの cost analysis
    • team と project ごとの cost reporting
  4. Continuous Optimization と Improvement:

    • cost optimization recommendations を実装する
    • 定期的な cost review と analysis
    • cost reduction goal を設定し追跡する

その他の選択肢の問題点:

  • A. 手動の resource management のみを使用する: 手動管理は scalability に欠け、error potential が高く、optimization opportunity を見逃す可能性があります。
  • B. AWS Cost Explorer のみを使用する: AWS Cost Explorer は AWS service-level の cost analysis には有用ですが、詳細な Kubernetes resource-level の cost analysis や automated optimization features は提供しません。
  • D. third-party cost management tools のみを使用する: third-party tools は有用な場合がありますが、AWS native services や Kubernetes auto-scaling tools との統合が限定的なことがあり、追加コストが発生する可能性があります。

ドキュメントに質問する

Enter で送信、Shift+Enter で改行します。