Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conformitron with cost optimizations #176

Merged
merged 102 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
06daad2
initial commit
Howlla Feb 8, 2024
1995c6b
remove argocd repo code
Howlla Feb 8, 2024
01b15c6
argoCD Infra and Flux GitOps
Howlla Feb 9, 2024
134e42e
update application and branch
Howlla Feb 9, 2024
42faa59
update argo addon config owner
Howlla Feb 9, 2024
c20bfb4
update owner of github argo addon
Howlla Feb 9, 2024
087b1cc
creating addons inside for loop
Howlla Feb 10, 2024
24ae202
moving addons creation inside for loop
Howlla Feb 10, 2024
4fb0050
update branch of argo addon
Howlla Feb 12, 2024
8f09934
update branch for argo addon
Howlla Feb 12, 2024
bc4ee93
update flux
Howlla Feb 12, 2024
17d51f4
8 clusters enabled
Howlla Feb 13, 2024
dd6ad3b
sepearte addons
Howlla Feb 14, 2024
8701849
refactor to seperate builder with multiple AMP providers
Howlla Feb 16, 2024
afac52b
external secrets already part of oss pattern
Howlla Feb 16, 2024
cfa3975
Bottlerocket clusters added, eks 1.24 and 1.25 support removed
Howlla Feb 16, 2024
3010f26
coredns version explicitly passed to stop fail for eks1.26
Howlla Feb 16, 2024
c177c71
reorder addon props to pass them correctly
Howlla Feb 16, 2024
b90be5f
documentation added
Howlla Feb 19, 2024
3218659
Merge branch 'conformitronInitiative' into myBranch
Howlla Feb 19, 2024
366a52c
Merge pull request #1 from Howlla/myBranch
Howlla Feb 19, 2024
7ae6b86
mkdocs fix
Howlla Feb 19, 2024
2a870d0
mkdocs update
Howlla Feb 19, 2024
2128938
mkdocs fix formatting for service quotas
Howlla Feb 19, 2024
a57583b
test
Howlla Feb 21, 2024
dfd636d
est
Howlla Feb 21, 2024
742475b
hardcode amg
Howlla Feb 21, 2024
9ac620c
upbound
Howlla Feb 21, 2024
879de8e
downgrade eks for grafana cluster
Howlla Feb 21, 2024
5e83a79
hardcode amp amg
Howlla Feb 21, 2024
70c5268
update https
Howlla Feb 21, 2024
3c5bfe7
ssm agent addon
Howlla Feb 21, 2024
a579793
ssm agent
Howlla Feb 21, 2024
8ddef51
Add files via upload
Howlla Feb 22, 2024
11be402
secrets update
Howlla Feb 23, 2024
da7d68f
docs update
Howlla Feb 23, 2024
1432aac
amp resource provider
Howlla Feb 23, 2024
ae22574
modify kustomizations
Howlla Feb 23, 2024
1dec0b6
Merge branch 'aws-samples:main' into conformitronInitiative
Howlla Feb 23, 2024
2f6f075
Merge branch 'conformitronInitiative' into test123
Howlla Feb 24, 2024
81668d4
amgupdate
Howlla Mar 1, 2024
a51c2ce
update branch
Howlla Mar 1, 2024
57a00c7
ebs-csi-driver added
Howlla Mar 1, 2024
beb929e
ebs-csi-driver added
Howlla Mar 1, 2024
56ff2ab
Add cluster autoscaler
Howlla Mar 1, 2024
a8e0dc5
minify bottlerocket clusterName
Howlla Mar 1, 2024
bf93ebc
reduce metrics collected
Howlla Mar 5, 2024
91e5305
add autoscaler
Howlla Mar 5, 2024
b92d574
Add csi driver
Howlla Mar 5, 2024
6f87bec
add resources
Howlla Mar 5, 2024
0c6fa66
testing
Howlla Mar 6, 2024
fe256b6
modify scrape rules
Howlla Mar 6, 2024
b239335
Seperate BR logs
Howlla Mar 8, 2024
2103cfe
remove amp for grafana cluster
Howlla Mar 8, 2024
522ecc1
kustomizations added and nodexp monitoring removed
Howlla Mar 10, 2024
0f48f2e
further cost optimize
Howlla Mar 11, 2024
418cfac
cost optimize 2xlarge
Howlla Mar 13, 2024
7c27eba
modify nodegroup names
Howlla Mar 17, 2024
e9adf91
cost optimization
Howlla Mar 18, 2024
071f54d
change branch for flux
Howlla Mar 19, 2024
8f692c0
change branch to howlla
Howlla Mar 20, 2024
bf33a2c
reset branch
Howlla Mar 20, 2024
f885b53
remove ssm agent
Howlla Mar 22, 2024
028dd9f
force single node only
Howlla Mar 23, 2024
45020a6
update to max 2
Howlla Mar 23, 2024
87aff5e
remove testers
Howlla Mar 25, 2024
de56ec7
update disksize
Howlla Apr 1, 2024
a4b5a69
rename mng node group
Howlla Apr 1, 2024
a37a4e7
reduce number of clusters
Howlla Apr 5, 2024
ea43c18
single AMP
Howlla Apr 5, 2024
7e79337
single AMP
Howlla Apr 5, 2024
7f201d9
single AMP
Howlla Apr 6, 2024
582c0fb
single amp try2
Howlla Apr 6, 2024
e3c2c42
single amp try3
Howlla Apr 6, 2024
e924c7b
using export variable for ampProvider
Howlla Apr 6, 2024
34fa1b0
attempt 5
Howlla Apr 7, 2024
a33e8b6
GetNamedResource to get the ampProvider
Howlla May 3, 2024
94b4c1c
GetNamedResource to get the ampProvider
Howlla May 3, 2024
57e2f10
HardCode the endpoint
Howlla May 3, 2024
b6d0cf5
HardCode the endpoint
Howlla May 3, 2024
8d9203d
remove repeated scraping rules from amp
Howlla May 10, 2024
4017b60
change monitoring code
Howlla May 20, 2024
eef054f
change monitoring code
Howlla May 20, 2024
347a7e8
useopensourcepattern addons"
Howlla May 20, 2024
ce186fe
remove repeated addons"
Howlla May 20, 2024
3db6e36
reorder resource provider
Howlla May 20, 2024
e5db581
hardcode workspace
Howlla May 20, 2024
1545f58
all clusters go
Howlla May 24, 2024
94a1134
final commit
Howlla May 31, 2024
b51b7bd
conformitronPipeline
Howlla Jun 8, 2024
8491fab
lint fix
Howlla Jun 8, 2024
dd75a41
Merge branch 'aws-samples:main' into conformitronPipeline
Howlla Jun 19, 2024
34a5a65
remove coredns addon version
Howlla Jun 25, 2024
b86489f
fix kubeflow link to stop .md link error
Howlla Jul 8, 2024
bdf7cd3
improve documentation and remove cdk variables
Howlla Jul 8, 2024
f2bfbb4
refactoring code as per feedback received on PR
Howlla Jul 9, 2024
a7a96ba
integrate Mikhail's feedback
Howlla Jul 10, 2024
b5ced35
integrate feedback
Howlla Jul 10, 2024
930a544
add dashboards
Howlla Jul 10, 2024
2152ebf
minor typo in instructions and functional testing
Howlla Jul 10, 2024
930771e
remove extra commited files
Howlla Jul 10, 2024
7ebc049
fix org name for testing
Howlla Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ site
.DS_STORE

# Python virtual env directory
*.venv*
*.venv*

*otel-collector-config-new.yml
Binary file added aws-quickstart-eks-blueprints-1.13.1.tgz
Binary file not shown.
13 changes: 13 additions & 0 deletions bin/multi-cluster-conformitron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { configureApp, errorHandler } from '../lib/common/construct-utils';
import { PipelineMultiCluster } from '../lib/multi-cluster-construct/pipeline';


const app = configureApp();

//-------------------------------------------
// Multiple clusters, multiple regions.
//-------------------------------------------

new PipelineMultiCluster().buildAsync(app).catch((error) => {
errorHandler(app, "Multi cluster pattern is not setup. It may be due to missing secrets: ", error);
});
31 changes: 30 additions & 1 deletion cdk.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
{
"app": "npx ts-node dist/lib/common/default-main.js"
"app": "npx ts-node dist/lib/common/default-main.js",
"context": {
"conformitron.amp.endpoint": "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-77b8828d-0985-49e0-9268-2e0e8f3ba758/",
"conformitron.amp.arn":"arn:aws:aps:us-east-1:975050283200:workspace/ws-77b8828d-0985-49e0-9268-2e0e8f3ba758",
"conformitron.amg.endpoint": "https://g-75bcfc519c.grafana-workspace.us-east-1.amazonaws.com",
"conformitron.version": ["1.28","1.29","1.30"],
"fluxRepository": {
"name": "grafana-dashboards",
"namespace": "grafana-operator",
"repository": {
"repoUrl": "https://github.com/aws-observability/aws-observability-accelerator",
"name": "grafana-dashboards",
"targetRevision": "main",
"path": "./artifacts/grafana-operator-manifests/eks/infrastructure"
},
"values": {
"GRAFANA_CLUSTER_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/cluster.json",
"GRAFANA_KUBELET_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/kubelet.json",
"GRAFANA_NSWRKLDS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/namespace-workloads.json",
"GRAFANA_NODEEXP_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodeexporter-nodes.json",
"GRAFANA_NODES_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodes.json",
"GRAFANA_WORKLOADS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/workloads.json"
},
"kustomizations": [
{
"kustomizationPath": "./artifacts/grafana-operator-manifests/eks/infrastructure"
}
]
}
}
}
Binary file added docs/patterns/images/ConformitronDashboard1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/patterns/images/ConformitronDashboard2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/patterns/images/ConformitronDashboard3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/patterns/images/CostOptimizationSSM1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/patterns/images/CostOptimizationSSM2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/patterns/images/conformitron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/patterns/kubeflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ kubectl port-forward svc/ml-pipeline-ui 9000:80 -n =kubeflow-pipelines

```
and open this browser: http://localhost:9000/#/pipelines
more pipeline examples can be found at https://www.kubeflow.org/docs/components/pipelines/tutorials/
more pipeline examples can be found at https://www.kubeflow.org/docs/components/pipelines/legacy-v1/tutorials/


## Cleanup
Expand Down
243 changes: 243 additions & 0 deletions docs/patterns/multi-cluster-conformitron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
# Multi-cluster pattern with observability, cost optimizations and metrics aggregation

elamaran11 marked this conversation as resolved.
Show resolved Hide resolved
## Objective

This pattern was started to solve a problem faced at AWS. We often get third-party software for validation and need a consistent automated approach to run Kubernetes evaluator testing, deployment of containerized products, and validation in Kubernetes environments on a variety of Amazon EKS environments.

In this pattern we:

1. Automate deployment of multiple EKS cluster in a region, with a Continuous Deployment pipeline triggered upon a commit to the GitHub repository that hosts the pipeline configuration.

1. Configure the EKS clusters to deploy with different architectures (x86 or ARM or Bottlerocket) and different Kubernetes versions (3 most recent by default).

1. Automate testing of all the available [EKS Anywhere Addons](https://github.com/aws-samples/eks-anywhere-addons), on each of the clusters, essentially testing their compatibility across all the potential architecture/version available today on AWS.

1. Deploying this pattern 24x7 we observed high costs (300$ a day). By using the AWS Systems Manager Automations and AutoScaling Groups we scale-down to zero during non-business hours resulting in 60% cost savings. We also borrowed optimized OTEL collector configurations from [CDK Observability Accelerator](https://github.com/aws-observability/cdk-aws-observability-accelerator) to further reduce Prometheus storage costs.

To learn more about our EKS Addon validation checkout our [blog](https://aws.amazon.com/blogs/containers/conformitron-validate-third-party-software-with-amazon-eks-and-amazon-eks-anywhere/)

![Architecture of multi-cluster deployment](images/conformitron.png)

### GitOps confguration

GitOps is a branch of DevOps that focuses on using Git code repositories to manage infrastructure and application code deployments.

For this pattern there is a git driven deployment using GitHub and Codepipeline which automatically redploys the EKS Clusters when modifications are made to the GitHub repo.

Secondly, for the deployment of workloads on the cluster we leverage FluxCD, this a GitOps approach for the workloads i.e. the third-party-software we want to validate on our hardware.

We require some additional secrets to be created in Secrets Manager for the pattern to function properly

1. AWS CodePipeline Bootstrap - The AWS CodePipeline points to the GitHub fork of this repository i.e [cdk-eks-blueprint-patterns] (https://github.com/aws-samples/cdk-eks-blueprints-patterns).

A `github-token` secret must be stored as plaintext in AWS Secrets Manager for the CodePipeline to access the webhooks on GitHub. For more information on how/why to set it up, please refer to the [docs](https://docs.aws.amazon.com/codepipeline/latest/userguide/GitHub-create-personal-token-CLI.html). The GitHub Personal Access Token should have these scopes:
1. *repo* - to read your forked cdk-blueprint-patterns repostiory
1. *admin:repo_hook* - if you plan to use webhooks (enabled by default)

1. FluxCD Bootstrap - The FluxCD points to the [EKS Anywhere Addons](https://github.com/aws-samples/eks-anywhere-addons) repository. Since this is a public repository you will not need to add a github token to read it.

As part of the FluxCD configuration, it uses Kustomize to apply all the addons that are in the repository along with deploying their functional tests and a custom validator cronJob.


## Prerequisites
Start by setting the account and region environment variables:

```sh
export ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
export AWS_REGION=$(aws configure get region)
```
1. In case you haven't done this before, bootstrap your AWS Account for AWS CDK use using:

```bash
cdk bootstrap
```

1. Fork this repository (cdk-eks-blueprints-patterns) to your GitHub organisation/user
1. Git clone your forked repository onto your machine
1. Install the AWS CDK Toolkit globally on your machine using

```bash
npm install -g aws-cdk@2.133.0
```

1. Increase AWS service quota for required resources, navigate to [Service Quota Tutorial](https://aws.amazon.com/getting-started/hands-on/request-service-quota-increase/) to learn more
```
SERVICE | QUOTA NAME | REQUESTED QUOTA
Amazon Virtual Private Cloud (Amazon VPC) | NAT gateways per Availability Zone | 30
Amazon Virtual Private Cloud (Amazon VPC) | VPCs per region | 30
Amazon Elastic Compute Cloud (Amazon EC2) | EC2-VPC Elastic IPs | 30
```
We are using seperate VPC as a best practice, but you can use default vpc if you prefer. Also, If you decide to use different regions for each cluster you dont need quota increase, please reach out if you have need for this use case.

1. Amazon Managed Grafana Workspace: To visualize metrics collected, you need an Amazon Managed Grafana workspace. If you have an existing workspace, create environment variables `AMG_ENDPOINT_URL` as described below.

Else, to create a new workspace, visit and run our [supporting example for Grafana Deployment](https://aws-observability.github.io/terraform-aws-observability-accelerator/helpers/managed-grafana/)

```bash
export AMG_ENDPOINT_URL=https://g-xxx.grafana-workspace.region.amazonaws.com
export AMG_WORKSPACE_ID=g-xxx
```

1. Grafana API Key: Amazon Managed Grafana provides a control plane API for generating Grafana API keys or Service Account Tokens. This allows programatic provisioning of Grafana dashboards using the EKS grafana operator.

```bash
export AMG_API_KEY=$(aws grafana create-workspace-api-key \
--key-name "grafana-operator-key" \
--key-role "ADMIN" \
--seconds-to-live 432000 \
--workspace-id $AMG_WORKSPACE_ID \
--query key \
--output text)
```

1. AWS SSM Parameter Store for GRAFANA API KEY: Update the Grafana API key secret in AWS SSM Parameter Store using the above new Grafana API key. This will be referenced by Grafana Operator deployment of our solution to access and provision Grafana dashboards from Amazon EKS monitoring Cluster

```bash
aws ssm put-parameter --name "/grafana-api-key" \
--type "SecureString" \
--value $AMG_API_KEY \
--region $AWS_REGION
```

1. Amazon Managed Prometheus Workspace: To store observability metrics from all clusters we will use Amazon Managed Prometheus due to it's ease of setup and easy integration with other AWS services. We recommend setting up a new seperate Prometheus workspace using the CLI commands below. The provisioning of a new AMP workspace can be automated by leveraging the `.resourceProvider` in our CDK blueprints. See [Example](https://github.com/aws-observability/cdk-aws-observability-accelerator/blob/main/lib/existing-eks-opensource-observability-pattern/index.ts). We intentionally left this out to allow to connecting with existing AMP deployments, but please reach out to us if you need guidance on automate this provisioning.

```bash
aws amp create-workspace --alias conformitron
```

Copy the `workspaceID` from the output and export it as a variable

```bash
export AMP_WS_ID=ws-xxxxxxx-xxxx-xxxx-xxxx-xxxxxx
```


1. Modify the code in your forked repo to point to your GitHub username/organisation. Open the [pattern file source code](../../lib/multi-cluster-construct/pipeline.ts) and look for the declared const of `gitOwner`. Change it to your GitHub username.


## Deploying

Clone the repository:

```sh
git clone https://github.com/aws-samples/cdk-eks-blueprints-patterns.git
cd cdk-eks-blueprints-patterns
```

Set the pattern's parameters in the CDK context by overriding the _cdk.json_ file (edit _PARENT_DOMAIN_NAME_ as it fits):
```sh
cat << EOF > cdk.json
{
"app": "npx ts-node dist/lib/common/default-main.js",
"context": {
"conformitron.amp.endpoint": "https://aps-workspaces.${AWS_REGION}.amazonaws.com/workspaces/${AMP_WS_ID}/",
"conformitron.amp.arn":"arn:aws:aps:${AWS_REGION}:${ACCOUNT_ID}:workspace/${AMP_WS_ID}",
"conformitron.amg.endpoint": "${AMG_ENDPOINT_URL}",
"conformitron.version": ["1.28","1.29","1.30"],
"fluxRepository": {
"name": "grafana-dashboards",
"namespace": "grafana-operator",
"repository": {
"repoUrl": "https://github.com/aws-observability/aws-observability-accelerator",
"name": "grafana-dashboards",
"targetRevision": "main",
"path": "./artifacts/grafana-operator-manifests/eks/infrastructure"
},
"values": {
"GRAFANA_CLUSTER_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/cluster.json",
"GRAFANA_KUBELET_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/kubelet.json",
"GRAFANA_NSWRKLDS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/namespace-workloads.json",
"GRAFANA_NODEEXP_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodeexporter-nodes.json",
"GRAFANA_NODES_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodes.json",
"GRAFANA_WORKLOADS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/workloads.json"
},
"kustomizations": [
{
"kustomizationPath": "./artifacts/grafana-operator-manifests/eks/infrastructure"
}
]
}
}
}

EOF
```

You are now ready to deploy the pipeline. Run the following command from the root of this repository to deploy the pipeline stack:

```bash
make pattern multi-cluster-conformitron deploy multi-cluster-central-pipeline
```

Now you can go to [AWS CodePipeline console](https://eu-west-1.console.aws.amazon.com/codesuite/codepipeline/pipelines), and see how it was automatically created to deploy multiple Amazon EKS clusters to different environments.
elamaran11 marked this conversation as resolved.
Show resolved Hide resolved

## Grafana Dashboards
![Dashboard 1](images/ConformitronDashboard1.png)

![Dashboard 2](images/ConformitronDashboard2.png)

![Dashboard 3](images/ConformitronDashboard3.png)


# SSM Cost Optimizations for conformitron clusters

Running all the clusters by default for 24 hours results in a daily spend of $300+

To minimize these costs we have written a systems manager automation which automatically scales down autoscaling group to 0 desired nodes during off-business hours.

On weekdays 5 PM PST clusters are scaled to 0 -> CRON EXPRESSION: `0 17 ? * MON-FRI *`
On weekdays 5 AM PST clusters are scaled to 1 -> CRON EXPRESSION: `0 05 ? * MON-FRI *`
On weekends clusters stay scaled to 0.

These optimizations bring down the weekly cost to less than 1000$ essentially for a more than 60% cost savings.

Please find the SSM Automation documents `lib/multi-cluster-construct/resources/cost-optimization/scaleDownEksToZero.yml` and `lib/multi-cluster-construct/resources/cost-optimization/scaleUpEksToOne.yml`.

Lets take a look at one of the scripts `scaleDownEksToZero.yml`

```yaml
schemaVersion: '0.3'
...
...
mainSteps:
...
...
inputs:
Service: eks
Api: UpdateNodegroupConfig <---- Update the managed node group
clusterName: arm-1-26-blueprint <---- Modify according to your naming convention
nodegroupName: eks-blueprints-mng
scalingConfig:
minSize: 0 <---- New Scaling Configuration
maxSize: 1
desiredSize: 0 <---- Scale To zero
```
By triggering this automation at 5PM on Weekdays we automatically scale down clusters during off-hours.

To run these scripts first you will have to modify update them with your own account_ID
We will use `sed` command to automatically update the files
```bash
sed "s/ACCOUNT_ID/$ACCOUNT_ID/g" scaleDownEksToZero.yml > scaleDownEksToZeroNew.yml
sed "s/ACCOUNT_ID/$ACCOUNT_ID/g" scaleUpEksToOne.yml > scaleUpEksToOneNew.yml
```

1. Then navigate to the Systems Manager > Documents and Create a new Automation.

![Cost Optimization Step 1](images/CostOptimizationSSM1.png)

1. Click on JSON and copy over the yml content to create a new runbook

![Cost Optimization Step 2](images/CostOptimizationSSM2.png)

1. Once saved, navigate to EventBridge > Scheduler > Schedules

![Cost Optimization Step 3](images/CostOptimizationEventBridge.png)

1. Create a new schedule with the CRON expression specified aboce

![Cost Optimization Step 4](images/CostOptimizationEventBridge2.png)

1. For Target select "StartAutomationExecution" and type in the document name from step 2

![Cost Optimization Step 5](images/CostOptimizationEventBridge3.png)

69 changes: 69 additions & 0 deletions lib/multi-cluster-construct/cluster-secret-store-addon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as blueprints from '@aws-quickstart/eks-blueprints';
import * as eks from "aws-cdk-lib/aws-eks";
import { Construct } from 'constructs';
import { dependable } from '@aws-quickstart/eks-blueprints/dist/utils';

export class ClusterSecretStoreAddon implements blueprints.ClusterAddOn {
id?: string | undefined;
@dependable(blueprints.addons.ExternalsSecretsAddOn.name)
deploy(clusterInfo: blueprints.ClusterInfo): void | Promise<Construct> {
const cluster = clusterInfo.cluster;

const clusterSecretStore = new eks.KubernetesManifest(clusterInfo.cluster, "ClusterSecretStore", {
cluster: cluster,
manifest: [
{
apiVersion: "external-secrets.io/v1beta1",
kind: "ClusterSecretStore",
metadata: {name: "eksa-secret-store"},
spec: {
provider: {
aws: {
service: "SecretsManager",
region: clusterInfo.cluster.stack.region,
auth: {
jwt: {
serviceAccountRef: {
name: "external-secrets-sa",
namespace: "external-secrets",
},
},
},
},
},
},
},
],
});

const clusterConfigMapStore = new eks.KubernetesManifest(clusterInfo.cluster, "ClusterConfigMap", {
cluster: cluster,
manifest: [
{
apiVersion: "external-secrets.io/v1beta1",
kind: "ClusterSecretStore",
metadata: {name: "eksa-configmap-store"},
spec: {
provider: {
aws: {
service: "ParameterStore",
region: clusterInfo.cluster.stack.region,
auth: {
jwt: {
serviceAccountRef: {
name: "external-secrets-sa",
namespace: "external-secrets",
},
},
},
},
},
},
},
],
});

clusterConfigMapStore.node.addDependency(clusterSecretStore);
return Promise.resolve(clusterSecretStore);
}
}
Loading
Loading