This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Add an easy way to create a Docker config Secret for private image pulling #49
Labels
kind/enhancement
Improvements or new features
Comments
Note for the documentation: the configured Pulumi secret named
It took me a while to get this right so please add this to the documentation so other people do not have to waste time too. |
If you created the registry with pulumi (for example on azure) you can use the outputs from the registry object to generate your secret. const registry = new azure.containerservice.Registry(.... Then call the below function as follows const secret = createImagePullSecret(registry.adminUsername,
registry.adminPassword, registry.loginServer, k8sProvider) And to create the secret. export function createImagePullSecret(username: pulumi.Output<string>,
password: pulumi.Output<string>,
registry : pulumi.Output<string>,
k8sProvider : k8s.Provider): k8s.core.v1.Secret {
// Put the username password into dockerconfigjson format.
let base64JsonEncodedCredentials : pulumi.Output<string> =
pulumi.all([username, password, registry])
.apply(([username, password, registry]) => {
const base64Credentials = Buffer.from(username + ':' + password).toString('base64')
const json = `{"auths":{"${registry}":{"auth":"${base64Credentials}"}}}`
console.log(json)
return Buffer.from(json).toString('base64')
})
return new k8s.core.v1.Secret('image-pull-secret', {
metadata: {
name: 'image-pull-secret',
},
type: 'kubernetes.io/dockerconfigjson',
data: {
".dockerconfigjson": base64JsonEncodedCredentials,
},
}, { provider: k8sProvider })
} |
For DigitalOcean: // Private container registry to deploy images into
export const registry = new digitalocean.ContainerRegistry(`container-registry`);
export const registryCreds = pulumi.secret(new digitalocean.ContainerRegistryDockerCredentials("container-registry-creds", { registryName: registry.name }).dockerCredentials);
const registryCredsKubeSecretName = new k8s.core.v1.Secret('registry-creds-secret', {
type: 'kubernetes.io/dockerconfigjson',
data: {
".dockerconfigjson": registryCreds.apply(v => Buffer.from(v).toString('base64')),
},
}, { provider }) |
Thanks @snipebin <3 |
And how do you patch the |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The above snippet is the current way to create a Secret which can be used to pull private Docker images from Docker Hub. Please provide an easier way to create such a secret.
Context:
Issue created on request of @lblackstone
The text was updated successfully, but these errors were encountered: