Skip to content

Commit 89a63bc

Browse files
Add files via upload
1 parent c286003 commit 89a63bc

File tree

4 files changed

+345
-0
lines changed

4 files changed

+345
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# CAST AI Anywhere Terraform Deployment
2+
3+
This repository contains Terraform code to deploy CAST AI components on an "anywhere" (on-prem/Minikube) Kubernetes cluster. The configuration deploys two components:
4+
5+
- **CAST AI Agent**
6+
- **CAST AI Cluster Controller**
7+
- **CAST AI Evictor
8+
- **CAST AI Pod Mutator
9+
- **CAST AI Workload Autoscaler
10+
11+
## Prerequisites
12+
13+
Before deploying, ensure you have the following installed and configured:
14+
15+
- **Terraform** (v1.x recommended)
16+
[Download Terraform](https://www.terraform.io/downloads)
17+
- **Minikube**
18+
[Start Minikube](https://minikube.sigs.k8s.io/docs/start/)
19+
- **Docker Desktop** (make sure Docker is running)
20+
[Download Docker Desktop](https://www.docker.com/products/docker-desktop)
21+
- **kubectl**
22+
[Install kubectl](https://kubernetes.io/docs/tasks/tools/)
23+
- **Helm**
24+
[Install Helm](https://helm.sh/docs/intro/install/)
25+
26+
You will also need:
27+
- A valid **CAST AI API Key** (https://docs.cast.ai/docs/authentication)
28+
- A unique cluster identifier (for example, `minikube-anywhere-cluster`)
29+
30+
## Repository Structure
31+
32+
- **main.tf**
33+
Contains the Terraform configuration to:
34+
- Start Minikube and wait until it is ready.
35+
- Configure the Kubernetes and Helm providers (using the `minikube` context).
36+
- Create the required namespace.
37+
- Deploy the CAST AI Components.
38+
- **variables.tf**
39+
Defines variables for CAST AI API key, cluster identifier, and configurations.
40+
- **outputs.tf**
41+
Displays outputs such as the status of the deployed components.
42+
43+
## Setup and Deployment
44+
45+
### 1. Clone the Repository
46+
47+
Clone the repository to your local machine:
48+
49+
```sh
50+
git clone https://github.com/juliette-cast/castai-anywhere-terraform.git
51+
cd castai-anywhere-terraform
52+
```
53+
54+
### 2. Initialize Terraform
55+
56+
Run the following command to initialize Terraform and download the required providers:
57+
58+
```sh
59+
terraform init
60+
```
61+
62+
### 3. Validate the Terraform Configuration
63+
64+
Ensure the configuration is correct:
65+
66+
```sh
67+
terraform validate
68+
```
69+
70+
### 4. Plan the Deployment
71+
72+
Preview what Terraform will create:
73+
74+
```sh
75+
terraform plan
76+
```
77+
78+
### 5. 1st Apply the Configuration
79+
80+
This will create the cluster and Deploy the CAST AI Agentand connect to the UI, then you will use the clustr ID from the console to add to your vaoraibles to deploy the other components
81+
82+
```sh
83+
terraform apply
84+
```
85+
86+
### 6. 2nd Apply to deploy the other components
87+
88+
```sh
89+
terraform apply
90+
```
91+
92+
### 7. Verify Deployment
93+
94+
Check the status of deployed components:
95+
96+
```sh
97+
kubectl get pods -n castai-agent
98+
```
99+
100+
Expected output:
101+
```sh
102+
NAME READY STATUS RESTARTS AGE
103+
castai-agent-79bf777cc8-8w88l 2/2 Running 0 22m
104+
castai-agent-79bf777cc8-kvf2q 2/2 Running 0 22m
105+
castai-agent-cpvpa-964fc94b6-pqfzc 1/1 Running 0 23m
106+
castai-cluster-controller-77dffcd8f5-7jflv 2/2 Running 0 19m
107+
castai-cluster-controller-77dffcd8f5-cpnp6 2/2 Running 0 19m
108+
castai-evictor-64bdd9fb6c-tmxjv 1/1 Running 0 37s
109+
castai-evictor-cpvpa-6c6bdf8f74-r2m4b 1/1 Running 0 37s
110+
castai-pod-mutator-7556c5db85-pqrwx 1/1 Running 0 16m
111+
castai-pod-mutator-7556c5db85-tqzsh 1/1 Running 1 16m
112+
castai-workload-autoscaler-64655596c4-b72l7 1/1 Running 0 15m
113+
castai-workload-autoscaler-64655596c4-x7bj8 1/1 Running 1 (15m ago) 15m
114+
```
115+
116+
### 7. Check CAST AI Console
117+
118+
1. **Log in to [CAST AI Console](https://app.cast.ai)**
119+
2. **Navigate to `Clusters`**
120+
3. **Confirm that the Minikube cluster is "Connected"**
121+
122+
### 8. Optional: Destroy the Deployment
123+
124+
If you need to remove the deployment, run:
125+
126+
```sh
127+
terraform destroy
128+
```
129+
or delete the castai-agent namespace
130+
```sh
131+
kubectl delete ns castai-agent
132+
```
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Start Minikube using the Docker driver
2+
resource "null_resource" "start_minikube" {
3+
provisioner "local-exec" {
4+
command = "minikube start --driver=docker"
5+
}
6+
}
7+
8+
# Wait for Minikube to be ready
9+
data "external" "wait_for_minikube" {
10+
program = ["bash", "-c", "while ! kubectl get nodes >/dev/null 2>&1; do sleep 5; done; echo '{}'"]
11+
depends_on = [null_resource.start_minikube]
12+
}
13+
14+
# Configure the Kubernetes provider
15+
provider "kubernetes" {
16+
config_path = "~/.kube/config"
17+
config_context = "minikube"
18+
}
19+
20+
# Configure the Helm provider
21+
provider "helm" {
22+
kubernetes {
23+
config_path = "~/.kube/config"
24+
config_context = "minikube"
25+
}
26+
}
27+
28+
# Create the namespace "castai-agent"
29+
resource "kubernetes_namespace" "castai" {
30+
depends_on = [data.external.wait_for_minikube]
31+
metadata {
32+
name = "castai-agent"
33+
labels = {
34+
"app.kubernetes.io/managed-by" = "Helm"
35+
}
36+
annotations = {
37+
"meta.helm.sh/release-name" = "castai-agent"
38+
"meta.helm.sh/release-namespace" = "castai-agent"
39+
}
40+
}
41+
}
42+
43+
# Install CAST AI Agent
44+
resource "helm_release" "castai_agent" {
45+
depends_on = [kubernetes_namespace.castai]
46+
name = "castai-agent"
47+
repository = "https://castai.github.io/helm-charts"
48+
chart = "castai-agent"
49+
namespace = "castai-agent"
50+
create_namespace = false
51+
timeout = 600
52+
53+
set {
54+
name = "apiKey"
55+
value = var.cast_ai_api_key
56+
}
57+
set {
58+
name = "clusterName"
59+
value = var.cluster_name
60+
}
61+
set {
62+
name = "provider"
63+
value = "anywhere"
64+
}
65+
}
66+
67+
# Install CAST AI Cluster Controller
68+
resource "helm_release" "castai_cluster_controller" {
69+
depends_on = [helm_release.castai_agent]
70+
name = "castai-cluster-controller"
71+
repository = "https://castai.github.io/helm-charts"
72+
chart = "castai-cluster-controller"
73+
namespace = "castai-agent"
74+
create_namespace = false
75+
timeout = 600
76+
77+
set {
78+
name = "castai.apiKey"
79+
value = var.cast_ai_api_key
80+
}
81+
set {
82+
name = "castai.clusterID"
83+
value = var.cluster_id
84+
}
85+
set {
86+
name = "enableTopologySpreadConstraints"
87+
value = "true"
88+
}
89+
}
90+
91+
# Install CAST AI Evictor
92+
resource "helm_release" "castai_evictor" {
93+
depends_on = [helm_release.castai_cluster_controller]
94+
name = "castai-evictor"
95+
repository = "https://castai.github.io/helm-charts"
96+
chart = "castai-evictor"
97+
namespace = "castai-agent"
98+
create_namespace = false
99+
timeout = 600
100+
101+
set {
102+
name = "managedByCASTAI"
103+
value = var.managed_by_castai
104+
}
105+
set {
106+
name = "replicaCount"
107+
value = "1"
108+
}
109+
set {
110+
name = "aggressive_mode"
111+
value = "true"
112+
}
113+
}
114+
115+
# Install CAST AI Pod Mutator
116+
resource "helm_release" "castai_pod_mutator" {
117+
depends_on = [helm_release.castai_cluster_controller]
118+
name = "castai-pod-mutator"
119+
repository = "https://castai.github.io/helm-charts"
120+
chart = "castai-pod-mutator"
121+
namespace = "castai-agent"
122+
create_namespace = false
123+
timeout = 600
124+
125+
set {
126+
name = "castai.apiKey"
127+
value = var.cast_ai_api_key
128+
}
129+
set {
130+
name = "castai.clusterID"
131+
value = var.cluster_id
132+
}
133+
set {
134+
name = "enableTopologySpreadConstraints"
135+
value = "true"
136+
}
137+
138+
set {
139+
name = "castai.organizationID"
140+
value = var.organization_id # <-- Add this line
141+
}
142+
}
143+
144+
145+
146+
# Install CAST AI Workload Autoscaler
147+
resource "helm_release" "castai_workload_autoscaler" {
148+
depends_on = [helm_release.castai_pod_mutator]
149+
name = "castai-workload-autoscaler"
150+
repository = "https://castai.github.io/helm-charts"
151+
chart = "castai-workload-autoscaler"
152+
namespace = "castai-agent"
153+
create_namespace = false
154+
timeout = 600
155+
156+
set {
157+
name = "castai.apiKey"
158+
value = var.cast_ai_api_key
159+
}
160+
set {
161+
name = "castai.clusterID"
162+
value = var.cluster_id
163+
}
164+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "castai_agent_status" {
2+
value = helm_release.castai_agent.status
3+
}
4+
5+
output "castai_cluster_controller_status" {
6+
value = helm_release.castai_cluster_controller.status
7+
}
8+
9+
output "castai_evictor_status" {
10+
value = helm_release.castai_evictor.status
11+
}
12+
13+
output "castai_pod_mutator_status" {
14+
value = helm_release.castai_pod_mutator.status
15+
}
16+
17+
output "castai_workload_autoscaler_status" {
18+
value = helm_release.castai_workload_autoscaler.status
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variable "cast_ai_api_key" {
2+
description = "Your CAST AI API key"
3+
type = string
4+
sensitive = true
5+
default = "" # add your api key
6+
}
7+
8+
variable "cluster_name" {
9+
description = "Name of your cluster"
10+
type = string
11+
default = "" # give a name for your cluster
12+
}
13+
14+
variable "cluster_id" {
15+
description = "Identifier for your CAST AI cluster"
16+
type = string
17+
default = "" # add the cluster ID you copied from the UI from the 1st apply
18+
}
19+
20+
variable "organization_id" {
21+
description = "Your CAST AI Organization ID"
22+
type = string
23+
default = "" # add your Org ID ..this is required for pod mutator deployment
24+
}
25+
26+
variable "managed_by_castai" {
27+
description = "Flag to indicate if the components are managed by CAST AI"
28+
type = bool
29+
default = false # if its true, CAST overrides every changes made
30+
}

0 commit comments

Comments
 (0)