태스크 실행

Kf에서 단기 워크플로를 태스크로 실행하여 단기 워크플로를 실행할 수 있습니다. 태스크는 앱 아래에서 실행되므로 각 태스크에 연결된 앱이 있어야 합니다. 각 태스크 실행은 상위 앱의 빌드 아티팩트를 사용합니다. 태스크는 단기 실행되므로 앱은 장기 실행 애플리케이션으로 배포되지 않으며 앱 또는 태스크에 대한 경로가 생성되면 안 됩니다.

태스크 실행을 위한 앱 푸시

앱 매니페스트 또는 소스 코드의 디렉터리로 이동하여 kf push APP_NAME --task 명령어로 태스크 실행을 위한 앱을 만듭니다. --task 플래그는 앱이 태스크를 실행하기 위해 사용되기 때문에 앱에 경로가 생성되지 않으며 앱이 장기 실행 애플리케이션으로 배포되지 않는다는 점을 나타냅니다.

$ kf push helloworld --task

앱을 나열하여 앱 인스턴스 또는 경로가 생성되지 않았는지 확인합니다.

$ kf apps
Listing Apps in Space: test-space
Name                     Instances  Memory  Disk  CPU   URLs
helloworld               stopped    1Gi     1Gi   100m  <nil>

앱에서 태스크 실행

앱에서 태스크를 실행할 때 선택적으로 --command 플래그를 사용하여 시작 명령어를 지정할 수 있습니다. 시작 명령어가 지정되지 않으면 앱에 지정된 시작 명령어를 사용합니다. 앱에 시작 명령어가 지정되지 않은 경우 컨테이너 이미지의 CMD 구성을 조회합니다. 태스크를 성공적으로 실행하려면 시작 명령어가 있어야 합니다.

$ kf run-task helloworld --command "printenv"
Task helloworld-gd8dv is submitted successfully for execution.

태스크 이름은 Kubernetes API 서버에서 자동으로 생성됩니다. 앱 이름이 프리픽스로 추가되고 임의 문자열이 서픽스로 추가됩니다. 태스크 이름은 동일한 클러스터 내의 태스크에 대한 고유 식별자입니다.

태스크 리소스 한도 지정

리소스 제한(예: CPU 코어/메모리 한도/디스크 할당량)은 앱(kf push 시)에 지정하거나 kf run-task 명령어 도중에 지정할 수 있습니다. kf run-task 명령어에 지정된 한도는 앱에 지정된 한도보다 우선합니다.

앱에서 리소스 제한을 지정하려면 kf push 명령어에 --cpu-cores, --memory-limit, --disk-quota 플래그를 사용하면 됩니다.

$ kf push helloworld --command "printenv" --cpu-cores=0.5 --memory-limit=2G --disk-quota=5G --task

앱에서 이러한 한도를 재정의하려면 kf run-task 명령어에 --cpu-cores, --memory-limit, --disk-quota 플래그를 사용하면 됩니다.

$ kf run-task helloworld --command "printenv" --cpu-cores=0.5 --memory-limit=2G --disk-quota=5G

태스크의 커스텀 표시 이름 지정

필요에 따라 --name 플래그를 사용하여 태스크의 커스텀 표시 이름을 지정하면 쉽게 식별/그룹화될 수 있습니다.

$ kf run-task helloworld --command "printenv" --name foo
Task helloworld-6swct is submitted successfully for execution.

$ kf tasks helloworld
Listing Tasks in Space: test space
Name              ID  DisplayName        Age    Duration  Succeeded  Reason
helloworld-6swct  3   foo                1m     21s       True       <nil>

태스크 관리

kf tasks APP_NAME 명령어로 앱의 모든 태스크 보기

$ kf tasks helloworld
Listing Tasks in Space: test space
Name              ID  DisplayName        Age    Duration  Succeeded  Reason
helloworld-gd8dv  1   helloworld-gd8dv   1m     21s       True       <nil>

태스크 취소

kf terminate-task 명령어를 사용하여 활성 태스크를 취소합니다.

태스크 이름으로 태스크를 취소합니다.

$ kf terminate-task helloworld-6w6mz
Task "helloworld-6w6mz" is successfully submitted for termination

또는 APP_NAME + 태스크 ID로 태스크를 취소합니다.

$ kf terminate-task helloworld 2
Task "helloworld-6w6mz" is successfully submitted for termination
  • 참고: 대기 중이거나 실행 중인 태스크만 취소할 수 있으며 완료된 태스크는 취소할 수 없습니다.

취소된 태스크는 PipelineRunCancelled 상태를 가집니다.

$ kf tasks helloworld
Listing Tasks in Space: test space
Name              ID  DisplayName        Age    Duration  Succeeded  Reason
helloworld-gd8dv  1   helloworld-gd8dv   1m     21s       True       <nil>
helloworld-6w6mz  2   helloworld-6w6mz   38s    11s       False      PipelineRunCancelled

태스크 로그 보기

kf logs APP_NAME --task 명령어를 사용하여 태스크 로그를 봅니다.

$ kf logs helloworld --task