Hi there,
In a classic Kubernetes I was able to create a Deployment with many containers. Like:
...
apiVersion: apps/v1
kind: Deployment
....
containers:
- image: EXPAMPLE_IMAGE
name: example-1
imagePullPolicy: Always
env:
- name: APP_CURRENT_VERSION
value: "v1.02.00"
volumeMounts:
- name: shared-files
mountPath: /var/www/html
- image: EXAMPLE_IMAGE_2
name: nginx
imagePullPolicy: Always
volumeMounts:
- name: shared-files
mountPath: /var/www/html
...
But in a terraform documentation I don’t see an option containers in deployment, only a container option exist:
https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment#container
Also I trying to use the terraform console util for generate from yaml deployment file to tf deployment file like:
echo 'yamldecode(file("app7nginx-deployment.yaml"))' | terraform console
In generated code I find an option “containers”:
"spec" = {
"containers" = [
{
But when I trying to apply this an option in my deployment I get an error:
30: containers = [
│
│ An argument named "containers" is not expected here.
My a deployment looks like this:
resource "kubernetes_deployment" "example-static-deployment" {
metadata {
name = "example-static-deployment"
namespace = kubernetes_namespace.main.metadata.0.name
}
spec {
replicas = 1
selector {
match_labels = {
app = "${var.app_namespace}-example-static-deployment"
}
}
template {
metadata {
labels = {
app = "${var.app_namespace}-example-static-deployment"
}
}
spec {
image_pull_secrets {
name = kubernetes_secret.secret_docker_cfg.metadata.0.name
}
hostname = "example-static-deployment"
volume {
name = "share-disk"
empty_dir = {}
}
containers = [
{
image = "EXAMPLE-IMAGE-1"
name = "example-1"
port {
container_port = "8080"
}
volume_mount {
mount_path = "/app/dist/storage"
name = "share-disk"
}
env {
name = "NODE_ENV"
value = "${var.NODE_ENV}"
}
env {
name = "DB_HOSTNAME"
value = "${var.DB_HOSTNAME}"
}
env {
name = "DB_NAME"
value = "${var.DB_NAME}"
}
env {
name = "DB_USERNAME"
value = "${var.DB_USERNAME}"
}
env {
name = "DB_PASSWORD"
value = "${var.DB_PASSWORD}"
}
env {
name = "DB_TYPE"
value = "${var.DB_TYPE}"
}
},
{
image = "nginx"
name = "example-2"
port {
container_port = "80"
}
volume_mount {
mount_path = "/usr/share/nginx/html"
name = "share-disk"
}
}
]
}
}
}
}