Skip to content

Commit

Permalink
Added a minikube setup script. (kubeflow#1387)
Browse files Browse the repository at this point in the history
* Added a minikube setup script.

* Make local-notebooks accessible via Jupyter Notebooks

* Restructure minikube deployment script to work with kfctl patterns

* Cleanup

* fix comparison in jupyterhub.libsonnet for the new params

* Fix jsonnet string param parsing issues.

* Addressing some of jlewi's comments

* Refactored to split out kfctl.sh and setup-minikube.sh

* Remove unused function.

* Updated to use -1 on the env vars for UID / GID

* Move Docker registry env var into createEnv
  • Loading branch information
abhi-g authored and k8s-ci-robot committed Aug 25, 2018
1 parent 4a3e55e commit a52c321
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 12 deletions.
15 changes: 15 additions & 0 deletions kubeflow/core/jupyterhub.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@
name: "GCP_SECRET_NAME",
value: $.params.gcpSecretName,
},
if $.params.cloud == "minikube" && std.toString($.params.notebookUid) != "-1" then
{
name: "NOTEBOOK_UID",
value: std.toString($.params.notebookUid),
},
if $.params.cloud == "minikube" && std.toString($.params.notebookGid) != "-1" then
{
name: "NOTEBOOK_GID",
value: std.toString($.params.notebookGid),
},
if $.params.cloud == "minikube" then
{
name: "ACCESS_LOCAL_FS",
value: std.toString($.params.accessLocalFs),
},
]),
}, // jupyterHub container
],
Expand Down
22 changes: 22 additions & 0 deletions kubeflow/core/kubeform_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ def _expand_user_properties(self, template):
c.KubeSpawner.singleuser_working_dir = '/home/jovyan'
volumes = []
volume_mounts = []

# Allow environment vars to override uid and gid.
# This allows local host path mounts to be read/writable
env_uid = os.environ.get('NOTEBOOK_UID')
if env_uid:
c.KubeSpawner.singleuser_uid = int(env_uid)
env_gid = os.environ.get('NOTEBOOK_GID')
if env_gid:
c.KubeSpawner.singleuser_fs_gid = int(env_gid)
access_local_fs = os.environ.get('ACCESS_LOCAL_FS')
if access_local_fs == 'true':
def modify_pod_hook(spawner, pod):
pod.spec.containers[0].lifecycle = {
'postStart' : {
'exec' : {
'command' : ['ln', '-s', '/mnt/local-notebooks', '/home/jovyan/local-notebooks' ]
}
}
}
return pod
c.KubeSpawner.modify_pod_hook = modify_pod_hook

###################################################
# Persistent volume options
###################################################
Expand Down
3 changes: 3 additions & 0 deletions kubeflow/core/prototypes/jupyterhub.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// @optionalParam repoName string kubeflow-images-public The repository name for JupyterNotebook.
// @optionalParam disks string null Comma separated list of Google persistent disks to attach to jupyter environments.
// @optionalParam gcpSecretName string user-gcp-sa The name of the secret containing service account credentials for GCP
// @optionalParam notebookUid string -1 UserId of the host user for minikube local fs mount
// @optionalParam notebookGid string -1 GroupID of the host user for minikube local fs mount
// @optionalParam accessLocalFs string false Set true if mounting a local fs directory that needs to be accessed by Jupyter Notebook in Minikube.

// updatedParams uses the environment namespace if
// the namespace parameter is not explicitly set
Expand Down
54 changes: 42 additions & 12 deletions scripts/kfctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ENV_FILE="env.sh"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source "${DIR}/util.sh"
source "${DIR}/gke/util.sh"
source "${DIR}/util-minikube.sh"

createEnv() {
# Check if there is a file env.sh
Expand All @@ -29,13 +30,15 @@ createEnv() {
echo KUBEFLOW_REPO=${KUBEFLOW_REPO:-"${DEFAULT_KUBEFLOW_REPO}"} >> ${ENV_FILE}
echo KUBEFLOW_VERSION=${KUBEFLOW_VERSION:-"master"} >> ${ENV_FILE}
echo KUBEFLOW_KS_DIR=${KUBEFLOW_KS_DIR:-"$(pwd)/ks_app"} >> ${ENV_FILE}
echo KUBEFLOW_DOCKER_REGISTRY=${KUBEFLOW_DOCKER_REGISTRY:-""} >> ${ENV_FILE}

# Namespace where kubeflow is deployed
echo K8S_NAMESPACE=${K8S_NAMESPACE:-"kubeflow"} >> ${ENV_FILE}

if [ "${PLATFORM}" == "minikube" ]; then
echo KUBEFLOW_CLOUD=minikube >> ${ENV_FILE}
fi
if [ "${PLATFORM}" == "minikube" ]; then
echo KUBEFLOW_CLOUD=minikube >> ${ENV_FILE}
echo MOUNT_LOCAL=${MOUNT_LOCAL} >> ${ENV_FILE}
fi

if [ "${PLATFORM}" == "ack" ]; then
echo KUBEFLOW_CLOUD=ack >> ${ENV_FILE}
Expand All @@ -50,8 +53,7 @@ createEnv() {
echo PROJECT must be set either using environment variable PROJECT
echo or by setting the default project in gcloud
exit 1
fi
echo KUBEFLOW_DEPLOY=${KUBEFLOW_DEPLOY:-true} >> ${ENV_FILE}
fi

# Name of the deployment
DEPLOYMENT_NAME=${DEPLOYMENT_NAME:-"kubeflow"}
Expand Down Expand Up @@ -112,6 +114,7 @@ if [ "${COMMAND}" == "init" ]; then
esac
shift
done

mkdir -p ${DEPLOYMENT_NAME}
# Most commands expect to be executed from the app directory
cd ${DEPLOYMENT_NAME}
Expand Down Expand Up @@ -161,12 +164,6 @@ if [ -z "${WHAT}" ]; then
exit 1
fi

KUBEFLOW_VERSION=${KUBEFLOW_VERSION:-"master"}
KUBEFLOW_DEPLOY=${KUBEFLOW_DEPLOY:-true}
K8S_NAMESPACE=${K8S_NAMESPACE:-"kubeflow"}
KUBEFLOW_CLOUD=${KUBEFLOW_CLOUD:-"minikube"}
KUBEFLOW_DOCKER_REGISTRY=${KUBEFLOW_DOCKER_REGISTRY:-""}

# TODO(ankushagarwal): verify ks version is higher than 0.11.0
check_install ks
check_install kubectl
Expand All @@ -181,7 +178,20 @@ ksApply () {
pushd .
cd "${KUBEFLOW_KS_DIR}"

if [ "${PLATFORM}" == "minikube" ]; then
set +e
O=`kubectl get namespace ${K8S_NAMESPACE} 2>&1`
RESULT=$?
set -e

if [ "${RESULT}" -eq 0 ]; then
echo "namespace ${K8S_NAMESPACE} already exists"
else
kubectl create namespace ${K8S_NAMESPACE}
fi
fi

set +e
O=$(ks env describe default 2>&1)
RESULT=$?
set -e
Expand All @@ -200,11 +210,21 @@ ksApply () {
ks apply default -c argo
ks apply default -c spartakus
popd

set +x
if [ "${PLATFORM}" == "minikube" ]; then
if is_kubeflow_ready; then
mount_local_fs
setup_tunnels
else
echo -e "${RED}Unable to get kubeflow ready${NC}"
fi
fi
set -x
}

source "${ENV_FILE}"

echo PLATFORM=${PLATFORM}
if [ "${COMMAND}" == "generate" ]; then
if [ "${WHAT}" == "platform" ] || [ "${WHAT}" == "all" ]; then
if [ "${PLATFORM}" == "gcp" ]; then
Expand All @@ -221,6 +241,16 @@ if [ "${COMMAND}" == "generate" ]; then
if [ "${PLATFORM}" == "gcp" ]; then
gcpGenerateKsApp
fi

if [ "${PLATFORM}" == "minikube" ]; then
create_local_fs_mount_spec
if ${MOUNT_LOCAL}; then
ks param set jupyterhub disks "local-notebooks"
ks param set jupyterhub notebookUid `id -u`
ks param set jupyterhub notebookGid `id -g`
ks param set jupyterhub accessLocalFs true
fi
fi
fi
fi

Expand Down

0 comments on commit a52c321

Please sign in to comment.