Skip to content

Instantly share code, notes, and snippets.

@Vertiwell
Created September 1, 2022 20:49
Show Gist options
  • Save Vertiwell/b05c92b69c327514892f5882b7355449 to your computer and use it in GitHub Desktop.
Save Vertiwell/b05c92b69c327514892f5882b7355449 to your computer and use it in GitHub Desktop.
#!/bin/bash
### Deploying Robusta on Kubernetes for Debian/Ubuntu based OS
## Baseline Guide: https://docs.robusta.dev/master/getting-started/installation.html
# Type of Deployment: Helm
#
### Minimum Requirements ###
## Kubernetes Cluster (Tested on K0s, K3s, K8s)
## This is a Cloud Based UI App that connects to your cluster, it will ask to create an account, you can also connect it to Slack or Teams (or both)
#
## The following base packages are required:
# Helm, Package Manager
# curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
# chmod 700 get_helm.sh && \
# ./get_helm.sh && \
# Python PIP
apt-get install python3-pip -y
#
## Bring in the variables from the main configuration file
source /root/repo/deployment_config
#
## Set Variables
#
# Chart Repo
CHART=robusta/robusta
# Application
APPLICATION=robusta
# Chart Version: helm repo update && helm search repo robusta/robusta --versions
CHARTVERSION=0.10.1
# Set directory as a variable
FILEDIR=/root/helm/${APPLICATION}
# Namespace for this application
NAMESPACE=robusta
#
### Installation
#
# Set a directory to store files generated by this script (used for upgrades later)
mkdir -p /root/helm/${APPLICATION}
# Create Namespace
cat <<EOF >${FILEDIR}/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: ${NAMESPACE}
EOF
# Apply namespace
kubectl apply -f ${FILEDIR}/namespace.yaml
# Install the Helm chart repo
helm repo add robusta https://robusta-charts.storage.googleapis.com && helm repo update
## Create custom values file
# Install Robusta CLI
pip install -U robusta-cli --no-cache
# Generate and update generated config values if account exists
if [ -z "${ACCOUNTID}" ]
then
echo "No Existing Account Used, Moving On"
echo "Enter a Gmail/Google Workspace address, Choose an email you haven't used with Robusta before:"
read GOEMAIL
echo "Choose an Account Name (can be anything):"
read ACCNAME
printf ""${CLUSTERNAME}"\nN\nN\nN\nY\nN\n"${GOEMAIL}"\n"${ACCNAME}"\nN\nN\nY" | robusta gen-config
# Slack Integration
sed -i "s/sinksConfig: .*/sinksConfig:\n- slack_sink:\n name: main_slack_sink\n slack_channel: ${SLACKCHAN}\n api_key: ${SLACKAPI}/g" generated_values.yaml
else
echo "Existing Account Used, Updating..."
printf ""${CLUSTERNAME}"\nN\nN\nN\nN\nN\nN\nN" | robusta gen-config
sed -i "s/ signing_key: .*/ signing_key: ${SIGNINGKEY}/g" generated_values.yaml
sed -i "s/ account_id: .*/ account_id: ${ACCOUNTID}/g" generated_values.yaml
echo -e "" >> generated_values.yaml
# Slack Integration and UI Auth Token
sed -i "s/sinksConfig: .*/sinksConfig:\n- slack_sink:\n name: main_slack_sink\n slack_channel: ${SLACKCHAN}\n api_key: ${SLACKAPI}\n- robusta_sink:\n name: robusta_ui_sink\n token: "${UITOKEN}"/g" generated_values.yaml
fi
# Allow Routing to Robusta CLoud (temp while waiting for on-prem UI)
sed -i "s/disableCloudRouting: true/disableCloudRouting: false/g" generated_values.yaml
# Move the generated config file and add further values
mv generated_values.yaml ${FILEDIR}/custom-values.yaml
# Helm Chart Values: https://github.com/robusta-dev/robusta/blob/master/helm/robusta/values.yaml
cat <<EOF >>${FILEDIR}/custom-values.yaml
enablePrometheusStack: true
enablePlatformPlaybooks: true
enableServiceMonitors: true
kube-prometheus-stack:
prometheus:
prometheusSpec:
retentionSize: "9GB"
storageSpec:
volumeClaimTemplate:
spec:
storageClassName: ${STORAGECLASS}
resources:
requests:
storage: 10Gi
EOF
# Deploy the Application Helm Chart
helm upgrade ${APPLICATION} ${CHART} --install -n ${NAMESPACE} -f ${FILEDIR}/custom-values.yaml --version ${CHARTVERSION}
# Wait for the containers to come update
n=0
echo "Deploying pods, please be patient, average build time 5mins" && sleep 15 && \
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=90s deployment/robusta-kube-prometheus-st-operator -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do
$ROLLOUT_STATUS_CMD
n=$((n + 1))
sleep 5
done
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=60s deployment/robusta-kube-prometheus-st-operator -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do
$ROLLOUT_STATUS_CMD
n=$((n + 1))
sleep 5
done
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=60s deployment/robusta-forwarder -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do
$ROLLOUT_STATUS_CMD
n=$((n + 1))
sleep 5
done
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=60s deployment/robusta-grafana -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do
$ROLLOUT_STATUS_CMD
n=$((n + 1))
sleep 5
done
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=60s deployment/robusta-runner -n ${NAMESPACE}"
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do
$ROLLOUT_STATUS_CMD
n=$((n + 1))
sleep 5
done
#
### Upgrade Helm Chart
# Install the script that checks this chart for updates and sends them to Slack
/root/repo/Test-K3S-Cluster/Apps/Misc/helm_chart_update_script.sh "${FILEDIR}" "${CHART}" "${NAMESPACE}" "${APPLICATION}" "${SLACKURL}"
###
# Provide the user the URL
echo "URL for Robusta https://platform.robusta.dev/"
# Wipe everything (don't forget to save account details!!!): kubectl delete ns robusta; rm -r /root/helm/robusta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment