본문 바로가기
machine learning

kfp image policy 정의하기

by 유주원 2023. 1. 16.

2022.12.29 - [machine learning] - Kubeflow pipeline 작성 및 pvc에 저장하기

 

kfp로 pipeline을 작성하고 실행하다 보면 image tag가 같은 경우 새로 이미지를 pull 받지 않고 기존 컨테이너를 활용하는 것을 확인 할 수가 있다. 해당 기능이 어떤 점에서는 편할 수 있지만 동작 시 혼란을 야기할 수 있기 때문에 kfp 정의 시 image policy를 정의해 주도록 하자.

 

def train_op():
    op = dsl.ContainerOp(
        name='Test',
        image='test:test01'
    )

    op.set_image_pull_policy("IfNotPresent")
    
    return op.apply(onprem.mount_pvc(pvc_name='pvc-test', volume_name='test', volume_mount_path='/test'))

 

op.set_image_pull_policy 함수를 통해 이미지 정책을 정의해 줄 수 있다.

파라미터는 string 값을 받으며, "IfNotPresent", "Always", "Never" 이렇게 3개의 값을 사용할 수 있다.

 

https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.dsl.html

 

kfp.dsl package — Kubeflow Pipelines documentation

ValueError – if k8s_resource is provided along with other arguments if k8s_resource is not a VolumeSnapshot if pvc and volume are None if pvc and volume are not None if volume does not reference a PVC

kubeflow-pipelines.readthedocs.io

 

위 함수 적용후 생성된 yaml 값을 보면 아래와 같이 image policy가 설정되어 있는 것을 확인할 수가 있다.

 

- name: Test  
  container:
    image: test:test01
    imagePullPolicy: IfNotPresent