Skip to content

Instantly share code, notes, and snippets.

@oguzhalit
Created April 6, 2022 16:14
Show Gist options
  • Save oguzhalit/859dce0fb7ec253642c074fed10d67f5 to your computer and use it in GitHub Desktop.
Save oguzhalit/859dce0fb7ec253642c074fed10d67f5 to your computer and use it in GitHub Desktop.
Example Docker Secret K8S with Python
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