Skip to content

Instantly share code, notes, and snippets.

@agu3rra
Created September 17, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agu3rra/03349647142591988a46026dbc3dedaf to your computer and use it in GitHub Desktop.
Save agu3rra/03349647142591988a46026dbc3dedaf to your computer and use it in GitHub Desktop.
Quick snippet to convert values into base64 encoding for usage with Kubernetes secrets.yml files
import yaml
import base64
# Assumes sample.yml will have a data: entry
if __name__ == '__main__':
with open('sample.yml', 'r') as fh:
stream = fh.read()
data = yaml.safe_load(stream)
for key, value in data['data'].items():
encoded = base64.b64encode(str(value).encode('utf-8')).decode('utf-8')
print(f"{key}: {encoded}")
@agu3rra
Copy link
Author

agu3rra commented Sep 17, 2020

Sample yml:

apiVersion: v1
data:
  SECRET1: supersecret123
  SECRET2: topsecrethere
kind: Secret
metadata:
  name: deploymentSecrets
  namespace: myspace
type: Opaque

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment