github.com/m3db/m3@v1.5.0/kube/terraform/main.tf (about)

     1  resource "kubernetes_namespace" "m3db_namespace" {
     2    metadata {
     3      name = "m3db"
     4    }
     5  }
     6  
     7  resource "kubernetes_service" "etcd_service" {
     8    metadata {
     9      name      = "etcd"
    10      namespace = "m3db"
    11      labels {
    12        app = "etcd"
    13      }
    14    }
    15    spec {
    16      port {
    17        name = "client"
    18        port = 2379
    19      }
    20      port {
    21        name = "peer"
    22        port = 2380
    23      }
    24      selector {
    25        app = "etcd"
    26      }
    27      cluster_ip = "None"
    28    }
    29  }
    30  
    31  resource "kubernetes_service" "etcd_cluster" {
    32    metadata {
    33      name      = "etcd-cluster"
    34      namespace = "m3db"
    35      labels {
    36        app = "etcd"
    37      }
    38    }
    39    spec {
    40      port {
    41        protocol = "TCP"
    42        port     = 2379
    43      }
    44      selector {
    45        app = "etcd"
    46      }
    47      type = "ClusterIP"
    48    }
    49  }
    50  
    51  resource "kubernetes_stateful_set" "etcd_stateful_set" {
    52    metadata {
    53      name      = "etcd"
    54      namespace = "m3db"
    55      labels {
    56        app = "etcd"
    57      }
    58    }
    59    spec {
    60      service_name = "etcd"
    61      replicas = 3
    62      selector {
    63        match_labels {
    64          app = "etcd"
    65        }
    66      }
    67      template {
    68        metadata {
    69          labels {
    70            app = "etcd"
    71          }
    72        }
    73        spec {
    74          container {
    75            name    = "etcd"
    76            image   = "quay.io/coreos/etcd:v3.4.3"
    77            command = ["etcd", "--name", "$(MY_POD_NAME)", "--listen-peer-urls", "http://$(MY_IP):2380", "--listen-client-urls", "http://$(MY_IP):2379,http://127.0.0.1:2379", "--advertise-client-urls", "http://$(MY_POD_NAME).etcd:2379", "--initial-cluster-token", "etcd-cluster-1", "--initial-advertise-peer-urls", "http://$(MY_POD_NAME).etcd:2380", "--initial-cluster", "etcd-0=http://etcd-0.etcd:2380,etcd-1=http://etcd-1.etcd:2380,etcd-2=http://etcd-2.etcd:2380", "--initial-cluster-state", "new", "--data-dir", "/var/lib/etcd"]
    78            port {
    79              name           = "client"
    80              container_port = 2379
    81            }
    82            port {
    83              name           = "peer"
    84              container_port = 2380
    85            }
    86            env {
    87              name = "MY_IP"
    88              value_from {
    89                field_ref {
    90                  field_path = "status.podIP"
    91                }
    92              }
    93            }
    94            env {
    95              name = "MY_POD_NAME"
    96              value_from {
    97                field_ref {
    98                  field_path = "metadata.name"
    99                }
   100              }
   101            }
   102            env {
   103              name  = "ETCDCTL_API"
   104              value = "3"
   105            }
   106            volume_mount {
   107              name       = "etcd-data"
   108              mount_path = "/var/lib/etcd"
   109            }
   110          }
   111        }
   112      }
   113      volume_claim_template {
   114        metadata {
   115          name = "etcd-data"
   116        }
   117        spec {
   118          access_modes = ["ReadWriteOnce"]
   119          resources {
   120            requests {
   121              storage = "50Gi"
   122            }
   123          }
   124          storage_class_name = "fast"
   125        }
   126      }
   127    }
   128  }
   129  
   130  resource "kubernetes_config_map" "m3dbnode_config" {
   131    metadata {
   132      name      = "m3dbnode-config"
   133      namespace = "m3db"
   134    }
   135    data {
   136      m3dbnode.yml = "coordinator:\n  listenAddress: \"0.0.0.0:7201\"\n  metrics:\n    scope:\n      prefix: \"coordinator\"\n    prometheus:\n      handlerPath: /metrics\n      listenAddress: 0.0.0.0:7203\n    sanitization: prometheus\n    samplingRate: 1.0\n    extended: none\n  tagOptions:\n    idScheme: quoted\n\ndb:\n  logging:\n    level: info\n\n  metrics:\n    prometheus:\n      handlerPath: /metrics\n    sanitization: prometheus\n    samplingRate: 1.0\n    extended: detailed\n\n  listenAddress: 0.0.0.0:9000\n  clusterListenAddress: 0.0.0.0:9001\n  httpNodeListenAddress: 0.0.0.0:9002\n  httpClusterListenAddress: 0.0.0.0:9003\n  debugListenAddress: 0.0.0.0:9004\n\n  hostID:\n    resolver: hostname\n\n  client:\n    writeConsistencyLevel: majority\n    readConsistencyLevel: unstrict_majority\n\n  gcPercentage: 100\n\n  writeNewSeriesAsync: true\n  writeNewSeriesBackoffDuration: 2ms\n\n  commitlog:\n    flushMaxBytes: 524288\n    flushEvery: 1s\n    queue:\n      calculationType: fixed\n      size: 2097152\n\n  filesystem:\n    filePathPrefix: /var/lib/m3db\n\n  config:\n    service:\n        env: default_env\n        zone: embedded\n        service: m3db\n        cacheDir: /var/lib/m3kv\n        etcdClusters:\n        - zone: embedded\n          endpoints:\n          - http://etcd-0.etcd:2379\n          - http://etcd-1.etcd:2379\n          - http://etcd-2.etcd:2379\n"
   137    }
   138  }
   139  
   140  resource "kubernetes_service" "m3dbnode_service" {
   141    metadata {
   142      name      = "m3dbnode"
   143      namespace = "m3db"
   144      labels {
   145        app = "m3dbnode"
   146      }
   147    }
   148    spec {
   149      port {
   150        name = "client"
   151        port = 9000
   152      }
   153      port {
   154        name = "cluster"
   155        port = 9001
   156      }
   157      port {
   158        name = "http-node"
   159        port = 9002
   160      }
   161      port {
   162        name = "http-cluster"
   163        port = 9003
   164      }
   165      port {
   166        name = "debug"
   167        port = 9004
   168      }
   169      port {
   170        name = "coordinator"
   171        port = 7201
   172      }
   173      port {
   174        name = "coordinator-metrics"
   175        port = 7203
   176      }
   177      selector {
   178        app = "m3dbnode"
   179      }
   180      cluster_ip = "None"
   181    }
   182  }
   183  
   184  resource "kubernetes_service" "m3_coordinator_service" {
   185    metadata {
   186      name      = "m3coordinator"
   187      namespace = "m3db"
   188      labels {
   189        app = "m3dbnode"
   190      }
   191    }
   192    spec {
   193      port {
   194        name = "coordinator"
   195        port = 7201
   196      }
   197      port {
   198        name = "coordinator-metrics"
   199        port = 7203
   200      }
   201      selector {
   202        app = "m3dbnode"
   203      }
   204    }
   205  }
   206  
   207  resource "kubernetes_stateful_set" "m3dbnode_stateful_set" {
   208    metadata {
   209      name      = "m3dbnode"
   210      namespace = "m3db"
   211      labels {
   212        app = "m3dbnode"
   213      }
   214    }
   215    spec {
   216      service_name = "m3dbnode"
   217      replicas = 3
   218      selector {
   219        match_labels {
   220          app = "m3dbnode"
   221        }
   222      }
   223      update_strategy {
   224        type = "RollingUpdate"
   225      }
   226      template {
   227        metadata {
   228          labels {
   229            app = "m3dbnode"
   230          }
   231        }
   232        spec {
   233          container {
   234            name  = "m3db"
   235            image = "quay.io/m3/m3dbnode:latest"
   236            image_pull_policy = "Always"
   237            args  = ["-f", "/etc/m3db/m3dbnode.yml"]
   238            volume_mount {
   239              name       = "config-vol"
   240              mount_path = "/etc/m3db/"
   241            }
   242            volume_mount {
   243              name       = "m3db-db"
   244              mount_path = "/var/lib/m3db"
   245            }
   246            port {
   247              name           = "client"
   248              container_port = 9000
   249              protocol       = "TCP"
   250            }
   251            port {
   252              name           = "cluster"
   253              container_port = 9001
   254              protocol       = "TCP"
   255            }
   256            port {
   257              name           = "http-node"
   258              container_port = 9002
   259              protocol       = "TCP"
   260            }
   261            port {
   262              name           = "http-cluster"
   263              container_port = 9003
   264              protocol       = "TCP"
   265            }
   266            port {
   267              name           = "debug"
   268              container_port = 9004
   269              protocol       = "TCP"
   270            }
   271            port {
   272              name           = "coordinator"
   273              container_port = 7201
   274              protocol       = "TCP"
   275            }
   276            port {
   277              name           = "coord-metrics"
   278              container_port = 7203
   279              protocol       = "TCP"
   280            }
   281          }
   282          volume {
   283            name = "config-vol"
   284            config_map {
   285              name = "m3dbnode-config"
   286            }
   287          }
   288          dns_policy                       = "ClusterFirst"
   289          restart_policy                   = "Always"
   290          termination_grace_period_seconds = 30
   291        }
   292      }
   293      volume_claim_template {
   294        metadata {
   295          name = "m3db-db"
   296        }
   297        spec {
   298          access_modes = ["ReadWriteOnce"]
   299          storage_class_name = "fast"
   300          resources {
   301            requests {
   302              storage = "200Gi"
   303            }
   304          }
   305        }
   306      }
   307    }
   308  }
   309