Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 39 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# Local .terraform directories
**/.terraform*
**/terraform*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

# IntelliJ project files
.idea
*.iml
out
gen
119 changes: 119 additions & 0 deletions modules/rabbitmq-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# RabbitMQ @ Kubernetes

Deploy a RabbitMQ cluster on kubernetes using the RabbitmqOperator.

## Notes

* Use the label `spotinst.io/restrict-scale-down` to prevent right sizing.

## Implementation

```hcl
#
# Use the s3 bucket for state management.
#
terraform {

backend "s3" {}

}

#
# Get kubernetes cluster info.
#
data "aws_eks_cluster" "cluster" {

#
# mlfabric k8 cluster specifically for github action runners.
#
name = var.cluster_name

}

#
# Retrieve authentication for kubernetes from aws.
#
data "aws_eks_cluster_auth" "cluster" {

#
# mlfabric k8 cluster specifically for github action runners.
#
name = var.cluster_name

}

#
# Install the rabbitmq cluster object.
#
variable "aws_profile" {}
variable "aws_region" {}

#
# Retrieve authentication for kubernetes from aws.
#
provider "aws" {

profile = var.aws_profile
region = var.aws_region

}

#
# Get kubernetes cluster info.
#
data "aws_eks_cluster" "cluster" {

name = var.cluster_name

}

#
# Retrieve authentication for kubernetes from aws.
#
data "aws_eks_cluster_auth" "cluster" {

name = var.cluster_name

}

provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
token = data.aws_eks_cluster_auth.cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[ 0 ].data)
}

#
# Install the rabbitmq cluster object.
#
module "rabbitmq-nontls" {

source = "app.terraform.io/MAA-ML-DEVOPS/rabbitmq-cluster/kubernetes"
version = "2.0.7"

namespace = "default"
name = "rabbitmq"
internal_cidrs = "8.0.0.224/32"
limit_cpu = "7"
limit_memory = "15Gi"
replicas = 3
default_username = "rabbitmq"
default_password = "supersecret"

#
# Restrict rabbitmq to running on nodes with this selector.
#
role = "infra"

labels = {

#
# Prevent right sizing of the workload which causes rabbitmq
# to be rescheduled if downsizing occurs.
#
"spotinst.io/restrict-scale-down" = "true"

}

}

```
149 changes: 149 additions & 0 deletions modules/rabbitmq-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
resource "kubernetes_manifest" "cluster" {

manifest = {

"apiVersion" = "rabbitmq.com/v1beta1"
"kind" = "RabbitmqCluster"

"metadata" = {

"namespace" = var.namespace
"name" = var.name
"labels" = var.labels

}

"spec" = {

replicas = var.replicas
image = var.image

service = {

type = "LoadBalancer"

annotations = {

"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"
"service.beta.kubernetes.io/aws-load-balancer-internal" = var.internal_cidrs

}

}

affinity = {

nodeAffinity = {

requiredDuringSchedulingIgnoredDuringExecution = {

nodeSelectorTerms = [

{

matchExpressions = [

{

key = "role"
operator = "In"
values = [ var.role ]

}

]

}

]

}

}

}

override = {

statefulSet = {

spec = {

template = {

metadata = {

labels = var.labels

}

}

}

}

}

persistence = {

storageClassName = "gp2"
storage = "${ var.storage_gb }Gi"

}

resources = {

requests = {

cpu = var.limit_cpu
memory = var.limit_memory

}

limits = {

cpu = var.limit_cpu
memory = var.limit_memory

}

}

rabbitmq = {

additionalPlugins = var.additional_plugins
additionalConfig = <<EOF
prometheus.return_per_object_metrics = true
consumer_timeout = 3600000
default_user = ${ var.default_username }
default_pass = ${ var.default_password }
EOF

}

persistence = var.persistence

resources = {

requests = {

cpu = var.request_cpu
memory = var.request_memory

}

limits = {

cpu = var.limit_cpu
memory = var.limit_memory

}

}

}

}

}
Loading