/k8s-cloudwatch-adapter

An implementation of Kubernetes custom metrics API for Amazon CloudWatch; now maintained by ActZero.ai

Primary LanguageGoApache License 2.0Apache-2.0

GitHub release GitHub issues GitHub PRs

Kubernetes Custom Metrics Adapter for Kubernetes

An implementation of the Kubernetes Custom Metrics API and External Metrics API for AWS CloudWatch metrics.

This adapter allows you to scale your Kubernetes deployment using the Horizontal Pod Autoscaler (HPA) with metrics from AWS CloudWatch.

Prerequisites

This adapter requires your node groups to have the following permissions to access metric data from Amazon CloudWatch.

  • cloudwatch:GetMetricData

You can create an IAM policy using this template and attach it to your node group role.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "cloudwatch:GetMetricData"
            ],
            "Resource": "*"
        }
    ]
}

Deploy

Requires a Kubernetes cluster with Metric Server deployed.

Now, deploy the CRD and adapter using the Helm charts in the /charts directory:

$ helm repo add k8s-cloudwatch-adapter https://gitlab.com/api/v4/projects/45916012/packages/helm/stable
$ helm install k8s-cloudwatch-adapter-crd .k8s-cloudwatch-adapter/k8s-cloudwatch-adapter-crd \
>   --namespace custom-metrics \
>   --create-namespace
NAME: k8s-cloudwatch-adapter-crd
LAST DEPLOYED: Mon May 8 11:36:53 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm install k8s-cloudwatch-adapter k8s-cloudwatch-adapter/k8s-cloudwatch-adapter --namespace custom-metrics
NAME: k8s-cloudwatch-adapter
LAST DEPLOYED: Mon May 8 13:20:17 2023
NAMESPACE: custom-metrics
STATUS: deployed
REVISION: 1
TEST SUITE: None

Verifying the deployment

Next you can query the APIs to see if the adapter is deployed correctly by running:

$ kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1" | jq .
{
  "kind": "APIResourceList",
  "apiVersion": "v1",
  "groupVersion": "external.metrics.k8s.io/v1beta1",
  "resources": [
  ]
}

Deploying the Sample Application

There is a sample SQS application provided in this repository for you to test how the adapter works. Refer to this guide.

Further Reading

License

This library is licensed under the Apache 2.0 License. Contributions are welcomed!

Issues

Report any non-security issues in the Github Issue Tracker.

Please see CONTRIBUTING.md for information on reporting security issues.