Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Refactor the install (#12)
Browse files Browse the repository at this point in the history
* Refactor the install

Fixes https://github.com/kf5i/k3ai/issues/11.

* Refactor the install

Fixes https://github.com/kf5i/k3ai/issues/11.

* Add management plung

* Add management plung
  • Loading branch information
Gsantomaggio authored Oct 9, 2020
1 parent d55099e commit fc6b7ea
Showing 1 changed file with 164 additions and 72 deletions.
236 changes: 164 additions & 72 deletions install
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/bin/bash

#########################################
### K3ai (keɪ3ai)
### https://github.com/kf5i/k3ai
### Alessandro Festa @bringyourownai
### Gabriele Santomaggio @gsantomaggio
#########################################

info()
{
echo '[INFO] ' "$@"
Expand Down Expand Up @@ -41,88 +49,172 @@ while [ : ]
done
}

kubeflow_install_pipelines(){
info "Installing pipelines crd"
export PIPELINE_VERSION=1.0.1
kubectl apply -k "github.com/kubeflow/pipelines/manifests/kustomize/cluster-scoped-resources?ref=$PIPELINE_VERSION"
kubectl wait --for condition=established --timeout=60s crd/applications.app.k8s.io
sleep_cursor &
info "Installing pipelines manifests"
kubectl apply -k "github.com/kubeflow/pipelines/manifests/kustomize/env/platform-agnostic-pns?ref=$PIPELINE_VERSION"

waiting_pod_array=("k8s-app=kube-dns;kube-system"
"k8s-app=metrics-server;kube-system"
"app=traefik;kube-system"
"app=minio;kubeflow"
"app=mysql;kubeflow"
"app=cache-server;kubeflow"
"app=ml-pipeline-persistenceagent;kubeflow"
"component=metadata-grpc-server;kubeflow"
"app=ml-pipeline-ui;kubeflow")

for i in "${waiting_pod_array[@]}"; do
echo "$i";
IFS=';' read -ra VALUES <<< "$i"
wait "${VALUES[0]}" "${VALUES[1]}"
done



info "Kubeflow pipelines ready!!"

info "Defining the ingress"
sleep_cursor

kubectl apply -f - << EOF
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: traefik-lb
spec:
controller: traefik.io/ingress-controller
EOF

if [ $1 = "--gpu" ]
then
info "Install Pipelines with GPU support, docker as runtime"
curl -sfL https://get.k3s.io | sh -s - --docker --kubelet-arg="feature-gates=DevicePlugins=true" --write-kubeconfig-mode 644
#### GPU Support
kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.7.0/nvidia-device-plugin.yml
else
info "Install Pipelines without GPU support, containerd as runtime"
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
fi

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

info "Installing pipelines crd"
export PIPELINE_VERSION=1.0.1
kubectl apply -k "github.com/kubeflow/pipelines/manifests/kustomize/cluster-scoped-resources?ref=$PIPELINE_VERSION"
kubectl wait --for condition=established --timeout=60s crd/applications.app.k8s.io
sleep_cursor &
info "Installing pipelines manifests"
kubectl apply -k "github.com/kubeflow/pipelines/manifests/kustomize/env/platform-agnostic-pns?ref=$PIPELINE_VERSION"

waiting_pod_array=("k8s-app=kube-dns;kube-system"
"k8s-app=metrics-server;kube-system"
"app=traefik;kube-system"
"app=minio;kubeflow"
"app=mysql;kubeflow"
"app=cache-server;kubeflow"
"app=ml-pipeline-persistenceagent;kubeflow"
"component=metadata-grpc-server;kubeflow"
"app=ml-pipeline-ui;kubeflow")

for i in "${waiting_pod_array[@]}"; do
echo "$i";
IFS=';' read -ra VALUES <<< "$i"
wait "${VALUES[0]}" "${VALUES[1]}"
done
kubectl apply -f - << EOF
apiVersion: "networking.k8s.io/v1beta1"
kind: "Ingress"
metadata:
name: "pipeline-ingress"
namespace: kubeflow
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
ingressClassName: "traefik-lb"
rules:
- http:
paths:
- path: "/"
backend:
serviceName: "ml-pipeline-ui"
servicePort: 80
EOF

sleep_cursor

IP=$(kubectl get service/traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}' -n kube-system)
info "pipelines UI: http://"$IP
}

info "Kubeflow pipelines ready!!"
##################
INTERNAL_INSTALL_K3S_EXEC=""

info "Defining the ingress"
sleep_cursor

kubectl apply -f - << EOF
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: traefik-lb
spec:
controller: traefik.io/ingress-controller
EOF
k3s_install_service()
{
info "Installing k3s service with the following parameters:" "${INSTALL_K3S_EXEC} ${INTERNAL_INSTALL_K3S_EXEC}"
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="${INSTALL_K3S_EXEC} ${INTERNAL_INSTALL_K3S_EXEC}" sh -s -
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
}

kubectl apply -f - << EOF
apiVersion: "networking.k8s.io/v1beta1"
kind: "Ingress"
metadata:
name: "example-ingress"
namespace: kubeflow
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
ingressClassName: "traefik-lb"
rules:
- http:
paths:
- path: "/"
backend:
serviceName: "ml-pipeline-ui"
servicePort: 80
EOF
k3s_install_service_gpu()
{
info "Installing the GPU Support on docker"
INTERNAL_INSTALL_K3S_EXEC="--docker"
k3s_install_service
#### GPU Support
kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.7.0/nvidia-device-plugin.yml
}

sleep_cursor

info "K3s AI ready!!"
default_installation(){
info "Installing pipelines"
k3s_install_service
kubeflow_install_pipelines
}


manage_plugin(){
PLUGIN=$1
PLUGIN="${PLUGIN:2}"
info "Installing plugin: " $PLUGIN
info "URL:" https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/$PLUGIN/install
curl -sfL https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/$PLUGIN/install | bash -s -
}


manage() {
### DEFAULT == --cpu and --pipelines
# if [[ "$#" -eq 0 ]]; then
# kubeflow_install_pipelines
# fi
while [[ "$#" -ne 0 ]]; do
case "$1" in
"--pipelines")
kubeflow_install_pipelines
shift 1
;;
--plugin*)
info "Installing plugin:" "$1"
manage_plugin "$1"
shift 1
;;
*)
shift 1
;;
esac
done
}


info "To use kubectl: export KUBECONFIG=/etc/rancher/k3s/k3s.yaml"
info "or you can use k3s kubectl "


main() {
### DEFAULT == --cpu and --pipelines
if [[ "$#" -eq 0 ]]; then
default_installation
fi
OR="$@"
while [[ "$#" -ne 0 ]]; do
case "$1" in
"--gpu")
k3s_install_service_gpu
manage $OR
shift 1
;;
"--cpu")
info "Installing the CPU Support"
k3s_install_service
manage $OR
shift 1
;;
"--skipk3s")
info "Skip Installation Server"
manage $OR
shift 1
;;

*)
shift 1
;;
esac
done
}

main "$@"


info "K3ai setup finished"
info "k3s-uninstall.sh to uninstall"

IP=$(kubectl get service/traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}' -n kube-system)
info "pipelines UI: http://"$IP

0 comments on commit fc6b7ea

Please sign in to comment.