Skip to content

Commit

Permalink
Add R/O Onboarding example for AKS (#230)
Browse files Browse the repository at this point in the history
* Add R/O Onboarding example for AKS

* remove unused variables

* run make generate-sdk

* update sdk

---------

Co-authored-by: Phil Andrews <[email protected]>
Co-authored-by: Phil Andrews <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2023
1 parent 820d922 commit 3ed7998
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
7 changes: 6 additions & 1 deletion castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions examples/aks/aks_cluster_read_only/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AKS and CAST AI example with CAST AI Autoscaler policies and additional Node Configurations
Following example shows how to onboard AKS cluster to CAST AI, configure [Autoscaler policies](https://docs.cast.ai/reference/policiesapi_upsertclusterpolicies) and additional [Node Configurations](https://docs.cast.ai/docs/node-configuration/).

Example configuration should be analysed in the following order:
1. Create Virtual network - `vnet.tf`
2. Create AKS cluster - `aks.tf`
3. Create CAST AI related resources to connect AKS cluster to CAST AI, configure Autoscaler and Node Configurations - `castai.tf`

# Usage
1. Rename `tf.vars.example` to `tf.vars`
2. Update `tf.vars` file with your cluster name, cluster region and CAST AI API token.
3. Initialize Terraform. Under example root folder run:
```
terraform init
```
4. Run Terraform apply:
```
terraform apply -var-file=tf.vars
```
5. To destroy resources created by this example:
```
terraform destroy -var-file=tf.vars
```
9 changes: 9 additions & 0 deletions examples/aks/aks_cluster_read_only/aks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "azuread_client_config" "current" {}

data "azurerm_subscription" "current" {}

data "azurerm_kubernetes_cluster" "this" {
name = var.cluster_name
resource_group_name = var.resource_group
}

42 changes: 42 additions & 0 deletions examples/aks/aks_cluster_read_only/castai.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 3. Connect AKS cluster to CAST AI in READ-ONLY mode.

# Configure Data sources and providers required for CAST AI connection.

provider "castai" {
api_url = var.castai_api_url
api_token = var.castai_api_token
}

provider "helm" {
kubernetes {
host = data.azurerm_kubernetes_cluster.this.kube_config.0.host
client_certificate = base64decode(data.azurerm_kubernetes_cluster.this.kube_config.0.client_certificate)
client_key = base64decode(data.azurerm_kubernetes_cluster.this.kube_config.0.client_key)
cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.this.kube_config.0.cluster_ca_certificate)
}
}

resource "helm_release" "castai_agent" {
name = "castai-agent"
repository = "https://castai.github.io/helm-charts"
chart = "castai-agent"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true

set {
name = "provider"
value = "aks"
}
set_sensitive {
name = "apiKey"
value = var.castai_api_token
}

# Required until https://github.com/castai/helm-charts/issues/135 is fixed.
set {
name = "createNamespace"
value = "false"
}
}

8 changes: 8 additions & 0 deletions examples/aks/aks_cluster_read_only/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Following providers required by AKS and Vnet resources.
provider "azurerm" {
features {}
}

provider "azuread" {
tenant_id = data.azurerm_subscription.current.tenant_id
}
4 changes: 4 additions & 0 deletions examples/aks/aks_cluster_read_only/tf.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cluster_name = "EXAMPLE"
cluster_region = "EXAMPLE"
castai_api_token = "EXAMPLE"
resource_group = "EXAMPLE_group"
25 changes: 25 additions & 0 deletions examples/aks/aks_cluster_read_only/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "cluster_name" {
type = string
description = "Name of the AKS cluster to be connected to the CAST AI."
}

variable "cluster_region" {
type = string
description = "Region of the cluster to be connected to CAST AI."
}

variable "resource_group" {
type = string
description = "Azure resource group that contains the cluster."
}

variable "castai_api_url" {
type = string
description = "CAST AI url to API, default value is https://api.cast.ai"
default = "https://api.cast.ai"
}

variable "castai_api_token" {
type = string
description = "CAST AI API token created in console.cast.ai API Access keys section."
}
14 changes: 14 additions & 0 deletions examples/aks/aks_cluster_read_only/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
azuread = {
source = "hashicorp/azuread"
}
castai = {
source = "castai/castai"
}
}
required_version = ">= 0.13"
}

0 comments on commit 3ed7998

Please sign in to comment.