Tutorial: https://codelabs.developers.google.com/codelabs/kubeflow-introduction/index.html#0

install ubuntu:
https://www.ubuntu.com/

download a proper version of google cloud SDK:
https://cloud.google.com/sdk/downloads#linux
https://cloud.google.com/sdk/docs/quickstart-linux
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-203.0.0-linux-x86_64.tar.gz
tar -xvf google-cloud-sdk-231.0.0-linux-x86_64.tar.gz
cd google-cloud-sdk
./install.sh

gcloud init

gcloud components install kubectl


install docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce

docker info

create cluster
PROJECT_ID=coen241-xzhu
gcloud config set project $PROJECT_ID
gcloud container clusters create kubeflow-codelab --zone us-central1-a --machine-type n1-standard-2
gcloud container clusters get-credentials kubeflow-codelab --zone us-central1-a

# make sure kubectl works fine
kubectl get nodes


# I am using kfadmin instead of default-admin as shown in the tutorial
kubectl create clusterrolebinding kfadmin \
     --clusterrole=cluster-admin --user=$(gcloud config get-value account)


install ks tools
KS_VER=ks_0.11.0_linux_amd64
wget --no-check-certificate https://github.com/ksonnet/ksonnet/releases/download/v0.11.0/$KS_VER.tar.gz
tar -xvf $KS_VER.tar.gz
PATH=$PATH:$(pwd)/$KS_VER


download repo
wget https://github.com/googlecodelabs/kubeflow-introduction/archive/master.zip

init ksonnet
ks init ksonnet-kubeflow
cd ksonnet-kubeflow


ks env add cloud
ks generate core kubeflow-core --name=kubeflow-core --cloud=gke
ks apply cloud -c kubeflow-core
kubectl get all


Part3

BUCKET_NAME=funtest-xzhu4
gsutil mb gs://$BUCKET_NAME/


//move back to the kubeflow-introduction project directory
cd ..
//create service account
gcloud iam service-accounts create kubeflow-codelab --display-name kubeflow-codelab


PROJECT_ID=coen241-ubuntu
IAM_EMAIL=kubeflow-codelab@$PROJECT_ID.iam.gserviceaccount.com
gsutil acl ch -u $IAM_EMAIL:O gs://$BUCKET_NAME

# important
gcloud iam service-accounts keys create ./tensorflow-model/key.json --iam-account=$IAM_EMAIL


Build Container

VERSION_TAG=$(date +%s)
TRAIN_PATH=us.gcr.io/$PROJECT_ID/kubeflow-train:$VERSION_TAG
docker build -t $TRAIN_PATH ./tensorflow-model --build-arg version=$VERSION_TAG --build-arg bucket=$BUCKET_NAME


docker run -it $TRAIN_PATH


//allow docker to access our GCR registry
gcloud auth configure-docker

//push container to GCR
docker push $TRAIN_PATH


Training on the Cluster

//move back into ksonnet directory
cd ksonnet-kubeflow

//generate component from prototype
ks generate tf-job train

//set the parameters for this job
ks param set train image $TRAIN_PATH
ks param set train name "train-"$VERSION_TAG

Apply the container to the cluster:
ks apply cloud -c train

kubectl describe tfjob


Serving
//create a ksonnet component from the prototype
ks generate tf-serving serve --name=mnist-serve
//set the parameters and apply to the cluster
ks param set serve modelPath gs://$BUCKET_NAME/
ks apply cloud -c serve

Deploying UI

//move back to the kubeflow-introduction project directory
cd ..

UI_PATH=us.gcr.io/$PROJECT_ID/kubeflow-web-ui

docker build -t $UI_PATH ./web-ui
gcloud auth configure-docker
docker push $UI_PATH

//move back into ksonnet project directory
cd ksonnet-kubeflow

ks generate deployed-service web-ui --name=web-ui --image=$UI_PATH \
      --type=LoadBalancer --containerPort=5000 --servicePort=80

//apply component to our cluster
ks apply cloud -c web-ui

kubectl get service web-ui

END