Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kubernetes Terraform App Deployment Brief Example
resource kubernetes_namespace deployment {
metadata {
name = var.namespace
}
}
// Example Secrets to expose as env vars in deployment
resource kubernetes_secret appsecrets {
metadata {
name = "appsecrets"
namespace = kubernetes_namespace.deployment.metadata.0.name
}
type = "Opaque"
data = {
ACCOUNT_KEY = var.account_key
}
}
// Example configmap settings to expose as env vars in deployment
resource kubernetes_config_map settings {
metadata {
name = "appconfig"
namespace = kubernetes_namespace.deployment.metadata.0.name
}
data = {
SOMEPATH = "/root/why/is/this/parameterized"
APPNAMESPACE = kubernetes_namespace.deployment.metadata.0.name
CLOUDSERVICE = "Azure"
ACCOUNTNAME = var.account_name
APPNAME = var.kubernetes_app_name
}
}
resource kubernetes_deployment app {
metadata {
name = var.kubernetes_app_name
namespace = kubernetes_namespace.deployment.metadata.0.name
labels = {
app = var.kubernetes_app_name
}
}
spec {
replicas = 1
selector {
match_labels = {
app = var.kubernetes_app_name
}
}
template {
metadata {
labels = {
app = var.kubernetes_app_name
}
}
spec {
container {
name = var.kubernetes_app_name
image = "${var.container_registry}/${var.image}:${var.image_tag}"
command = var.container_command
// This is a configmap to envvar setup
env_from {
config_map_ref {
name = kubernetes_config_map.settings.metadata.0.name
}
}
// And a secret to envvar setup
env {
name = "ACCOUNT_KEY"
value_from {
secret_key_ref {
name = kubernetes_secret.appsecrets.metadata.0.name
key = "ACCOUNT_KEY"
}
}
}
resources {
requests {
memory = var.kubernetes_pod_memory
}
}
termination_message_path = "/dev/termination-log"
image_pull_policy = "Always"
}
restart_policy = "Always"
termination_grace_period_seconds = 30
dns_policy = "ClusterFirst"
}
}
strategy {
type = "RollingUpdate"
rolling_update {
max_unavailable = "1"
max_surge = "1"
}
}
revision_history_limit = 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment