2019-05-22 05:50:53 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
#Based on ideas from https://github.com/rook/rook/blob/master/tests/scripts/minikube.sh
|
|
|
|
|
|
|
|
function wait_for_ssh() {
|
|
|
|
local tries=100
|
|
|
|
while ((tries > 0)); do
|
|
|
|
if minikube ssh echo connected &>/dev/null; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
tries=$((tries - 1))
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
echo ERROR: ssh did not come up >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy_image_to_cluster() {
|
|
|
|
local build_image=$1
|
|
|
|
local final_image=$2
|
2019-05-29 10:02:16 +00:00
|
|
|
if [ -z "$(docker images -q "${build_image}")" ]; then
|
2019-05-22 05:50:53 +00:00
|
|
|
docker pull "${build_image}"
|
2019-05-29 10:02:16 +00:00
|
|
|
fi
|
|
|
|
if [[ "${VM_DRIVER}" == "none" ]]; then
|
2019-05-22 05:50:53 +00:00
|
|
|
docker tag "${build_image}" "${final_image}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
docker save "${build_image}" | (eval "$(minikube docker-env --shell bash)" && docker load && docker tag "${build_image}" "${final_image}")
|
|
|
|
}
|
|
|
|
|
|
|
|
# install minikube
|
|
|
|
function install_minikube() {
|
|
|
|
if type minikube >/dev/null 2>&1; then
|
|
|
|
local version
|
|
|
|
version=$(minikube version)
|
2019-06-01 21:26:42 +00:00
|
|
|
read -ra version <<<"${version}"
|
2019-05-22 05:50:53 +00:00
|
|
|
version=${version[2]}
|
|
|
|
if [[ "${version}" != "${MINIKUBE_VERSION}" ]]; then
|
|
|
|
echo "installed minikube version ${version} is not matching requested version ${MINIKUBE_VERSION}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "minikube already installed with ${version}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing minikube. Version: ${MINIKUBE_VERSION}"
|
2019-11-07 09:55:12 +00:00
|
|
|
curl -Lo minikube https://storage.googleapis.com/minikube/releases/"${MINIKUBE_VERSION}"/minikube-linux-"${MINIKUBE_ARCH}" && chmod +x minikube && mv minikube /usr/local/bin/
|
2019-05-22 05:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_kubectl() {
|
|
|
|
# Download kubectl, which is a requirement for using minikube.
|
|
|
|
echo "Installing kubectl. Version: ${KUBE_VERSION}"
|
2019-11-07 09:55:12 +00:00
|
|
|
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/"${KUBE_VERSION}"/bin/linux/"${MINIKUBE_ARCH}"/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/
|
2019-05-22 05:50:53 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 08:22:43 +00:00
|
|
|
function enable_psp() {
|
|
|
|
echo "prepare minikube to support pod security policies"
|
|
|
|
mkdir -p "$HOME"/.minikube/files/etc/kubernetes/addons
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
cp "$DIR"/psp.yaml "$HOME"/.minikube/files/etc/kubernetes/addons/psp.yaml
|
|
|
|
}
|
|
|
|
|
2019-05-22 05:50:53 +00:00
|
|
|
# configure minikube
|
2019-11-07 09:55:12 +00:00
|
|
|
MINIKUBE_ARCH=${MINIKUBE_ARCH:-"amd64"}
|
2019-05-22 05:50:53 +00:00
|
|
|
MINIKUBE_VERSION=${MINIKUBE_VERSION:-"latest"}
|
2019-12-19 15:35:58 +00:00
|
|
|
KUBE_VERSION=${KUBE_VERSION:-"v1.14.10"}
|
2019-05-22 05:50:53 +00:00
|
|
|
MEMORY=${MEMORY:-"3000"}
|
|
|
|
VM_DRIVER=${VM_DRIVER:-"virtualbox"}
|
|
|
|
#configure image repo
|
|
|
|
CEPHCSI_IMAGE_REPO=${CEPHCSI_IMAGE_REPO:-"quay.io/cephcsi"}
|
|
|
|
K8S_IMAGE_REPO=${K8S_IMAGE_REPO:-"quay.io/k8scsi"}
|
2019-12-03 12:36:15 +00:00
|
|
|
DISK="sda1"
|
|
|
|
if [[ "${VM_DRIVER}" == "kvm2" ]]; then
|
|
|
|
# use vda1 instead of sda1 when running with the libvirt driver
|
|
|
|
DISK="vda1"
|
|
|
|
fi
|
2019-05-22 05:50:53 +00:00
|
|
|
|
|
|
|
#feature-gates for kube
|
2019-11-26 08:29:28 +00:00
|
|
|
K8S_FEATURE_GATES=${K8S_FEATURE_GATES:-"BlockVolume=true,CSIBlockVolume=true,VolumeSnapshotDataSource=true,ExpandCSIVolumes=true"}
|
2019-05-22 05:50:53 +00:00
|
|
|
|
2020-01-21 08:22:43 +00:00
|
|
|
#extra-config for kube https://minikube.sigs.k8s.io/docs/reference/configuration/kubernetes/
|
|
|
|
EXTRA_CONFIG=${EXTRA_CONFIG:-"--extra-config=apiserver.enable-admission-plugins=PodSecurityPolicy"}
|
|
|
|
|
2019-05-22 05:50:53 +00:00
|
|
|
case "${1:-}" in
|
|
|
|
up)
|
|
|
|
install_minikube
|
2019-06-02 09:49:24 +00:00
|
|
|
#if driver is 'none' install kubectl with KUBE_VERSION
|
2019-05-22 05:50:53 +00:00
|
|
|
if [[ "${VM_DRIVER}" == "none" ]]; then
|
|
|
|
mkdir -p "$HOME"/.kube "$HOME"/.minikube
|
|
|
|
install_kubectl
|
|
|
|
fi
|
|
|
|
|
2020-01-21 08:22:43 +00:00
|
|
|
enable_psp
|
|
|
|
|
2019-05-22 05:50:53 +00:00
|
|
|
echo "starting minikube with kubeadm bootstrapper"
|
2020-01-21 08:22:43 +00:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
minikube start --memory="${MEMORY}" -b kubeadm --kubernetes-version="${KUBE_VERSION}" --vm-driver="${VM_DRIVER}" --feature-gates="${K8S_FEATURE_GATES}" ${EXTRA_CONFIG}
|
2019-05-22 05:50:53 +00:00
|
|
|
|
|
|
|
# create a link so the default dataDirHostPath will work for this
|
|
|
|
# environment
|
|
|
|
if [[ "${VM_DRIVER}" != "none" ]]; then
|
|
|
|
wait_for_ssh
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
minikube ssh "sudo mkdir -p /mnt/${DISK}/${PWD}; sudo mkdir -p $(dirname $PWD); sudo ln -s /mnt/${DISK}/${PWD} $(dirname $PWD)/"
|
|
|
|
minikube ssh "sudo mkdir -p /mnt/${DISK}/var/lib/rook;sudo ln -s /mnt/${DISK}/var/lib/rook /var/lib/rook"
|
|
|
|
fi
|
|
|
|
kubectl cluster-info
|
|
|
|
;;
|
|
|
|
down)
|
|
|
|
minikube stop
|
|
|
|
;;
|
|
|
|
ssh)
|
|
|
|
echo "connecting to minikube"
|
|
|
|
minikube ssh
|
|
|
|
;;
|
2019-12-03 12:36:15 +00:00
|
|
|
deploy-rook)
|
|
|
|
echo "deploy rook"
|
2020-01-20 11:28:30 +00:00
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
|
|
|
"$DIR"/rook.sh deploy
|
2019-12-03 12:36:15 +00:00
|
|
|
;;
|
|
|
|
teardown-rook)
|
|
|
|
echo "teardown rook"
|
2020-01-20 11:28:30 +00:00
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
|
|
|
"$DIR"/rook.sh teardown
|
2019-12-03 12:36:15 +00:00
|
|
|
|
|
|
|
# delete rook data for minikube
|
|
|
|
minikube ssh "sudo rm -rf /mnt/${DISK}/var/lib/rook; sudo rm -rf /var/lib/rook"
|
|
|
|
minikube ssh "sudo mkdir -p /mnt/${DISK}/var/lib/rook; sudo ln -s /mnt/${DISK}/var/lib/rook /var/lib/rook"
|
|
|
|
;;
|
2019-05-22 05:50:53 +00:00
|
|
|
cephcsi)
|
2019-05-29 10:02:16 +00:00
|
|
|
echo "copying the cephcsi image"
|
2020-01-21 04:45:28 +00:00
|
|
|
copy_image_to_cluster "${CEPHCSI_IMAGE_REPO}"/cephcsi:v2.0-canary "${CEPHCSI_IMAGE_REPO}"/cephcsi:v2.0-canary
|
2019-05-22 05:50:53 +00:00
|
|
|
;;
|
|
|
|
k8s-sidecar)
|
|
|
|
echo "copying the kubernetes sidecar images"
|
2020-01-01 14:23:02 +00:00
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-attacher:v1.2.1 "${K8S_IMAGE_REPO}"/csi-attacher:v1.2.1
|
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-attacher:v2.1.0 "${K8S_IMAGE_REPO}"/csi-attacher:v2.1.0
|
2020-01-01 14:37:14 +00:00
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-snapshotter:v1.2.2 $"${K8S_IMAGE_REPO}"/csi-snapshotter:v1.2.2
|
2020-01-01 14:31:51 +00:00
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-provisioner:v1.4.0 "${K8S_IMAGE_REPO}"/csi-provisioner:v1.4.0
|
2020-01-01 14:41:56 +00:00
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-node-driver-registrar:v1.2.0 "${K8S_IMAGE_REPO}"/csi-node-driver-registrar:v1.2.0
|
2020-01-03 01:55:42 +00:00
|
|
|
copy_image_to_cluster "${K8S_IMAGE_REPO}"/csi-resizer:v0.4.0 "${K8S_IMAGE_REPO}"/csi-resizer:v0.4.0
|
2019-05-22 05:50:53 +00:00
|
|
|
;;
|
|
|
|
clean)
|
|
|
|
minikube delete
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " $0 [command]
|
|
|
|
Available Commands:
|
|
|
|
up Starts a local kubernetes cluster and prepare disk for rook
|
|
|
|
down Stops a running local kubernetes cluster
|
|
|
|
clean Deletes a local kubernetes cluster
|
|
|
|
ssh Log into or run a command on a minikube machine with SSH
|
2019-12-03 12:36:15 +00:00
|
|
|
deploy-rook Deploy rook to minikube
|
|
|
|
teardown-rook Teardown a rook from minikube
|
2019-05-22 05:50:53 +00:00
|
|
|
cephcsi copy built docker images to kubernetes cluster
|
|
|
|
k8s-sidecar copy kubernetes sidecar docker images to kubernetes cluster
|
|
|
|
" >&2
|
|
|
|
;;
|
|
|
|
esac
|