Skip to content

Commit

Permalink
Use mongo_values.yaml and add PVC
Browse files Browse the repository at this point in the history
Signed-off-by: Juho Holmi <[email protected]>
  • Loading branch information
JouHouFin committed Apr 2, 2021
1 parent f6dc54e commit c9caf41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ override.tf.json
# End of https://www.toptal.com/developers/gitignore/api/terraform

*kubeconfig
my_stuff.json
89 changes: 10 additions & 79 deletions modules/container_deployment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
#https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/guides/getting-started
#https://www.hashicorp.com/blog/kubernetes-cluster-with-aks-and-terraform

resource "kubernetes_namespace" "hono" {
metadata {
name = "hono"
}
}


# https://github.com/bitnami/azure-marketplace-charts/tree/master/bitnami/mongodb
resource "helm_release" "mongodb" {
name = "mongodb"
name = "mongodb"

repository = "https://marketplace.azurecr.io/helm/v1/repo"
chart = "mongodb"
version = "~> 10.7.1"
cleanup_on_fail = "true"
values = [
file("${path.module}/mongo_values.yaml")
]

set {
name = "architecture"
value = "standalone"
}
set {
name = "useStatefulSet"
value = "true"
}
set_sensitive {
name = "auth.rootPassword"
value = "root-secret"
Expand All @@ -32,35 +25,14 @@ resource "helm_release" "mongodb" {
name = "auth.password"
value = "hono-secret"
}
set_sensitive {
name = "auth.database"
value = "honodb"
}
set_sensitive {
name = "auth.username"
value = "honouser"
}
set {
name = "replicaCount"
value = "2"
}
set {
name = "cleanup_on_fail"
value = "true"
}
# Uncomment these if you want the DB to be externally available. NB! Remember that this
# script also has auth credentials, so use external access with caution.
#
# set {
# name = "externalAccess.enabled"
# value = "true"
# }
# set {
# name = "service.type"
# value = "LoadBalancer"
# }

}

# https://github.com/eclipse/packages/tree/master/charts/hono
resource "helm_release" "hono" {
name = "hono"

Expand Down Expand Up @@ -117,45 +89,4 @@ resource "helm_release" "hono" {
name = "cleanup_on_fail"
value = "true"
}
}

/*
resource "kubernetes_deployment" "test" {
metadata {
name = "test"
namespace= kubernetes_namespace.test.metadata.0.name
}
spec {
replicas = 2
selector {
match_labels = {
app = "test"
}
}
template {
metadata {
labels = {
app = "test"
}
}
spec {
container {
image = "nginx:1.19.4"
name = "nginx"
resources {
limits = {
memory = "512M"
cpu = "1"
}
requests = {
memory = "256M"
cpu = "50m"
}
}
}
}
}
}
}
*/
}
17 changes: 17 additions & 0 deletions modules/container_deployment/mongo_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
architecture: "standalone"
persistence:
existingClaim: "mongodb-data"
useStatefulSet: true
metrics:
enabled: true
replicaCount: 2
auth:
database: "honodb"

# Uncomment these if you want the DB to be externally available. NB! Remember that this
# script also has auth credentials, so use external access with caution.
#
# externalAccess:
# enabled: true
# service:
# type: "LoadBalancer"
23 changes: 22 additions & 1 deletion modules/k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,30 @@ resource "kubernetes_storage_class" "azure-disk-retain" {
}
storage_provisioner = "kubernetes.io/azure-disk"
reclaim_policy = "Retain"
volume_binding_mode = "WaitForFirstConsumer"
volume_binding_mode = "Immediate"
parameters = {
kind = "managed"
cachingMode = "ReadOnly"
}
}

resource "kubernetes_persistent_volume_claim" "example" {
metadata {
name = "mongodb-data"
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "8Gi"
}
}
storage_class_name = "azure-disk-retain"
}
}

resource "kubernetes_namespace" "hono" {
metadata {
name = "hono"
}
}

0 comments on commit c9caf41

Please sign in to comment.