From c9caf41a1e206adcfecfe27c34281fefe28f6ab3 Mon Sep 17 00:00:00 2001 From: Juho Holmi Date: Fri, 2 Apr 2021 14:29:35 +0300 Subject: [PATCH] Use mongo_values.yaml and add PVC Signed-off-by: Juho Holmi --- .gitignore | 1 + modules/container_deployment/main.tf | 89 +++---------------- .../container_deployment/mongo_values.yaml | 17 ++++ modules/k8s/main.tf | 23 ++++- 4 files changed, 50 insertions(+), 80 deletions(-) create mode 100644 modules/container_deployment/mongo_values.yaml diff --git a/.gitignore b/.gitignore index 80647fc..865ec69 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ override.tf.json # End of https://www.toptal.com/developers/gitignore/api/terraform *kubeconfig +my_stuff.json \ No newline at end of file diff --git a/modules/container_deployment/main.tf b/modules/container_deployment/main.tf index 0e6cb44..b87b3c6 100644 --- a/modules/container_deployment/main.tf +++ b/modules/container_deployment/main.tf @@ -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" @@ -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" @@ -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" - } - } - } - } - } - } -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/modules/container_deployment/mongo_values.yaml b/modules/container_deployment/mongo_values.yaml new file mode 100644 index 0000000..ba8a5f9 --- /dev/null +++ b/modules/container_deployment/mongo_values.yaml @@ -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" \ No newline at end of file diff --git a/modules/k8s/main.tf b/modules/k8s/main.tf index 57486eb..bbfe860 100644 --- a/modules/k8s/main.tf +++ b/modules/k8s/main.tf @@ -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" + } } \ No newline at end of file