Post

Kubeflow for ML - Chapter 2





Chapter 2: Hello Kubeflow

๐Ÿ‘€ ๋ณธ ํฌ์ŠคํŠธ๋Š” Kubeflow for Machine Learning ์ฑ…์„ ๋ฐœ์ทŒ/์š”์•ฝํ•˜๋ฉด์„œ ํ•„์š”ํ•œ ๋‚ด์šฉ์€ ์ถ”๊ฐ€ํ•˜์—ฌ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Introduction

์›๋ž˜ ์ฑ…์˜ ๋ณธ ์žฅ์€ kubectl๊ณผ kfctl ์„ ์ด์šฉํ•˜์—ฌ Kubeflow๋ฅผ ์„ค์น˜ํ•˜๋Š” ๋‚ด์šฉ์„ ๋‹ค๋ฃจ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ฒ˜์Œ ๊ณต๋ถ€ํ•˜๋Š” ์ž…์žฅ์—์„œ ์ฑ…์˜ ๋‚ด์šฉ์„ ๋”ฐ๋ผ๊ฐ€๊ณ  ์žˆ์—ˆ๋Š”๋ฐ kubeflow/kfctl ์ €์žฅ์†Œ๊ฐ€ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ณด๊ณ  ์กฐ๊ธˆ ์˜์•„ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ €์žฅ์†Œ์˜ ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹์ด 2021๋…„ 3์›” 16์ผ์ด๊ณ  ๊ด€๋ฆฌ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋˜๊ณ  ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋Š” ์ฐพ์•„๋ณผ ์ˆ˜ ์—†์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋˜ ์ค‘ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์Šˆ๊ฐ€ ๋“ฑ๋ก๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ๋Š”๋ฐ์š”.

Example
kfctl is deprecated... ๐Ÿ’€

๋‚ด์šฉ์ธ ์ฆ‰ Kubeflow 1.3 ์ดํ›„ ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” ๋ชจ๋‘ kustomize๋ฅผ ์ด์šฉํ•ด์„œ๋งŒ ๋ฐฐํฌ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํ˜„์žฌ ์ปค๋ฎค๋‹ˆํ‹ฐ ๋‚ด์— kfctl์„ ์ง€์›ํ•˜๊ฑฐ๋‚˜ ๊ฐœ๋ฐœํ•˜๋Š” ์ธ์›์ด ์ „๋ฌดํ•˜๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ œ๋Š” kfctl์„ ์•„์˜ˆ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ๋„ ์•„๋‹ˆ๊ณ  ์ผ๋ถ€ ์ปดํฌ๋„ŒํŠธ์—์„œ๋Š” ์•„์ง kfctl์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์—ฌ ๊ฒฐ๊ตญ ์„ค์น˜๋Š” ํ•ด์•ผํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋ณธ ํฌ์ŠคํŠธ์—์„œ๋Š” ์ฑ…์˜ ์„ค์น˜ ๋‚ด์šฉ์„ ๋”ฐ๋ผ๊ฐ€์ง€ ์•Š๊ณ  Kubeflow ์ตœ์‹  ๋ฒ„์ „์„ Manifest๋ฅผ ์ด์šฉํ•ด ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณ„๋„๋กœ ๋‹ค๋ฃจ๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

How to install Kubeflow?

ํ•˜๋‚˜ ์•Œ์•„๋‘์…”์•ผ ํ•  ๋‚ด์šฉ์€ ์•„๋ž˜ ์„ค์น˜ ๋ฐฉ๋ฒ•์€ M1 Mac์ด ์•„๋‹Œ Intel Mac์—์„œ๋งŒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ OS๋‚˜ ํ™˜๊ฒฝ์—์„œ๋Š” ์„ค์น˜ ๋ฐฉ๋ฒ•์ด ๋‹ค๋ฅผํ…Œ๋‹ˆ ๊ด€๋ จ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์—ฌ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. Kubeflow๋Š” ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ์„ค์น˜ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

Install Minikube

Homebrew๋ฅผ ์ด์šฉํ•ด์„œ Minikube๋ฅผ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค.

1
brew install minikube

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋œ ํ›„ ๋ฒ„์ „ ํ™•์ธ์„ ํ•ด์ค๋‹ˆ๋‹ค.

1
2
3
> minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7

Install Kubernetes

์ด์ œ Minikube์—์„œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ์„ค์น˜ํ• ํ…๋ฐ ๋ฒ„์ „ ์„ ํƒ์— ์ฃผ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Kubeflow Manifest ์ €์žฅ์†Œ์—์„œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค 1.22 ์ด์ƒ ๋ฒ„์ „๊ณผ๋Š” ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์–ด ์„ค์น˜์— ์ฃผ์˜๋ฅผ ์š”ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋กœ M1 ๋งฅ์—์„œ๋Š” Minikube ๋“œ๋ผ์ด๋ฒ„๋ฅผ ๋ฐ˜๋“œ์‹œ Docker๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŠธ๋Š” Intel Mac์—์„œ ๊ฐ€๋Šฅํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ M1์ด๋ฉด์„œ Docker๊ฐ€ ์„ค์น˜๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๊ด€๋ จ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์—ฌ Docker๋ฅผ ์„ค์น˜ ๋ฐ ์„ค์ • ํ›„ Kuberntetes๋ฅผ ์„ค์น˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๐Ÿ’ก M1์œผ๋กœ Minikube๋ฅผ ์ด์šฉํ•ด Kubeflow ์„ค์น˜๊ฐ€ ์•ˆ๋˜๋Š” ์ด์œ ๋Š” Kubeflow์˜ ์ปดํฌ๋„ŒํŠธ ์ค‘ Istio๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ํ™•์ธ ๊ฒฐ๊ณผ ํ˜„์žฌ Istio๋Š” ๊ณต์‹์ ์œผ๋กœ M1 Mac (arm64)๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌธ์ œ๊ฐ€ ์—†์œผ๋‚˜ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ปดํฌ๋„ŒํŠธ ์ค‘ ํ•˜๋‚˜์ธ Istio๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์„ค์น˜์™€ ์‚ฌ์šฉ์— ์–ด๋ ค์›€์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋ฐ˜๋“œ์‹œ M1 Mac์„ ํ†ตํ•ด Kubeflow๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค๋ฉด ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ด์šฉํ•ด Linux ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•˜์—ฌ ์„ค์น˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
> minikube start --driver=hyperkit --kubernetes-version=1.21.12 --memory=8g โ€”cpus=4 --profile kf
๐Ÿ˜„  [kf] Darwin 12.3.1 (arm64) ์˜ minikube v1.25.2
โœจ  ์œ ์ € ํ™˜๊ฒฝ ์„ค์ • ์ •๋ณด์— ๊ธฐ๋ฐ˜ํ•˜์—ฌ docker ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ค‘
๐Ÿ‘  kf ํด๋Ÿฌ์Šคํ„ฐ์˜ kf ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ ๋…ธ๋“œ๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ์ค‘
๐Ÿšœ  ๋ฒ ์ด์Šค ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋ฐ›๋Š” ์ค‘ ...
    > gcr.io/k8s-minikube/kicbase: 343.11 MiB / 343.12 MiB  100.00% 11.41 MiB p
๐Ÿ”ฅ  Creating docker container (CPUs=4, Memory=8192MB) ...
๐Ÿณ  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค v1.21.12 ์„ Docker 20.10.12 ๋Ÿฐํƒ€์ž„์œผ๋กœ ์„ค์น˜ํ•˜๋Š” ์ค‘
    โ–ช kubelet.housekeeping-interval=5m
    > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 41.31 MiB / 41.31 MiB [-------------] 100.00% 19.68 MiB p/s 2.3s
    > kubeadm: 39.56 MiB / 39.56 MiB [-------------] 100.00% 12.83 MiB p/s 3.3s
    > kubelet: 104.79 MiB / 104.79 MiB [-----------] 100.00% 31.86 MiB p/s 3.5s
    โ–ช ์ธ์ฆ์„œ ๋ฐ ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ค‘ ...
    โ–ช ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ์ด ๋ถ€ํŒ…...
    โ–ช RBAC ๊ทœ์น™์„ ๊ตฌ์„ฑํ•˜๋Š” ์ค‘ ...
๐Ÿ”Ž  Kubernetes ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ํ™•์ธ...
    โ–ช Using image gcr.io/k8s-minikube/storage-provisioner:v5
๐ŸŒŸ  ์• ๋“œ์˜จ ํ™œ์„ฑํ™” : storage-provisioner, default-storageclass
๐Ÿ„  ๋๋‚ฌ์Šต๋‹ˆ๋‹ค! kubectl์ด "kf" ํด๋Ÿฌ์Šคํ„ฐ์™€ "default" ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋„๋ก ๊ตฌ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์„œ ๋งŒ์•ฝ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์›ํ•˜๋Š” ์„ค์ • (4๊ฐœ์˜ CPU, 8GB์˜ ๋ฉ”๋ชจ๋ฆฌ)์œผ๋กœ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์‚ญ์ œํ•œ ๋‹ค์Œ Minikube์˜ ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•œ ๋‹ค์Œ ์žฌ์ƒ์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

1
2
3
4
5
6
# Minikube ์‚ญ์ œ
minikube delete -p kf

# Minikube ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
minikube config set cpus 4
minikube config set memory 8192

์˜ฌ๋ฐ”๋ฅด๊ฒŒ ํ”„๋กœํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

1
2
3
4
5
6
7
> minikube profile list

|---------|-----------|---------|--------------|------|----------|---------|-------|
| Profile | VM Driver | Runtime |      IP      | Port | Version  | Status  | Nodes |
|---------|-----------|---------|--------------|------|----------|---------|-------|
| kf  | docker    | docker  | XXX.XXX.XX.X | XXXX | v1.21.12 | Running |     1 |
|---------|-----------|---------|--------------|------|----------|---------|-------|

Install Kustomize

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํŒจํ‚ค์ง• ๋งค๋‹ˆ์ง€ ํˆด์ธ Kustomize๋„ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค. ์ด ์—ญ์‹œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์ฒ˜๋Ÿผ ๋ฒ„์ „ ์ œ์•ฝ ์‚ฌํ•ญ์ด ์žˆ์—ˆ๋Š”๋ฐ์š”. ์ตœ๊ทผ ๋ฒ„์ „์ธ 4.X ๋ฒ„์ „๊ณผ๋Š” ํ˜ธํ™˜์ด ๋˜์ง€ ์•Š์•„ ๊ทธ๋ณด๋‹ค ๋‚ฎ์€ ๋ฒ„์ „์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. 3.2.0 ๋ฒ„์ „ ์„ค์น˜๋ฅผ ๊ถŒ์žฅํ•˜๋Š”๋ฐ ์ง€๊ธˆ Kustomize 3.10.0 ๋ฒ„์ „๊นŒ์ง€ ๋‚˜์™€ ์žˆ์–ด ์ €๋Š” ๊ทธ๋ƒฅ 3.10.0 ๋ฒ„์ „์„ ์„ค์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์šด๋กœ๋“œ ํŽ˜์ด์ง€์—์„œ OS์— ๋งž๋Š” ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์Šต๋‹ˆ๋‹ค.

1
wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.10.0/kustomize_v3.10.0_darwin_amd64.tar.gz

๊ทธ ๋‹ค์Œ ์••์ถ•์„ ํ’€๊ณ  ํŒŒ์ผ์„ PATH ๊ฒฝ๋กœ์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.

1
2
tar -zxvf kustomize_v3.10.0_darwin_amd64.tar.gz
sudo mv kustomize /usr/local/bin/kustomize

๋งˆ์ง€๋ง‰์œผ๋กœ ์„ค์น˜ ํ™•์ธ์„ ํ•ฉ๋‹ˆ๋‹ค.

1
2
3
> kustomize version

{Version:kustomize/v3.10.0 GitCommit:602ad8aa98e2e17f6c9119e027a09757e63c8bec BuildDate:2021-02-10T00:00:50Z GoOs:darwin GoArch:amd64}

Install Kubeflow

์—ฌ๊ธฐ๊นŒ์ง€ ๋˜์—ˆ๋‹ค๋ฉด Kubeflow๋ฅผ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ์„  Kubeflow Manifests ์ €์žฅ์†Œ์—์„œ ์ตœ์‹  ๋ฒ„์ „ ์†Œ์Šค๋ฅผ ๋ณต์‚ฌํ•ด์˜ต๋‹ˆ๋‹ค.

1
git clone https://github.com/kubeflow/manifests.git

๊ทธ ๋‹ค์Œ Kubeflow๋ฅผ ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

1
2
cd manifests
while ! kustomize build example | minikube -p=kf kubectl -- apply -f -; do echo "Retrying to apply resources"; sleep 10; done

์ €์žฅ์†Œ ๋‚ด์˜ ์„ค์น˜ ๋ช…๋ น์–ด์™€ ๋‹ค๋ฅธ ์ ์€ minikube -p=kf ๋กœ kubectl ์•ž์— ๋‹ค๋ฅธ ๊ฒƒ์ด ๋ถ™์—ฌ์ ธ ์žˆ๋Š” ๊ฒƒ์ธ๋ฐ์š”. ์šฐ๋ฆฌ๋Š” Minikube๋ฅผ ์ด์šฉํ•ด ์„ค์น˜ํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ Minikube ๋‚ด์˜ kubectl ์„ ์ด์šฉํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ„ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์„ค์น˜๋ฅผ ์™„๋ฃŒํ•˜๊ณ  Kubeflow์˜ Pod๋“ค์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๊ธฐ๋™๋˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

1
minikube -p=kf kubectl -- get pods -A

๋ชจ๋“  Pod์ด Running์ธ ๊ฒƒ์„ ํ™•์ธํ•˜์—ฌ ์„ค์น˜๋ฅผ ์™„๋ฃŒํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.



This post is licensed under CC BY 4.0 by the author.