Skip to content

Commit

Permalink
add: Initial commit of anyscale-k8s-helm
Browse files Browse the repository at this point in the history
Changes to be committed:
	new file:   anyscale-k8s-helm/README.md
	new file:   anyscale-k8s-helm/data.tf
	new file:   anyscale-k8s-helm/helm-autoscaler.tf
	new file:   anyscale-k8s-helm/helm-ingress.tf
	new file:   anyscale-k8s-helm/helm-nvidia.tf
	new file:   anyscale-k8s-helm/main.tf
	new file:   anyscale-k8s-helm/outputs.tf
	new file:   anyscale-k8s-helm/test/README.md
	new file:   anyscale-k8s-helm/test/anyscale-aws-test/.terraform.lock.hcl
	new file:   anyscale-k8s-helm/test/anyscale-aws-test/main.tf
	new file:   anyscale-k8s-helm/test/anyscale-aws-test/outputs.tf
	new file:   anyscale-k8s-helm/test/anyscale-aws-test/variables.tf
	new file:   anyscale-k8s-helm/test/anyscale-aws-test/versions.tf
	new file:   anyscale-k8s-helm/test/anyscale-gcp-test/versions.tf
	new file:   anyscale-k8s-helm/test/eksctltest.yaml
	new file:   anyscale-k8s-helm/variables.tf
	new file:   anyscale-k8s-helm/versions.tf
  • Loading branch information
brent-anyscale committed Aug 14, 2024
1 parent dc8a36c commit 462c7d0
Show file tree
Hide file tree
Showing 17 changed files with 707 additions and 0 deletions.
17 changes: 17 additions & 0 deletions anyscale-k8s-helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[![Build Status][badge-build]][build-status]
[![Terraform Version][badge-terraform]](https://github.com/hashicorp/terraform/releases)
[![AWS Provider Version][badge-tf-aws]](https://github.com/terraform-providers/terraform-provider-aws/releases)

# anyscale-k8s-helm
This module creates Kubernetes helm charts for Anyscale applications and workloads.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- References -->
[Terraform]: https://www.terraform.io
[Issues]: https://github.com/anyscale/sa-sandbox-terraform/issues
[badge-build]: https://github.com/anyscale/sa-sandbox-terraform/workflows/CI/CD%20Pipeline/badge.svg
[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20-623CE4.svg?logo=terraform
[badge-tf-aws]: https://img.shields.io/badge/AWS-5.+-F8991D.svg?logo=terraform
[build-status]: https://github.com/anyscale/sa-sandbox-terraform/actions
1 change: 1 addition & 0 deletions anyscale-k8s-helm/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

32 changes: 32 additions & 0 deletions anyscale-k8s-helm/helm-autoscaler.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Description: This file contains the terraform configuration to deploy the autoscaler helm chart.
# https://github.com/kubernetes/autoscaler

resource "helm_release" "anyscale_cluster_autoscaler" {
count = local.module_enabled && var.cloud_provider == "aws" ? 1 : 0

name = var.anyscale_cluster_autoscaler_chart.name
repository = var.anyscale_cluster_autoscaler_chart.repository
chart = var.anyscale_cluster_autoscaler_chart.chart
namespace = var.anyscale_cluster_autoscaler_chart.namespace
version = var.anyscale_cluster_autoscaler_chart.chart_version
create_namespace = true
wait = true

set {
name = "autoDiscovery.clusterName"
value = var.kubernetes_cluster_name
}

set {
name = "awsRegion"
value = data.aws_region.current[0].name
}

dynamic "set" {
for_each = var.anyscale_cluster_autoscaler_chart.values
content {
name = set.key
value = set.value
}
}
}
29 changes: 29 additions & 0 deletions anyscale-k8s-helm/helm-ingress.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "helm_release" "ingress" {
count = local.module_enabled ? 1 : 0

name = "anyscale-ingress"
repository = "https://kubernetes.github.io/ingress-nginx"
chart = "ingress-nginx"
namespace = var.ingress_namespace
version = "4.11.1"
create_namespace = true
wait = true
set {
name = "controller.service.type"
value = "LoadBalancer"
}
set {
name = "controller.service.annotations.service\\.beta\\.kubernetes\\.io/aws-load-balancer-type"
value = "nlb"
}

set {
name = "controller.allowSnippetAnnotations"
value = true
}

set {
name = "controller.autoscaling.enabled"
value = true
}
}
15 changes: 15 additions & 0 deletions anyscale-k8s-helm/helm-nvidia.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "helm_release" "nvidia" {
count = local.module_enabled ? 1 : 0
name = "nvidia-device-plugin"
repository = "https://nvidia.github.io/k8s-device-plugin"
chart = "nvidia-device-plugin"
namespace = "nvidia-device-plugin"
create_namespace = true
version = "0.16.2"

// https://github.com/NVIDIA/k8s-device-plugin?tab=readme-ov-file#deploying-with-gpu-feature-discovery-for-automatic-node-labels
set {
name = "gfd.enabled"
value = true
}
}
24 changes: 24 additions & 0 deletions anyscale-k8s-helm/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
locals {
module_enabled = var.module_enabled
}

# AWS Data Sources
data "aws_caller_identity" "current" {
count = var.cloud_provider == "aws" ? 1 : 0
}
data "aws_region" "current" {
count = var.cloud_provider == "aws" ? 1 : 0
}

# GCP Data Sources
data "google_client_config" "current" {
count = var.cloud_provider == "gcp" ? 1 : 0
}

data "kubernetes_service" "ingress" {
count = local.module_enabled ? 1 : 0
metadata {
name = "${helm_release.ingress[0].name}-${helm_release.ingress[0].chart}-controller"
namespace = var.ingress_namespace
}
}
19 changes: 19 additions & 0 deletions anyscale-k8s-helm/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "lb_hostnames" {
value = try(data.kubernetes_service.ingress[0].status.0.load_balancer.0.ingress.*.hostname, [])
}

output "lb_ips" {
value = try(data.kubernetes_service.ingress[0].status.0.load_balancer.0.ingress.*.ip, [])
}

output "helm_ingress_status" {
value = try(helm_release.ingress[0].status, "")
}

output "helm_nvidia_status" {
value = try(helm_release.nvidia[0].status, "")
}

output "helm_autoscaler_status" {
value = try(helm_release.anyscale_cluster_autoscaler[0].status, "")
}
5 changes: 5 additions & 0 deletions anyscale-k8s-helm/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# anyscale-k8s-helm module unit tests

The `anyscale-k8s-helm` module is cloud agnostic.
There are tests for both AWS and GCP as subfolders.

104 changes: 104 additions & 0 deletions anyscale-k8s-helm/test/anyscale-aws-test/.terraform.lock.hcl

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

108 changes: 108 additions & 0 deletions anyscale-k8s-helm/test/anyscale-aws-test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ---------------------------------------------------------------------------------------------------------------------
# CREATE Anyscale K8s Helm Resources
# This template creates EKS resources for Anyscale
# Requires:
# - VPC
# - Security Group
# - IAM Roles
# - EKS Cluster
# ---------------------------------------------------------------------------------------------------------------------
locals {
# azs = slice(data.aws_availability_zones.available.names, 0, 3)

full_tags = merge(tomap({
anyscale-cloud-id = var.anyscale_cloud_id,
anyscale-deploy-environment = var.anyscale_deploy_env
}),
var.tags
)
}

# ---------------------------------------------------------------------------------------------------------------------
# Create resources for EKS TF Module
# Creates a VPC
# Creates a Security Group
# Creates IAM Roles
# ---------------------------------------------------------------------------------------------------------------------
locals {
public_subnets = ["172.24.101.0/24", "172.24.102.0/24", "172.24.103.0/24"]
private_subnets = ["172.24.20.0/24", "172.24.21.0/24", "172.24.22.0/24"]
}
module "eks_vpc" {
source = "../../../aws-anyscale-vpc"

anyscale_vpc_name = "anyscale-tftest-eks"
cidr_block = "172.24.0.0/16"

public_subnets = local.public_subnets
private_subnets = local.private_subnets
}
locals {
# Because subnet ID may not be known at plan time, we cannot use it as a key
anyscale_subnet_count = length(local.private_subnets)
}

module "eks_securitygroup" {
source = "../../../aws-anyscale-securitygroups"

vpc_id = module.eks_vpc.vpc_id

security_group_name_prefix = "anyscale-tftest-eks-"

ingress_with_self = [
{ rule = "all-all" }
]
}

module "eks_iam_roles" {
source = "../../../aws-anyscale-iam"

module_enabled = true
create_anyscale_access_role = false
create_cluster_node_instance_profile = false
create_iam_s3_policy = false

create_anyscale_eks_cluster_role = true
anyscale_eks_cluster_role_name = "anyscale-tftest-eks-cluster-role"
create_anyscale_eks_node_role = true
anyscale_eks_node_role_name = "anyscale-tftest-eks-node-role"

tags = local.full_tags
}

module "eks_cluster" {
source = "../../../aws-anyscale-eks-cluster"

module_enabled = true

anyscale_subnet_ids = module.eks_vpc.public_subnet_ids
anyscale_subnet_count = local.anyscale_subnet_count
anyscale_security_group_id = module.eks_securitygroup.security_group_id
eks_role_arn = module.eks_iam_roles.iam_anyscale_eks_cluster_role_arn

tags = local.full_tags
}

# ---------------------------------------------------------------------------------------------------------------------
# Create Helm Resources with no optional parameters
# ---------------------------------------------------------------------------------------------------------------------
module "all_defaults" {
source = "../../"

module_enabled = true
cloud_provider = "aws"

kubernetes_cluster_name = module.eks_cluster.eks_cluster_name
kubernetes_endpoint_address = module.eks_cluster.eks_cluster_endpoint
kubernetes_cluster_ca_data = module.eks_cluster.eks_cluster_ca_data
}

# ---------------------------------------------------------------------------------------------------------------------
# Do not create any resources
# ---------------------------------------------------------------------------------------------------------------------
module "test_no_resources" {
source = "../.."

module_enabled = false
cloud_provider = "aws"
}
20 changes: 20 additions & 0 deletions anyscale-k8s-helm/test/anyscale-aws-test/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

output "eks_cluster_name" {
description = "The name of the anyscale resource."
value = module.eks_cluster.eks_cluster_name
}

output "eks_cluster_arn" {
description = "The arn of the anyscale resource."
value = module.eks_cluster.eks_cluster_arn
}

output "eks_cluster_endpoint" {
description = "The endpoint of the anyscale resource."
value = module.eks_cluster.eks_cluster_endpoint
}

output "eks_kubeconfig" {
description = "The kubeconfig of the anyscale resource."
value = module.eks_cluster.eks_kubeconfig
}
Loading

0 comments on commit 462c7d0

Please sign in to comment.