The Wayback Machine - https://web.archive.org/web/20240118173408/https://www.geeksforgeeks.org/kubernetes-working-with-secrets/
Open In App
Related Articles

Kubernetes – Working With Secrets

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Kubernetes Secrets are objects that are used to store secret data in base64 encoded format. Using secrets enables developers not to put confidential information in the application code.  Since Secrets are created independently of the pods, there is less risk of secrets being exposed.

Uses of Secrets: 

  • As files in a volume mounted on one or more of its containers.
  • As container environment variable.
  • By the kubelet when pulling images for the Pod.

Creating a Secret:

$ kubectl create secret generic [secret-name] \  
--from-file=[key1]=[file1] \  
--from-file=[key2]=[file2]
creating secret

 

Decoding Secret:

$ kubectl get secret [secret] -o jsonpath='{.data}'
encoded key-value pairs.

 

The above output shows encoded key-value pairs.

Decode them using echo and pipe the output to base64

$ echo '[encoded-value]' | base64 --decode
 decoded password.

 

The above output is the decoded password.

Editing Secret:

$ kubectl edit secrets <secret-name>
edit secret

 

The config file during editing would look like this:

config file

 

Deleting Secret:

$ kubectl delete secret <secret-name>
deleting secret

 

Lost in the complex landscape of DevOps? It's time to find your way! Enroll in our DevOps Engineering Planning to Production Live Course and set out on an exhilarating expedition to conquer DevOps methodologies with precision and timeliness.
What We Offer:
  • Comprehensive DevOps Curriculum
  • Expert Guidance for Streamlined Learning
  • Hands-on Experience with Real-world Scenarios
  • Proven Track Record with 100,000+ Successful DevOps Enthusiasts

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 30 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials