Kubernetes Docker Secret Deployment With Terraform
Take a look at this series of code snippets that descibes how to deploy a Kubernetes secrets to EKS using Terraform.
Join the DZone community and get the full member experience.
Join For FreeDeploy 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.
x
##### docker-secret.tf #####
resource "kubernetes_secret" "k8-demo-secret" {
metadata {
name = lower(var.secret-name)
namespace = var.namespace
}
data = {
".dockerconfigjson" = file("${var.config-json-path}")
}
type = "kubernetes.io/dockerconfigjson"
}
##### variable.tf #####
variable "secret-name" {}
variable "config-json-path" {}
variable "namespace" {}
Deployment of kubernetes_secret module:
xxxxxxxxxx
module "docker-image-secret" {
source = "./docker-secret"
secret-name = var.docker-secret-name
config-json-path = var.docker-config-json-path
namespace = var.namespace
}
Variables passed to Module:
docker-secret-name = "docker-image-secret"
docker-config-json-path = "./../dockerconfig.json"
namespace = "k8-demo-namespace"
Format of dockerconfig.json: Put the username and encrypted password of the Docker repository.
xxxxxxxxxx
{
"auths" : {
"quay.io" : {
"password": "************",
"username" : "docker_user"
}
},
"HttpHeaders" : {
"User-Agent" : "Docker-Client/19.03.2 (darwin)"
},
"stackOrchestrator" : "swarm",
"experimental" : "disabled",
"credsStore" : "desktop"
}
Opinions expressed by DZone contributors are their own.
Comments