|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +export KS_VER=0.13.1 |
| 4 | +export KS_PKG=ks_${KS_VER}_linux_amd64 |
| 5 | +export KS_INSTALL_DIR=/usr/local/bin |
| 6 | + |
| 7 | +export KUBEFLOW_TAG=v0.5.1 |
| 8 | +export KFAPP=kubeflow |
| 9 | +export KUBEFLOW_SRC=/opt/kubeflow |
| 10 | + |
| 11 | +export DEEPOPS_DIR=$(dirname $(dirname $(readlink -f $0))) |
| 12 | + |
| 13 | +KSONNET_URL="${KSONNET_URL:-https://github.com/ksonnet/ksonnet/releases/download/v${KS_VER}/${KS_PKG}.tar.gz}" |
| 14 | +KUBEFLOW_URL="${KUBEFLOW_URL:-https://raw.githubusercontent.com/kubeflow/kubeflow/${KUBEFLOW_TAG}/scripts/download.sh}" |
| 15 | + |
| 16 | +### |
| 17 | + |
| 18 | +# Install dependencies |
| 19 | +. /etc/os-release |
| 20 | +case "$ID_LIKE" in |
| 21 | + rhel*) |
| 22 | + type curl >/dev/null 2>&1 |
| 23 | + if [ $? -ne 0 ] ; then |
| 24 | + sudo yum -y install curl wget |
| 25 | + fi |
| 26 | + ;; |
| 27 | + debian*) |
| 28 | + type curl >/dev/null 2>&1 |
| 29 | + if [ $? -ne 0 ] ; then |
| 30 | + sudo apt-get -y install curl wget |
| 31 | + fi |
| 32 | + ;; |
| 33 | + *) |
| 34 | + echo "Unsupported Operating System $ID_LIKE" |
| 35 | + exit 1 |
| 36 | + ;; |
| 37 | +esac |
| 38 | + |
| 39 | +# Rook |
| 40 | +kubectl get storageclass 2>&1 | grep "No resources found." >/dev/null 2>&1 |
| 41 | +if [ $? -eq 0 ] ; then |
| 42 | + echo "No storageclass found" |
| 43 | + echo "To provision Ceph storage, run: ./scripts/k8s_deploy_rook.sh" |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +# Ksonnet |
| 48 | +wget -O /tmp/${KS_PKG}.tar.gz "${KSONNET_URL}" \ |
| 49 | + --no-check-certificate |
| 50 | +mkdir -p ${KS_INSTALL_DIR} |
| 51 | +tempd=$(mktemp -d) |
| 52 | +tar -xvf /tmp/${KS_PKG}.tar.gz -C ${tempd} |
| 53 | +sudo mv ${tempd}/${KS_PKG}/ks ${KS_INSTALL_DIR} |
| 54 | +rm -rf ${tempd} /tmp/${KS_PKG}.tar.gz |
| 55 | + |
| 56 | +# Kubeflow |
| 57 | +if [ ! -d ${KUBEFLOW_SRC} ] ; then |
| 58 | + tempd=$(mktemp -d) |
| 59 | + cd ${tempd} |
| 60 | + curl "${KUBEFLOW_URL}" | bash |
| 61 | + cd - |
| 62 | + sudo mv ${tempd} ${KUBEFLOW_SRC} |
| 63 | +fi |
| 64 | + |
| 65 | +# Get master ip |
| 66 | +master_ip=$(kubectl get nodes -l node-role.kubernetes.io/master= --no-headers -o custom-columns=IP:.status.addresses.*.address | cut -f1 -d, | head -1) |
| 67 | + |
| 68 | +# Check for ingress controller |
| 69 | +ingress_name="nginx-ingress" |
| 70 | +ingress_ip_string="$(echo ${master_ip} | tr '.' '-')" |
| 71 | +if kubectl describe service -l "app=${ingress_name},component=controller" | grep 'LoadBalancer Ingress' >/dev/null 2>&1; then |
| 72 | + lb_ip="$(kubectl describe service -l "app=${ingress_name},component=controller" | grep 'LoadBalancer Ingress' | awk '{print $3}')" |
| 73 | + ingress_ip_string="$(echo ${lb_ip} | tr '.' '-').nip.io" |
| 74 | + echo "Using load balancer url: ${ingress_ip_string}" |
| 75 | +fi |
| 76 | + |
| 77 | +# Initialize and generate kubeflow |
| 78 | +set -e # XXX: Fail if anything in the initialization or configuration fail |
| 79 | +pushd ${HOME} |
| 80 | +${KUBEFLOW_SRC}/scripts/kfctl.sh init ${KFAPP} --platform none |
| 81 | +cd ${KFAPP} |
| 82 | + |
| 83 | +# Update the Kubeflow Jupyter UI |
| 84 | +export KSAPP_DIR="$(pwd)/ks_app" |
| 85 | +export KUBEFLOW_SRC |
| 86 | +${DEEPOPS_DIR}/scripts/update_kubeflow_config.py |
| 87 | + |
| 88 | +${KUBEFLOW_SRC}/scripts/kfctl.sh generate k8s |
| 89 | +pushd ${KSAPP_DIR} |
| 90 | +set +e |
| 91 | + |
| 92 | +# NOTE: temporarily using a custom image, to add custom command functionality |
| 93 | +ks param set jupyter-web-app image deepops/kubeflow-jupyter-web-app:v0.5-custom-command |
| 94 | + |
| 95 | +# Use NodePort directly if the IP string uses the master IP, otherwise use Ingress URL |
| 96 | +if echo "${ingress_ip_string}" | grep "${master_ip}" >/dev/null 2>&1; then |
| 97 | + ks param set ambassador ambassadorServiceType NodePort |
| 98 | + popd |
| 99 | + ${KUBEFLOW_SRC}/scripts/kfctl.sh apply k8s |
| 100 | + popd |
| 101 | + kf_ip=$master_ip |
| 102 | + kf_port=$(kubectl -n kubeflow get svc ambassador --no-headers -o custom-columns=:.spec.ports.*.nodePort) |
| 103 | + kf_url="http://${kf_ip}:${kf_port}" |
| 104 | +else |
| 105 | + ks param set ambassador ambassadorServiceType LoadBalancer |
| 106 | + popd |
| 107 | + ${KUBEFLOW_SRC}/scripts/kfctl.sh apply k8s |
| 108 | + popd |
| 109 | + kf_ip=$(kubectl -n kubeflow get svc ambassador --no-headers -o custom-columns=:.status.loadBalancer.ingress[0].ip) |
| 110 | + kf_url="http://${kf_ip}" |
| 111 | +fi |
| 112 | + |
| 113 | +echo |
| 114 | +echo "Kubeflow app installed to: ${HOME}/${KFAPP}" |
| 115 | +echo "To remove, run: cd ${HOME}/${KFAPP} && ${KUBEFLOW_SRC}/scripts/kfctl.sh delete k8s" |
| 116 | +echo "To fully remove all source and application code run: cd ${HOME} && rm -rf ${KFAPP}; rm -rf ${KUBEFLOW_SRC}" |
| 117 | +echo "To fully remove everything: cd ${HOME}/${KFAPP} && ${KUBEFLOW_SRC}/scripts/kfctl.sh delete k8s; cd ${DEEPOPS_DIR} && sudo rm -rf ${KFAPP}; sudo rm -rf ${KUBEFLOW_SRC}" |
| 118 | +echo |
| 119 | +echo "Kubeflow Dashboard: ${kf_url}" |
| 120 | +echo |
| 121 | +echo "This script is deprecated and will be removed in a future release in favor of v0.6" |
0 commit comments