Created
April 6, 2022 16:14
-
-
Save oguzhalit/859dce0fb7ec253642c074fed10d67f5 to your computer and use it in GitHub Desktop.
Example Docker Secret K8S with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import json | |
from kubernetes import client, config | |
config.load_kube_config() | |
v1 = client.CoreV1Api() | |
cred_payload = { | |
"auths": { | |
"DOCKER-SERVER": { | |
"Username": "DOCKER-USERNAME", | |
"Password": "DOCKER-PASSWORD", | |
"Email": "DOCKER-EMAIL", | |
} | |
} | |
} | |
data = { | |
".dockerconfigjson": base64.b64encode( | |
json.dumps(cred_payload).encode() | |
).decode() | |
} | |
secret = client.V1Secret( | |
api_version="v1", | |
data=data, | |
kind="Secret", | |
metadata=dict(name="NAME", namespace="NAMESPACE"), | |
type="kubernetes.io/dockerconfigjson", | |
) | |
v1.create_namespaced_secret("NAMESPACE", body=secret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment