skip to Main Content

I have the following two secrets for two different docker registries:

secret1-registry.yaml:

apiVersion: v1
data:
  .dockerconfigjson: somevalue1
kind: Secret
metadata:
  name: metadata1
type: kubernetes.io/dockerconfigjson

secret2-registry.yaml:

apiVersion: v1
data:
  .dockerconfigjson: somevalue2
kind: Secret
metadata:
  name: metadata2
type: kubernetes.io/dockerconfigjson

Is it possible to combine the two secrets?

2

Answers


  1. If you want to manually combine, the .dockerconfigjson field should be a base64-encoded representation of the combined Docker configuration JSON. To create the base64-encoded data, you can use a tool like echo -n ‘<json_data>’ | base64 -w 0.

    apiVersion: v1
    data:
      .dockerconfigjson: combined_base64_encoded_data
    kind: Secret
    metadata:
      name: combined-docker-secrets
    type: kubernetes.io/dockerconfigjson
    
    

    You can also use kubectl commands to create the combined secret. Assuming you have the content of somevalue1 and somevalue2 as actual Docker configuration JSONs.

    # Base64 encode the combined Docker configuration JSON
    combined_data=$(echo -n '{"auths":{"registry1":{"auth":"somevalue1"},"registry2":{"auth":"somevalue2"}}}' | base64 -w 0)
    
    # Create the combined secret
    kubectl create secret generic combined-docker-secrets 
      --from-literal=.dockerconfigjson=$combined_data 
      --type=kubernetes.io/dockerconfigjson
    
    Login or Signup to reply.
  2. Why would you want to combine those secrets? When you specify an imagePullSecret for a Deployment or a similar resource, you can provide a list of imagePullSecrets to use during the container image pull phase.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search