|
| 1 | +# Kubeflow demo - Simple pipeline |
| 2 | + |
| 3 | +This repository contains a demonstration of Kubeflow capabilities, suitable for |
| 4 | +presentation to public audiences. |
| 5 | + |
| 6 | +The base demo includes the following steps: |
| 7 | + |
| 8 | +1. [Setup your environment](#1-setup-your-environment) |
| 9 | +1. [Create a GKE cluster and install Kubeflow](#2-create-a-gke-cluster-and-install-kubeflow) |
| 10 | +1. [Install pipelines on GKE](#3-install-pipelines-on-gke) |
| 11 | + |
| 12 | +## 1. Setup your environment |
| 13 | + |
| 14 | +Clone the [kubeflow/kubeflow](https://github.com/kubeflow/kubeflow) repo and |
| 15 | +checkout the |
| 16 | +[`v0.3.3`](https://github.com/kubeflow/kubeflow/releases/tag/v0.3.3) branch. |
| 17 | +Clone the [kubeflow/pipelines](https://github.com/kubeflow/pipelines) repo and |
| 18 | +checkout the |
| 19 | +[`0.1.2`](https://github.com/kubeflow/pipelines/releases/tag/0.1.2) branch. |
| 20 | + |
| 21 | +Ensure that the repo paths, project name, and other variables are set correctly. |
| 22 | +When all overrides are set, source the environment file: |
| 23 | + |
| 24 | +``` |
| 25 | +source kubeflow-demo-simple-pipeline.env |
| 26 | +``` |
| 27 | + |
| 28 | +Create a clean python environment for installing Kubeflow Pipelines: |
| 29 | + |
| 30 | +``` |
| 31 | +conda create --name kfp python=3.6 |
| 32 | +source activate kfp |
| 33 | +``` |
| 34 | + |
| 35 | +Install the Kubeflow Pipelines SDK: |
| 36 | + |
| 37 | +``` |
| 38 | +pip install https://storage.googleapis.com/ml-pipeline/release/0.1.2/kfp.tar.gz --upgrade |
| 39 | +``` |
| 40 | + |
| 41 | +## 2. Create a GKE cluster and install Kubeflow |
| 42 | + |
| 43 | +Creating a cluster with click-to-deploy does not yet support the installation of |
| 44 | +pipelines. It is not useful for demonstrating pipelines, but is still worth showing. |
| 45 | + |
| 46 | +### Click-to-deploy |
| 47 | + |
| 48 | +Generate a web app Client ID and Client Secret by following the instructions |
| 49 | +[here](https://www.kubeflow.org/docs/started/getting-started-gke/#create-oauth-client-credentials). |
| 50 | +Save these as environment variables for easy access. |
| 51 | + |
| 52 | +In the browser, navigate to the |
| 53 | +[Click-to-deploy app](https://deploy.kubeflow.cloud/). Enter the project name, |
| 54 | +along with the Client ID and Client Secret previously generated. Select the |
| 55 | +desired ${ZONE} and latest version of Kubeflow, then click _Create Deployment_. |
| 56 | + |
| 57 | +In the [GCP Console](https://console.cloud.google.com/kubernetes), navigate to the |
| 58 | +Kubernetes Engine panel to watch the cluster creation process. This results in a |
| 59 | +full cluster with Kubeflow installed. |
| 60 | + |
| 61 | +### kfctl |
| 62 | + |
| 63 | +While node autoprovisioning is in beta, it must be enabled manually. To create |
| 64 | +a cluster with autoprovisioning, run the following commands, which will take |
| 65 | +around 30 minutes: |
| 66 | + |
| 67 | +``` |
| 68 | +gcloud container clusters create ${CLUSTER} \ |
| 69 | + --project ${DEMO_PROJECT} \ |
| 70 | + --zone ${ZONE} \ |
| 71 | + --cluster-version 1.11.2-gke.9 \ |
| 72 | + --num-nodes=8 \ |
| 73 | + --scopes cloud-platform,compute-rw,storage-rw \ |
| 74 | + --verbosity error |
| 75 | +
|
| 76 | +# scale down cluster to 3 (initial 8 is just to prevent master restarts due to upscaling) |
| 77 | +# we cannot use 0 because then cluster autoscaler treats the cluster as unhealthy. |
| 78 | +# Also having a few small non-gpu nodes is needed to handle system pods |
| 79 | +gcloud container clusters resize ${CLUSTER} \ |
| 80 | + --project ${DEMO_PROJECT} \ |
| 81 | + --zone ${ZONE} \ |
| 82 | + --size=3 \ |
| 83 | + --node-pool=default-pool |
| 84 | +
|
| 85 | +# enable node auto provisioning |
| 86 | +gcloud beta container clusters update ${CLUSTER} \ |
| 87 | + --project ${DEMO_PROJECT} \ |
| 88 | + --zone ${ZONE} \ |
| 89 | + --enable-autoprovisioning \ |
| 90 | + --max-cpu 20 \ |
| 91 | + --max-memory 200 \ |
| 92 | + --max-accelerator=type=nvidia-tesla-k80,count=8 |
| 93 | +``` |
| 94 | + |
| 95 | +Once the cluster has been created, install GPU drivers: |
| 96 | + |
| 97 | +``` |
| 98 | +kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/master/daemonset.yaml |
| 99 | +``` |
| 100 | + |
| 101 | +Add RBAC permissions, which allows your user to install kubeflow components on |
| 102 | +the cluster: |
| 103 | + |
| 104 | +``` |
| 105 | +kubectl create clusterrolebinding cluster-admin-binding-${USER} \ |
| 106 | + --clusterrole cluster-admin \ |
| 107 | + --user $(gcloud config get-value account) |
| 108 | +``` |
| 109 | + |
| 110 | +Setup kubectl access: |
| 111 | + |
| 112 | +``` |
| 113 | +kubectl create namespace kubeflow |
| 114 | +./create_context.sh gke ${NAMESPACE} |
| 115 | +``` |
| 116 | + |
| 117 | +Setup OAuth environment variables ${CLIENT_ID} and ${CLIENT_SECRET} using the |
| 118 | +instructions |
| 119 | +[here](https://www.kubeflow.org/docs/started/getting-started-gke/#create-oauth-client-credentials). |
| 120 | + |
| 121 | +``` |
| 122 | +kubectl create secret generic kubeflow-oauth --from-literal=client_id=${CLIENT_ID} --from-literal=client_secret=${CLIENT_SECRET} |
| 123 | +``` |
| 124 | + |
| 125 | +Create service accounts, add permissions, download credentials, and create secrets: |
| 126 | + |
| 127 | +``` |
| 128 | +ADMIN_EMAIL=${CLUSTER}-admin@${PROJECT}.iam.gserviceaccount.com |
| 129 | +USER_EMAIL=${CLUSTER}-user@${PROJECT}.iam.gserviceaccount.com |
| 130 | +ADMIN_FILE=${HOME}/.ssh/${ADMIN_EMAIL}.json |
| 131 | +USER_FILE=${HOME}/.ssh/${ADMIN_EMAIL}.json |
| 132 | +
|
| 133 | +gcloud iam service-accounts create ${CLUSTER}-admin --display-name=${CLUSTER}-admin |
| 134 | +gcloud iam service-accounts create ${CLUSTER}-user --display-name=${CLUSTER}-user |
| 135 | +
|
| 136 | +gcloud projects add-iam-policy-binding ${PROJECT} \ |
| 137 | + --member=serviceAccount:${ADMIN_EMAIL} \ |
| 138 | + --role=roles/storage.admin |
| 139 | +gcloud projects add-iam-policy-binding ${PROJECT} \ |
| 140 | + --member=serviceAccount:${USER_EMAIL} \ |
| 141 | + --role=roles/storage.admin |
| 142 | +
|
| 143 | +gcloud iam service-accounts keys create ${ADMIN_FILE} \ |
| 144 | + --project ${PROJECT} \ |
| 145 | + --iam-account ${ADMIN_EMAIL} |
| 146 | +gcloud iam service-accounts keys create ${USER_FILE} \ |
| 147 | + --project ${PROJECT} \ |
| 148 | + --iam-account ${USER_EMAIL} |
| 149 | +
|
| 150 | +kubectl create secret generic admin-gcp-sa \ |
| 151 | + --from-file=admin-gcp-sa.json=${ADMIN_FILE} |
| 152 | +kubectl create secret generic user-gcp-sa \ |
| 153 | + --from-file=user-gcp-sa.json=${USER_FILE} |
| 154 | +``` |
| 155 | + |
| 156 | +Install kubeflow with the following commands: |
| 157 | + |
| 158 | +``` |
| 159 | +kfctl init ${CLUSTER} --platform gcp |
| 160 | +cd ${CLUSTER} |
| 161 | +kfctl generate k8s |
| 162 | +kfctl apply k8s |
| 163 | +``` |
| 164 | + |
| 165 | +## 3. Install pipelines on GKE |
| 166 | + |
| 167 | +``` |
| 168 | +kubectl create clusterrolebinding sa-admin --clusterrole=cluster-admin --serviceaccount=kubeflow:pipeline-runner |
| 169 | +cd ks_app |
| 170 | +ks registry add ml-pipeline "${PIPELINES_REPO}/ml-pipeline" |
| 171 | +ks pkg install ml-pipeline/ml-pipeline |
| 172 | +ks generate ml-pipeline ml-pipeline |
| 173 | +ks param set ml-pipeline namespace kubeflow |
| 174 | +ks apply default -c ml-pipeline |
| 175 | +``` |
| 176 | + |
| 177 | +View the installed components in the GCP Console. In the |
| 178 | +[Kubernetes Engine](https://console.cloud.google.com/kubernetes) |
| 179 | +section, you will see a new cluster ${CLUSTER}. Under |
| 180 | +[Workloads](https://console.cloud.google.com/kubernetes/workload), |
| 181 | +you will see all the default Kubeflow and pipeline components. |
| 182 | + |
| 183 | + |
0 commit comments