Kubernetes Docker Secret Deployment With Terraform
Deploy a Kubernetes Secret using Terraform to EKS Server
Kubernetes secret can be deployed using Terraform resource kubernetes_secret. Below is a code snippet of the terraform code.
Plain Text
x
1
##### docker-secret.tf #####
2
3
resource "kubernetes_secret" "k8-demo-secret" {
4
metadata {
5
name = lower(var.secret-name)
6
namespace = var.namespace
7
}
8
9
data = {
10
".dockerconfigjson" = file("${var.config-json-path}")
11
}
12
13
type = "kubernetes.io/dockerconfigjson"
14
}
15
16
##### variable.tf #####
17
18
variable "secret-name" {}
19
variable "config-json-path" {}
20
variable "namespace" {}
21
Deployment of kubernetes_secret module:
Plain Text
xxxxxxxxxx
1
1
module "docker-image-secret" {
2
source = "./docker-secret"
3
secret-name = var.docker-secret-name
4
config-json-path = var.docker-config-json-path
5
namespace = var.namespace
6
}
Variables passed to Module:
Plain Text
x
1
docker-secret-name = "docker-image-secret"
2
docker-config-json-path = "./../dockerconfig.json"
3
namespace = "k8-demo-namespace"
Format of dockerconfig.json: Put the username and encrypted password of the Docker repository.
Plain Text
xxxxxxxxxx
1
15
1
{
2
"auths" : {
3
"quay.io" : {
4
"password": "************",
5
"username" : "docker_user"
6
}
7
},
8
"HttpHeaders" : {
9
"User-Agent" : "Docker-Client/19.03.2 (darwin)"
10
},
11
"stackOrchestrator" : "swarm",
12
"experimental" : "disabled",
13
"credsStore" : "desktop"
14
}