Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bash script for deploying minio on DigitalOcean; this was removed from my kubernetes deployment util.sh (now just provision.sh), but will function to serve the binary if added to your util.sh and the object-storage.sh is invoked as your user-data
#!/bin/bash
pwd_set () {
cd /root/
}
dl_kubernetes_archive () {
curl -sSL RELEASE_URL -O && \
KUBE_TAR="kubernetes.tar.gz"
}
unpack_kubernetes_archive () {
if [ ! -f $KUBE_TAR ];
then
echo "kubernetes.tar.gz not found"; exit 1
else
tar -xvzf kubernetes.tar.gz
fi
}
dl_minio () {
wget https://dl.minio.io/server/minio/release/linux-amd64/minio && \
cp minio /usr/local/bin/minio && \
chmod +x /usr/local/bin/minio
}
check_minio_config () {
mkdir -p .minio
}
config_minio () {
if [ "$(which minio)" == "" ]; then
echo "Can't find minio in PATH, please fix and retry."
exit 1
fi
if [ ! -f minio ]; then
echo "minio not found"; exit 1
fi
if [ -f .minio.config.json ]; then
cp .minio/config.json .minio/config.json.bak
else
echo -e ".minio/config.json not found\n" && \
touch .minio/config.json
fi
echo '{
"version": "7",
"credential": {
"accessKey": "MINIO_KEY",
"secretKey": "MINIO_SECRET"
},
"region": "us-east-1",
"logger": {
"console": {
"enable": true,
"level": "fatal"
},
"file": {
"enable": false,
"fileName": "",
"level": ""
},
"syslog": {
"enable": false,
"address": "",
"level": ""
}
},
"notify": {
"amqp": {
"1": {
"enable": false,
"url": "",
"exchange": "",
"routingKey": "",
"exchangeType": "",
"mandatory": false,
"immediate": false,
"durable": false,
"internal": false,
"noWait": false,
"autoDeleted": false
}
},
"elasticsearch": {
"1": {
"enable": false,
"url": "",
"index": ""
}
},
"redis": {
"1": {
"enable": false,
"address": "",
"password": "",
"key": ""
}
}
}
}' >> .minio/config.json
if [ -d "kubernetes" ]; then
minio server kubernetes
else
echo -e "`pwd`/kubernetes not found\n"; exit 1
fi
}
pwd_set && \
dl_kubernetes_archive && \
unpack_kubernetes_archive && \
dl_minio && \
check_minio_config && \
config_minio
find-object-url() {
RELEASE_URL="https://github.com/kubernetes/kubernetes/releases/download/v${KUBE_VERSION}/kubernetes.tar.gz"
MINIO_KEY=$(date +%s | sha256sum | base64 | head -c 8 ; echo)
MINIO_SECRET=$(date +%s | sha256sum | base64 | head -c 24 ; echo)
MINIO_NODE_ID="$(date +%s | sha256sum | base64 | head -c 6 ; echo)"
echo "=> Provisioning object storage..."
sed -e "s|RELEASE_URL|${RELEASE_URL}|" \
-e "s|MINIO_KEY|${MINIO_KEY}|" \
-e "s|MINIO_SECRET|${MINIO_SECRET}|" \
$(dirname $0)/digitalocean/cloud-config/object-storage.sh > $KUBE_TEMP/object-storage.sh
STORE_ADDR=$(doctl compute droplet create kubernetes-minio-${MINIO_NODE_ID} --size 512mb --image ubuntu-14-04-x64 --ssh-keys ${SSH_KEY_ID} --region ${DO_REGION} --user-data-file $KUBE_TEMP/object-storage.sh --wait | awk '{print $3}' | tail -n 1) && \
STORE_DROPLET_ID=$(doctl compute droplet list | grep minio-kube-source | tail -n 1 | awk '{print $1}') && \
#THIS NEEDS TO BE REPLACED BY A CHECK FOR PORT READINESS
echo "Allowing Minio setup time to complete..."; sleep 90; echo "Checking readiness..." && \
MINIO_ENDPOINT="http://$STORE_ADDR:9000" && \
echo "==> Minio Endpoint Created"
echo "===> $MINIO_ENDPOINT (${MINIO_KEY}/${MINIO_SECRET})" && \
echo "===> Adding server $MINIO_ENDPOINT to minio client" && \
mc config host add $MINIO_NODE_ID $MINIO_ENDPOINT $MINIO_KEY $MINIO_SECRET S3v4
share=$(mc share download $MINIO_NODE_ID/server/kubernetes-server-linux-amd64.tar.gz | grep Share)
KUBE_TAR=${share#Share: }
echo $share
urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c"
esac
done
}
RELEASE_TMP_URL=$KUBE_TAR
RELEASE_URL=`urlencode $KUBE_TAR`
echo "cluster/digitalocean/util.sh: Object temp URL:"
echo -e "\t$RELEASE_TMP_URL"
}
object-store-teardown () {
echo -e "Deleting droplet $STORE_DROPLET_ID...\n"; \
doctl compute droplet delete $STORE_DROPLET_ID && \
echo -e "...$STORE_DROPLET_ID deleted.\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.