Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: F/Grafana RDS posgresQL #36

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions infra/scripts/dbs/rds/psql/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

GIT_TLD=`git rev-parse --show-toplevel`
source ${GIT_TLD}/infra/scripts/dbs/rds/common.sh

echo "\nAdd security psql security group rules"
aws ec2 authorize-security-group-ingress \
--group-id ${RDS_VPC_SECURITY_GROUP_ID}\
--protocol tcp \
--port 5432 \
--source-group ${CLUSTER_SG} \
--region ${AWS_REGION} \
--no-cli-pager

## Create subnet group
echo "\nCreate PSQL DB subnet group..."
aws rds create-db-subnet-group --cli-input-json "{\"DBSubnetGroupName\":\"grafana-psql-subnet-group\",\"DBSubnetGroupDescription\":\"grafana psql subnet group\",\"SubnetIds\":$SUBNET}" --region ${AWS_REGION} --no-cli-pager

######## Create psql db
echo "\nCreate PSQL DB..."
aws rds create-db-instance \
--db-name grafanapsql \
--db-instance-identifier grafanapsql \
--allocated-storage 10 \
--db-instance-class db.t3.micro \
--engine postgres \
--engine-version "16.1" \
--master-username grafana \
--master-user-password postgres \
--no-publicly-accessible \
--vpc-security-group-ids ${RDS_VPC_SECURITY_GROUP_ID} \
--db-subnet-group-name "grafana-psql-subnet-group" \
--backup-retention-period 0 \
--region ${AWS_REGION} \
--tags Key=name,Value=grafanapsql \
--port 5432 \
--no-cli-pager

echo "\n Wait for PSQL DB..."
aws rds wait db-instance-available --db-instance-identifier grafanapsql --region ${AWS_REGION}

## GET DB endpoint
export PSQL_HOST=$(aws rds describe-db-instances --db-instance-identifier grafanapsql --region ${AWS_REGION} --query 'DBInstances[*].Endpoint.Address' --output text)
7 changes: 7 additions & 0 deletions infra/scripts/dbs/rds/psql/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

AWS_REGION=us-west-2

aws rds delete-db-instance --db-instance-identifier grafanapsql --skip-final-snapshot --region ${AWS_REGION} --no-cli-pager
aws rds wait db-instance-deleted --db-instance-identifier grafanapsql --region ${AWS_REGION} --no-cli-pager
aws rds delete-db-subnet-group --db-subnet-group-name grafana-psql-subnet-group --region ${AWS_REGION} --no-cli-pager
12 changes: 7 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ help:
@echo " Clenaup cluster via: make cleanup-cluster"
@echo " Clenaup all via: make cleanup"

setup: setup-cluster setup-cluster-autoscaler setup-istio setup-psql setup-observability setup-dbs-rds setup-rabbitmq-operator setup-app setup-gateway setup-keda setup-loadgen
setup: setup-cluster setup-cluster-autoscaler setup-istio setup-rds-psql setup-observability setup-dbs-rds setup-rabbitmq-operator setup-app setup-gateway setup-keda setup-loadgen

cleanup: destroy-istio-gateway destroy-dbs-rds cleanup-cluster destroy-loadgen

Expand Down Expand Up @@ -90,10 +90,9 @@ setup-loadgen:
kubectl create ns loadgen --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f scenarios/load-gen/load.yaml

setup-psql:
setup-rds-psql:
./infra/scripts/dbs/rds/psql/create.sh
kubectl create ns monitoring --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f monitoring/grafana-postgres/statefulset.yaml
kubectl wait --for=condition=ready pod -l app=postgresql --timeout=300s -n monitoring
kubectl apply -f monitoring/grafana-postgres/job.yaml

destroy-db-rds-mysql:
Expand All @@ -108,11 +107,14 @@ destroy-db-rds-sg:
destroy-istio-gateway:
helm uninstall istio-ingressgateway -n istio-system

destroy-dbs-rds: destroy-db-rds-mysql destroy-db-rds-documentdb destroy-db-rds-sg
destroy-dbs-rds: destroy-db-rds-mysql destroy-rds-psql destroy-db-rds-sg

destroy-loadgen:
kubectl delete -f scenarios/load-gen/load.yaml

destroy-rds-psql:
./infra/scripts/dbs/rds/psql/destroy.sh

cleanup-cluster:
eksctl delete cluster --region=us-east-1 --name=prod-eks-cluster --wait
aws iam delete-policy --policy-arn arn:aws:iam::813864300626:policy/k8s-asg-policy
Expand Down
4 changes: 2 additions & 2 deletions monitoring/chart-values/prometheus-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ grafana:
grafana.ini:
database:
type: postgres
host: postgres
user: postgres
host: grafanapsql.cn9m6m4s8zo0.us-west-2.rds.amazonaws.com
user: grafana
password: postgres
enabled: true
env:
Expand Down
2 changes: 1 addition & 1 deletion monitoring/grafana-postgres/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ spec:
containers:
- name: create-grafana-database
image: postgres:16.1-bullseye # Use the same PostgreSQL image
command: ["/bin/bash", "-c", "PGPASSWORD=postgres psql -h postgres -U postgres -c 'CREATE DATABASE grafana;'"]
command: ["/bin/bash", "-c", "PGPASSWORD=postgres psql -h grafanapsql.cn9m6m4s8zo0.us-west-2.rds.amazonaws.com -U grafana -d postgres -c 'CREATE DATABASE grafana;'"]
restartPolicy: Never