Skip to content

Commit 815bcb5

Browse files
committed
use external postgres and redis for nbc helm
1 parent 77cb7fb commit 815bcb5

File tree

6 files changed

+108
-7
lines changed

6 files changed

+108
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ this repo sets up three instances of netbox
66

77
# pre-req
88
```
9-
which terraform aws kubectl
9+
which terraform aws kubectl helm
1010
```
1111

1212
# how to use

nbc-helm.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#!/bin/bash
22

3-
helm install nbc oci://ghcr.io/netbox-community/netbox-chart/netbox --namespace nbc --create-namespace
3+
helm install netbox oci://ghcr.io/netbox-community/netbox-chart/netbox \
4+
--namespace netbox \
5+
--create-namespace \
6+
--set persistence.enabled=false \
7+
--set postgresql.enabled=false \
8+
--set externalDatabase.host=$(terraform output -raw postgres_host) \
9+
--set externalDatabase.password=$(terraform output -raw postgres_password) \
10+
--set valkey.enabled=false \
11+
--set tasksDatabase.host=$(terraform output -raw redis_host) \
12+
--set cachingDatabase.host=$(terraform output -raw redis_host)
413

5-
# sleep 400
6-
#export POD_NAME=$(kubectl get pods --namespace "nbc" -l "app.kubernetes.io/name=netbox,app.kubernetes.io/instance=nbc" -o jsonpath="{.items[0].metadata.name}")
7-
#kubectl port-forward $POD_NAME 8080:8080 -n nbc
14+
kubectl -n netbox create secret generic netbox-valkey \
15+
--from-literal=cache_password="" \
16+
--from-literal=task_password=""
17+
18+
# admin password
19+
kubectl -n netbox get secrets netbox-superuser -o jsonpath="{.data.password}" | base64 --decode
20+
21+
# port forward
22+
# kubectl -n netbox port-forward svc/netbox 8080:80
823

924
# cleanup
10-
# helm -n nbc uninstall nbc
11-
# kubectl delete pvc -n nbc --all
25+
# helm -n netbox uninstall netbox

postgres.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
resource "aws_db_subnet_group" "postgres" {
2+
name = "postgres-subnet-group"
3+
subnet_ids = module.vpc.private_subnets
4+
}
5+
6+
resource "aws_security_group" "postgres" {
7+
vpc_id = module.vpc.vpc_id
8+
}
9+
10+
resource "aws_vpc_security_group_egress_rule" "postgres_allow_all_out" {
11+
security_group_id = aws_security_group.postgres.id
12+
cidr_ipv4 = "0.0.0.0/0"
13+
ip_protocol = "-1"
14+
}
15+
16+
resource "aws_vpc_security_group_ingress_rule" "postgres_allow_psql_in" {
17+
security_group_id = aws_security_group.postgres.id
18+
cidr_ipv4 = "0.0.0.0/0"
19+
from_port = 5432
20+
to_port = 5432
21+
ip_protocol = "tcp"
22+
}
23+
24+
resource "aws_db_instance" "postgres" {
25+
identifier = "nb-pg-db"
26+
engine = "postgres"
27+
instance_class = "db.t3.medium"
28+
username = "netbox"
29+
password = var.postgres_password
30+
db_name = "netbox"
31+
allocated_storage = 20
32+
db_subnet_group_name = aws_db_subnet_group.postgres.name
33+
vpc_security_group_ids = [aws_security_group.postgres.id]
34+
skip_final_snapshot = true
35+
}
36+
37+
output "postgres_host" {
38+
value = aws_db_instance.postgres.address
39+
}
40+
41+
output "postgres_password" {
42+
value = var.postgres_password
43+
sensitive = true
44+
}

redis.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "aws_elasticache_subnet_group" "redis" {
2+
name = "redis-subnet-group"
3+
subnet_ids = module.vpc.private_subnets
4+
}
5+
6+
resource "aws_security_group" "redis" {
7+
name = "redis"
8+
vpc_id = module.vpc.vpc_id
9+
}
10+
11+
resource "aws_vpc_security_group_egress_rule" "redis_allow_all_out" {
12+
security_group_id = aws_security_group.redis.id
13+
cidr_ipv4 = "0.0.0.0/0"
14+
ip_protocol = "-1"
15+
}
16+
17+
resource "aws_vpc_security_group_ingress_rule" "redis_allow_redis_in" {
18+
security_group_id = aws_security_group.redis.id
19+
cidr_ipv4 = "0.0.0.0/0"
20+
from_port = 6379
21+
to_port = 6379
22+
ip_protocol = "tcp"
23+
}
24+
25+
resource "aws_elasticache_cluster" "redis" {
26+
cluster_id = "nb-redis"
27+
engine = "redis"
28+
node_type = "cache.t3.micro"
29+
num_cache_nodes = 1
30+
parameter_group_name = "default.redis7"
31+
subnet_group_name = aws_elasticache_subnet_group.redis.name
32+
security_group_ids = [aws_security_group.redis.id]
33+
}
34+
35+
output "redis_host" {
36+
value = aws_elasticache_cluster.redis.cache_nodes[0].address
37+
}

terraform.tfvars.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nbe_token = ""
22
nbe_console_password = "6chars"
33
nbe_admin_password = "12characters"
4+
postgres_password = "yesql123"

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ variable "nbe_admin_password" {
1212
type = string
1313
sensitive = true
1414
}
15+
16+
variable "postgres_password" {
17+
type = string
18+
sensitive = true
19+
}

0 commit comments

Comments
 (0)