Skip to content

Commit

Permalink
feat(Gossip KV): Cleanup Local and AWS Deployments (#1545)
Browse files Browse the repository at this point in the history
Closes #1529 (P0), #1528 (P1).

Summary of changes:
1. Local Deployments use Terraform.
2. Both Local / AWS Terraform projects have been split into separate
"infra" and "application" sections because there are intervening steps
(building images, etc.) that need to be done before applications can be
deployed.
3. Independent documentation for each local/AWS deployment - should make
it less confusing because these are expected to diverge.
  • Loading branch information
rohitkulshreshtha authored Nov 7, 2024
1 parent 656ee32 commit 33c2de2
Show file tree
Hide file tree
Showing 25 changed files with 1,468 additions and 250 deletions.
83 changes: 0 additions & 83 deletions datastores/gossip_kv/Makefile

This file was deleted.

37 changes: 5 additions & 32 deletions datastores/gossip_kv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,9 @@ The `sys` data section contains system data / state that is required by the key-

### `usr` Data

## Protocol
# Deployment
## Local (Minikube) Deployment
See [Minikube Deployment](./deployment/local/README.md) for more information.

## Checkpoints

# Running Locally Using Minikube
## Install Docker Desktop
```shell
brew install --cask docker
```
### Run docker (macOS)
```
open -a Docker
```

## Install Minikube
Read more [here](https://minikube.sigs.k8s.io/docs/start/)
```shell
brew install minikube
```

## Start Minikube
```shell
minikube start
```

## Install `kubectl`
```shell
brew install kubectl
```
## Configure Minikube to use your Docker Environment
```shell
eval $(minikube -p minikube docker-env)
```
## AWS Deployment
See [AWS Deployment](./deployment/aws/README.md) for more information.
76 changes: 76 additions & 0 deletions datastores/gossip_kv/deployment/aws/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
INFRA_PATH=./terraform/infra
APPLICATION_PATH=./terraform/application

BASE_IMAGE_VERSION:=latest
SERVER_IMAGE_VERSION:=latest
CLI_IMAGE_VERSION:=latest
LOAD_TEST_IMAGE_VERSION:=latest

# Docker Image Tags
BASE_IMAGE_TAG:=hydroflow-gossip-kv-base-image:$(BASE_IMAGE_VERSION)
SERVER_IMAGE_TAG:=hydroflow-gossip-kv-server:$(SERVER_IMAGE_VERSION)
CLI_IMAGE_TAG:=hydroflow-gossip-kv-cli:$(CLI_IMAGE_VERSION)
LOAD_TEST_IMAGE_TAG:=hydroflow-gossip-kv-load-test:$(LOAD_TEST_IMAGE_VERSION)

.PHONY : init infra docker_images base_image server_image cli_image upload_docker_images application config clean

init:
terraform -chdir="$(INFRA_PATH)" init
terraform -chdir="$(APPLICATION_PATH)" init

infra:
terraform -chdir="$(INFRA_PATH)" apply -auto-approve

kubectl_setup:
@echo "Setting up kubectl to work with AWS EKS Cluster"
aws eks update-kubeconfig --region $$(terraform -chdir=$(INFRA_PATH) output -raw region) --name $$(terraform -chdir=$(INFRA_PATH) output -raw cluster_name)

docker_images: base_image server_image cli_image

base_image:
docker build -t "$(BASE_IMAGE_TAG)" -f ../../../../datastores/gossip_kv/server/baseimage.Dockerfile ../../../..

server_image:
docker build -t "$(SERVER_IMAGE_TAG)" -f ../../../../datastores/gossip_kv/server/Dockerfile ../../../..

cli_image:
docker build -t "$(CLI_IMAGE_TAG)" -f ../../../../datastores/gossip_kv/cli/Dockerfile ../../../..

upload_docker_images: docker_images
$(eval SERVER_REPO_URL := $(shell terraform -chdir=$(INFRA_PATH) output -json repository_urls | jq -r '.["gossip_kv_server"]'))
$(eval CLI_REPO_URL := $(shell terraform -chdir=$(INFRA_PATH) output -json repository_urls | jq -r '.["gossip_kv_cli"]'))
$(eval LOAD_TEST_REPO_URL := $(shell terraform -chdir=$(INFRA_PATH) output -json repository_urls | jq -r '.["gossip_kv_load_test"]'))
$(eval REGION := $(shell terraform -chdir=$(INFRA_PATH) output -raw region))
echo $(SERVER_REPO_URL)
docker tag $(SERVER_IMAGE_TAG) $(SERVER_REPO_URL):$(SERVER_IMAGE_VERSION)
docker tag $(CLI_IMAGE_TAG) $(CLI_REPO_URL):$(CLI_IMAGE_VERSION)
docker tag $(LOAD_TEST_IMAGE_TAG) $(LOAD_TEST_REPO_URL):$(LOAD_TEST_IMAGE_VERSION)
aws ecr get-login-password --region $(REGION) | docker login --username AWS --password-stdin $(SERVER_REPO_URL)
docker push $(SERVER_REPO_URL):$(SERVER_IMAGE_VERSION)
aws ecr get-login-password --region $(REGION) | docker login --username AWS --password-stdin $(CLI_REPO_URL)
docker push $(CLI_REPO_URL):$(CLI_IMAGE_VERSION)
aws ecr get-login-password --region $(REGION) | docker login --username AWS --password-stdin $(LOAD_TEST_REPO_URL)
docker push $(LOAD_TEST_REPO_URL):$(LOAD_TEST_IMAGE_VERSION)

application:
terraform -chdir="$(APPLICATION_PATH)" apply -auto-approve

tunnel_grafana:
$(eval GRAFANA_PORT := $(shell terraform -chdir=$(APPLICATION_PATH) output -raw grafana_port))
@echo "Grafana will be accessible at http://localhost:$(GRAFANA_PORT)"
kubectl port-forward svc/grafana $(GRAFANA_PORT):$(GRAFANA_PORT)

tunnel_prometheus:
$(eval PROMETHEUS_PORT := $(shell terraform -chdir=$(APPLICATION_PATH) output -raw prometheus_port))
@echo "Prometheus will be accessible at http://localhost:$(PROMETHEUS_PORT)"
kubectl port-forward svc/prometheus $(PROMETHEUS_PORT):$(PROMETHEUS_PORT)


config:
kubectl apply -f seed_node_config.yaml

clean:
terraform -chdir="$(APPLICATION_PATH)" destroy -auto-approve
terraform -chdir="$(INFRA_PATH)" destroy -auto-approve
rm -rf $(INFRA_PATH)/.terraform $(INFRA_PATH)/terraform.tfstate $(INFRA_PATH)/terraform.tfstate.backup
rm -rf $(APPLICATION_PATH)/.terraform $(APPLICATION_PATH)/terraform.tfstate $(APPLICATION_PATH)/terraform.tfstate.backup
89 changes: 89 additions & 0 deletions datastores/gossip_kv/deployment/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# AWS Deployment

## Pre-requisites
- [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
- [Docker](https://docs.docker.com/get-docker/)
- [Kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- [Make](https://www.gnu.org/software/make/)
- [k9s](https://k9scli.io/)

### Mac Setup Using Homebrew
```shell
brew install terraform
brew install awscli
brew install docker
brew install kubernetes-cli
brew install k9s
```

## Initialize Setup
Initializes terraform providers required for local deployment.
```shell
make init
```

## Configure AWS Credentials
Make sure you have the AWS credentials configured. Subsequent terraform commands will use these credentials to create
the infrastructure.
```shell
aws configure
```

## Create Infrastructure
Creates a local kubernetes cluster using minikube.

```shell
make infra
```

## Kubectl
To enable kubectl usage with the newly created AWS EKS cluster, use the following command.

```shell
make kubectl_setup
```

## K9s
To monitor the cluster using k9s, use the following command.

```shell
k9s
```

## Build & Upload Docker Image
Build and upload the docker image for the application, into ECR.
```shell
make upload_docker_images
```

## Create Application
```shell
make application
```

## Check if the application is running
```shell
kubectl get pods # All gossip-kv-* pods should show status as "Running"
````

## Access Grafana Dashboards
```shell
make tunnel_grafana
```

## Access Prometheus
```shell
make tunnel_prometheus
```

## Update seed node configuration
```shell
make config
```

## Clean
Destroys the AWS resources and cleans up terraform state.
```shell
make clean
```
31 changes: 30 additions & 1 deletion datastores/gossip_kv/deployment/aws/terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
.terraform
### TERRAFORM IGNORES ###
# Terraform Plugin and module directories
**/.terraform/*

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

# Crash log files
crash.log
crash.*.log

*.tfvars
*.tfvars.json

# Ignore local override files
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Terraform CLI configuration files
.terraformrc
terraform.rc

# Backup files created by Terraform during state edits
*.backup

# Terraform plan files (these are generated and can be large)
*.tfplan

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

Loading

0 comments on commit 33c2de2

Please sign in to comment.