This terraform module will deploy ghost blog on kubernetes through terraform.
The following resources will be created:
- Deployment
- Service
- Ingress
See the accompanying blog post at https://matthewdavis.io/highly-available-ghost-blog-on-kubernetes and the Terraform module at https://registry.terraform.io/modules/mateothegreat/ghost/kubernetes/latest!
The following will create two deployments for each site listed in the sites list:
locals {
sites = [
{
name = "matthewdavis.io"
hostnames = [ "matthewdavis.io" ]
}, {
name = "garagefarm-ai"
hostnames = [ "garagefarm.ai" ]
}
]
}
Tell terraform what providers to pull in so we can use them to create resources:
provider "google" {
project = "changeme"
region = "us-east4"
credentials = "/path/to/gcp/service-account-key.json"
}
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "name-of-your-cluster-context"
host = data.google_container_cluster.cluster.endpoint
insecure = true
}
Get the clusters API endpoint (remove this if you just want to hardcode it above --^):
data "google_container_cluster" "cluster" {
name = "name-of-your-cluster"
location = "us-east4-a"
}
The terraform magic:
module "site" {
count = length(local.sites)
name = local.sites[ count.index ].name
namespace = "default"
hostnames = local.sites[ count.index ].hostnames
database_host = "changeme"
database_username = "changeme"
database_password = "changeme"
database_name = replace(local.sites[ count.index ].name, "-", "_")
request_cpu = "250m"
request_memory = "200Mi"
limit_cpu = "500m"
limit_memory = "250Mi"
replicas = 50
#
# Force pods to only run on the nodes that has the label
# "role" and the value "services" (optional).
#
node_selector = {
role = "services"
}
}