DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Auto-Scaling a Spring Boot Native App With Nomad
  • Full Stack Kubernetes with Kong Ingress Controller
  • Kubernetes for Java Developers
  • Smart Deployment Strategies for Modern Applications

Trending

  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal
  • Spring Boot Done Right: Lessons From a 400-Module Codebase
  • How Reactive Scaling Drains Your Cloud Budget Without Warning
  • Top JavaScript/TypeScript Gen AI Frameworks for 2026
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Docker Secret Deployment With Terraform

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.

By 
Shipra Garg user avatar
Shipra Garg
·
Sep. 23, 20 · Code Snippet
Likes (2)
Comment
Save
Tweet
Share
4.8K Views

Join the DZone community and get the full member experience.

Join For Free

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
}
14
}



Kubernetes Terraform (software) Plain text Docker (software)

Opinions expressed by DZone contributors are their own.

Related

  • Auto-Scaling a Spring Boot Native App With Nomad
  • Full Stack Kubernetes with Kong Ingress Controller
  • Kubernetes for Java Developers
  • Smart Deployment Strategies for Modern Applications

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook