elotl / kip

Virtual-kubelet provider running pods in cloud instances
Apache License 2.0
223 stars 14 forks source link

fix up using imagePullSecrets in kip, be able to use dockerconfigjson #98

Closed justnoise closed 4 years ago

justnoise commented 4 years ago

K8s docs for image pull specs are here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

This is a first pass at being able to use image pull secrets created with kubectl. It's not perfect (I think docker's config.json allows you to specify different creds for the same repo URL at different paths) but it's a decent start.

Creating docker secrets:

$ kubectl create secret docker-registry regcred \
    --docker-server=<server> \
    --docker-username=<username> \
    --docker-password=<password> \
    --docker-email=<docker-email>

$kubectl create secret generic file-regcred \ 
    --from-file=.dockerconfigjson=/home/myuser/.docker/config.json \
    --type=kubernetes.io/dockerconfigjson

The first case creates a secret detailed here: https://github.com/elotl/kip/issues/96 The second case creates a secret with the entire contents of /home/myuser/.docker/config.json base64 encoded. For that case, the docker server can either be a hostname (e.g. 689494258501.dkr.ecr.us-east-1.amazonaws.com) or a full url (https://index.docker.io/v1/).

This PR tries to understand both formats do work to extract the correct server credentials, either from the username and password fields or falling back to the auth field. It's possible we could just use the auth field... I'm unsure if we should be defensive or make that simplification.