dockerkubeflowkubeflow-pipelines

How to connect a secret containing Docker registry credentials to a Kubeflow pipeline for accessing a base image from a private docker hub repository?


I'm using a Docker image that I've pushed to a Docker hub public repository as the base_image for a Kubeflow component: subtract_op = create_component_from_func(func=subtract, base_image="<my public image>/<tag>:latest")

Now, I'm looking to transition to using a Docker hub private repository. I've already set up a secret containing the authentication details for the private repository using the following command in the Jupyter terminal: kubectl create secret docker-registry regcred --docker-server=docker.io --docker-username=<my username> --docker-password=<my password> --docker-email=<my email> --namespace=<namespace>

I'm a bit uncertain about the next steps to connect this secret to the pipeline so that it can access the base_image corresponding to the private repository.

Current code:

...
def subtract(a: float, b: float) -> float:
    '''Calculates sum of two arguments'''
    from my_library import subtract
    result = subtract(a,b)
    return result

subtract_op = create_component_from_func(func=subtract, base_image=<my private image>)

import kfp.dsl as dsl
@dsl.pipeline(
  name='Subtraction pipeline',
  description='An example pipeline that performs subtractions calculations.'
)
def subtraction_pipeline(
  a='1',
  b='7',
):
    first_add_task = subtract_op(a, 4)
    second_add_task = subtract_op(first_add_task.output, b)

arguments = {'a': '7', 'b': '8'}

kfp_client.create_run_from_pipeline_func(subtraction_pipeline, arguments=arguments)

So far I tried to connect the secret to the container operation but I haven't found a way of connecting it to Kubeflow yet. I'm using KFP library version: 1.8.13 on JupyterLab.


Solution

  • I have found a solution using PipelineConf with the image_pull_secrets parameter (documentation here: https://kfp.readthedocs.io/en/stable/_modules/kfp/dsl/_pipeline.html)

    Here is what I added to my code to pull the secret (private docker hub repo credentials) and access the private docker image:

    from kfp.dsl import PipelineConf
    from kubernetes.client.models import V1LocalObjectReference
            
    pipeline_conf = PipelineConf()
    pipeline_conf.set_image_pull_secrets(
        [V1LocalObjectReference(name='regcred')]
    )
    
    kfp_client.create_run_from_pipeline_func(substract_pipeline, arguments=arguments, pipeline_conf=pipeline_conf)