• Stars
    star
    131
  • Rank 268,396 (Top 6 %)
  • Language HCL
  • License
    MIT License
  • Created about 1 year ago
  • Updated 15 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform modules for creating Nomad servers and clients nodes on AWS.

Nomad Cluster Setup

Terraform modules to deploy a HashiCorp Nomad cluster on AWS using an Auto Scaling Group (ASG). The modules are designed to provision Nomad servers and clients in ASG, making it easy to manage the infrastructure for Nomad cluster. Additionally, the repository includes Packer scripts to build a custom Amazon Machine Image (AMI) with Nomad pre-installed.

Nomad architecture

AMI

The repository includes a Packer file, to build a custom Amazon Machine Image (AMI) with Nomad and docker pre-installed. This AMI is used by the Terraform modules when creating the ASG instances.

To build the AMI, run:

cd packer
make build

NOTE: dry_run mode is toggled as true by default. To build the AMI, set the dry_run variable in Makefile to false.

AWS Resources

The key resources provisioned by this module are:

  1. Auto Scaling Group (ASG)
  2. Security Group
  3. IAM Role
  4. Application Load Balancer (ALB) (optional)

Auto Scaling Group (ASG)

The module deploys Nomad on top of an Auto Scaling Group (ASG). For optimal performance and fault tolerance, it is recommended to run the Nomad server ASG with 3 or 5 EC2 instances distributed across multiple Availability Zones. Each EC2 instance should utilize an AMI built using the provided Packer script.

NOTE: The Nomad Client terraform module allows setting up EC2 instances instead of ASGs. Check out the nomad_clients Terraform Module Reference for more information.

Security Group

Each EC2 instance within the ASG is assigned a Security Group that permits:

The common Security Group is attached to both client and server nodes, enabling the Nomad agent to communicate and discover other agents within the cluster. The Security Group ID is exposed as an output variable for adding additional rules as needed. Furthermore, you can provide your own list of security groups as a variable to the module.

IAM Role

An IAM Role is attached to each EC2 instance within the ASG. This role is granted a minimal set of IAM permissions, allowing each instance to automatically discover other instances in the same ASG and form a cluster with them.

ALB

An internal Application Load Balancer (ALB) is optionally created for the Nomad servers. The ALB is configured to listen on port 80/443 and forward requests to the Nomad servers on port 4646. The ALB is exposed as an output variable for adding additional rules as needed.

Nomad Server

The setup_server script included in this project configures and bootstraps Nomad server nodes in an AWS Auto Scaling group. The script performs the following steps:

  • Configures the Nomad agent as a server on the EC2 instances and uses the nomad_join_tag_value tag to auto-join the cluster. Once all the server instances discover each other, they elect a leader.
  • Bootstraps the Nomad ACL system with a pre-configured token on the first server.
    • It waits for the cluster leader to get elected before bootstrapping ACL.
    • The token must be passed as the nomad_acl_bootstrap_token variable.

Terraform Module Reference

Check out nomad_servers documentation for module reference.

Nomad Client

The setup_client script included in this project configures Nomad client nodes in an AWS Auto Scaling group. The script performs the following steps:

  • Configures the Nomad agent as a client on the EC2 instances and uses the nomad_join_tag_value tag to auto-join the cluster.
  • Configures DNS resolution for the Nomad cluster inside exec driver.
  • Prepares configurations for different task drivers.

Terraform Module Reference

Check out nomad_clients documentation for module reference.

Example Usage

Nomad Servers

module "nomad_servers" {
  source = "git::https://github.com/zerodha/nomad-cluster-setup//modules/nomad-servers?ref=main"

  cluster_name         = "demo-nomad"
  nomad_join_tag_value = "demo"
  instance_count       = 3
  ami                  = "ami-xyz"
  vpc                  = "vpc-xyz"
  subnets              = "subnet-xyz"
  create_alb           = true
  nomad_alb_hostname   = "nomad.example.internal"

  nomad_gossip_encrypt_key  = var.nomad_gossip_encrypt_key
  nomad_acl_bootstrap_token = var.nomad_acl_bootstrap_token
}

Nomad Clients

module "nomad_client_demo" {
  source = "git::https://github.com/zerodha/nomad-cluster-setup//modules/nomad-clients?ref=main"

  cluster_name              = "demo-nomad"
  nomad_join_tag_value      = "demo"
  client_name               = "example-app"
  enable_docker_plugin      = true
  ami                       = "ami-abc"
  instance_type             = "c6a.xlarge"
  instance_desired_count    = 10
  vpc                       = "vpc-xyz"
  subnets                   = "subnet-xyz"
  route_53_resolver_address = "10.0.0.2"
}

NOTE: This module does not set up an ALB for accessing applications running on Nomad Clients. This is left up to the user to configure. Check out terraform-aws-alb or Other Examples for more information. You may also need to set target_group_arns if Auto-Scaling Groups are used.

Other Examples

Contributors

Contributing

Contributions to this repository are welcome. Please submit a pull request or open an issue to suggest improvements or report bugs.

LICENSE

LICENSE

More Repositories

1

pykiteconnect

The official Python client library for the Kite Connect trading APIs
Python
959
star
2

dungbeetle

A highly opinionated, distributed job-queue built specifically for queuing and executing heavy SQL read jobs asynchronously. Supports MySQL, Postgres, ClickHouse.
Go
397
star
3

kiteconnectjs

The official NodeJs client library for the Kite Connect trading APIs
TypeScript
307
star
4

javakiteconnect

The official Java client for communicating with Kite Connect API.
Java
194
star
5

gokiteconnect

Official Go client for Kite Connect API's
Go
165
star
6

frappe-attachments-s3

A frappe app to upload file attachments in doctypes to s3.
Python
111
star
7

logf

Extremely fast, light weight, zero alloc logfmt logging library for Go.
Go
85
star
8

gchatgpt

Google Chat bot for OpenAI ChatGPT
Go
81
star
9

fastglue

Fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework.
Go
78
star
10

dotnetkiteconnect

.NET library for Kite connect
C#
76
star
11

kite-connect-python-example

Kite connect Python client example
Python
62
star
12

simplesessions

simplesessions is a Go session management library that is completely agnostic of HTTP libraries and frameworks, backend stores, and even cookie jars.
Go
55
star
13

kaf-relay

Replicate and sync kafka topics between clusters in realtime. Supports topic re-mapping, healthchecks, and hot failovers for high availability.
Go
53
star
14

rbiparser

A utility for downloading, parsing and sanitizing bank database (IFSC, MICR, address etc.) Excel sheets from the RBI website.
Python
53
star
15

zerodhatech.github.io

The zerodha.tech blog
HTML
45
star
16

kiteconnect-rs

The official Rust client library for the Kite Connect trading APIs
Rust
45
star
17

phpkiteconnect

The official PHP client library for the Kite Connect trading APIs
PHP
43
star
18

cppkiteconnect

C++ Kite Connect API library / SDK
C++
40
star
19

py-frappe-client

Frappe client for humans
Python
30
star
20

fastcache

fastcache is an HTTP response caching package that plugs into fastglue that simplifies "dumb" caching of API endpoints.
Go
30
star
21

jpdfsigner

A HTTP server and a CLI for digitally signing PDFs.
Java
27
star
22

pdf_text_overlay

pdf_text_overlay is a python library to write text on top of pdf.
Python
25
star
23

vendor-payments

A frappe app that has workflows and reports to make payments to vendors by a company and track them
Python
25
star
24

kiteconnect-mocks

Mock responses for kiteconnect
23
star
25

mii-lama

A tool for posting metrics from node-exporter to LAMA (Indian stock market regulatory framework) API gateways
Go
19
star
26

rms-consolidated-scrips-status

A utility that parse Zerodha Consolidated google spreadsheets and render category-wise scrip details(margins, multiplier, etc)
Python
18
star
27

fastglue-csrf

CSRF middleware for https://github.com/zerodha/fastglue
Go
14
star
28

fastglue-metrics

Prometheus Metrics exposed for Fastglue HTTP Handlers.
Go
12
star
29

subscription_coupons

Subscription discount coupon code manager
Python
11
star
30

nithinkamath.me

HTML
11
star
31

osticket-autoassign

Osticket plugin to assign tickets automatically to random agents based on teams, department, and activity
PHP
10
star
32

osticket-archive

A utility to archive all closed tickets beyond a certain age to disk (including attachments) and delete them from the database. The tickets are archived as JSON files.
PHP
8
star
33

flask-kiteconnect

Flask extension for kiteconnect API
Python
7
star
34

python-wheels

Python wheels used in other Python projects
5
star
35

kite-discourse-sso

Discourse SSO in Go for Kite Connect. Serves as a template for implementing other Discourse integrations.
Go
4
star
36

fastglue-adapter

net/http adapter for fastglue
Go
3
star
37

pdfrender

Python
2
star