Python: how to create a docker-registry kind of secret?

Created on 4 Apr 2018  路  6Comments  路  Source: kubernetes-client/python

The example at https://github.com/kubernetes-client/python/blob/master/examples/notebooks/create_secret.ipynb shows how to create generic secrets...

How to create a docker-registry secret?

lifecyclstale

Most helpful comment

Hi @adityabyreddy74 and @marcellodesales, I recently ran into this problem and the following works for me (replacing all relevant capitalized fields):

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)

All 6 comments

Any update on this?

Hi @adityabyreddy74 and @marcellodesales, I recently ran into this problem and the following works for me (replacing all relevant capitalized fields):

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)

@cicdw Yup. I followed the same solution :). Thanks.

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/close

@adityabyreddy74: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Was this page helpful?
0 / 5 - 0 ratings