-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path24a_deploy_loki.sh
executable file
·44 lines (35 loc) · 1.86 KB
/
24a_deploy_loki.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
set -euo pipefail
ZONE="europe-west1"
NAMESPACE=logging
PROJECT="olly-2021-k8s-migration"
SA_NAME=loki-sa
SA_MAIL="${SA_NAME}@${PROJECT}.iam.gserviceaccount.com"
KEY_FILE=/tmp/loki-gcp-key.json
SECRET=loki-secrets
BUCKET_NAME="loki_bucket_o11y_fans"
echo "=== Setup GCS as cloud storage and deploy loki stack in namespace ${NAMESPACE}"
echo "!!! this should not be run for the local deployment as it will mess with the remote logging !!!"
echo "--- setup GCS as cloud storage for Loki"
gsutil ls "gs://$BUCKET_NAME/" || gsutil mb -b on -l "$ZONE" -p "$PROJECT" "gs://$BUCKET_NAME/"
echo "--- create service account for Loki to access GCS"
gcloud iam service-accounts describe "$SA_MAIL" > /dev/null || gcloud iam service-accounts create "$SA_NAME" --project "$PROJECT" --display-name="Service account for Loki"
gcloud projects add-iam-policy-binding "$PROJECT" \
--member="serviceAccount:$SA_MAIL" \
--project "$PROJECT" \
--role="roles/storage.objectAdmin"
echo "--- create service account secret"
gcloud iam service-accounts keys create "$KEY_FILE" --iam-account="$SA_MAIL"
kubectl delete secret "$SECRET" -n "$NAMESPACE" || true
kubectl create secret generic "$SECRET" --from-file=gcp_service_account.json="$KEY_FILE" -n "$NAMESPACE"
rm $KEY_FILE
echo "--- install and update helm repos"
helm repo update
helm repo add fluent https://fluent.github.io/helm-charts
helm repo add loki-helm https://grafana.github.io/helm-charts/
echo "--- install fluentd (this may already have been done in 24_deploy_logging.sh)"
helm upgrade --install -n "$NAMESPACE" -f tools/logging/fluentd.yaml fluentd fluent/fluentd
echo "--- install loki"
helm upgrade --install -n "$NAMESPACE" -f tools/logging/loki.yaml --create-namespace loki grafana/loki
echo "--- install promtail"
helm upgrade --install -n "$NAMESPACE" -f tools/logging/promtail.yaml --create-namespace promtail grafana/promtail