From 699afe20c86fcf16014c72351b64dbe6e7352389 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 29 Jul 2023 15:18:44 +1200 Subject: [PATCH] add monitoring stack --- Makefile | 16 +++++++ stacks/monitoring/Pulumi.yaml | 5 ++ stacks/monitoring/grafana.yaml | 88 ++++++++++++++++++++++++++++++++++ stacks/monitoring/main.go | 45 +++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 stacks/monitoring/Pulumi.yaml create mode 100644 stacks/monitoring/grafana.yaml create mode 100644 stacks/monitoring/main.go diff --git a/Makefile b/Makefile index b65f522..29d2c52 100644 --- a/Makefile +++ b/Makefile @@ -38,10 +38,26 @@ apps-up: apps-down: cd stacks/applications && pulumi stack select "applications" -c && pulumi destroy -y +.PHONY: monitoring-preview +monitoring-preview: + cd stacks/monitoring && pulumi stack select "monitoring" -c && pulumi preview + +.PHONY: monitoring-up +monitoring-up: + cd stacks/monitoring && pulumi stack select "monitoring" -c && pulumi up + +.PHONY: monitoring-down +monitoring-down: + cd stacks/monitoring && pulumi stack select "monitoring" -c && pulumi destroy -y + .PHONY: load-config load-config: cd stacks/cluster && pulumi stack output kubeconfig --show-secrets > $$HOME/.kube/config +.PHONY: grafana +grafana: + kubectl port-forward -n monitoring svc/grafana 3000:3000 + .PHONY: nuke nuke: ./kubernetes/resources/nuke.sh diff --git a/stacks/monitoring/Pulumi.yaml b/stacks/monitoring/Pulumi.yaml new file mode 100644 index 0000000..b6571cd --- /dev/null +++ b/stacks/monitoring/Pulumi.yaml @@ -0,0 +1,5 @@ +name: meshed +runtime: + name: go +description: A collection of monitoring applications + diff --git a/stacks/monitoring/grafana.yaml b/stacks/monitoring/grafana.yaml new file mode 100644 index 0000000..d7f6cac --- /dev/null +++ b/stacks/monitoring/grafana.yaml @@ -0,0 +1,88 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: grafana-pvc + namespace: monitoring +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: grafana + name: grafana + namespace: monitoring +spec: + selector: + matchLabels: + app: grafana + template: + metadata: + labels: + app: grafana + spec: + securityContext: + fsGroup: 472 + supplementalGroups: + - 0 + containers: + - name: grafana + image: grafana/grafana:9.1.0 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 3000 + name: http-grafana + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /robots.txt + port: 3000 + scheme: HTTP + initialDelaySeconds: 10 + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 2 + livenessProbe: + failureThreshold: 3 + initialDelaySeconds: 30 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 250m + memory: 750Mi + limits: + cpu: 500m + memory: 1Gi + volumeMounts: + - mountPath: /var/lib/grafana + name: grafana-pv + volumes: + - name: grafana-pv + persistentVolumeClaim: + claimName: grafana-pvc +--- +apiVersion: v1 +kind: Service +metadata: + name: grafana + namespace: monitoring +spec: + ports: + - port: 3000 + protocol: TCP + targetPort: http-grafana + selector: + app: grafana + sessionAffinity: None + type: LoadBalancer diff --git a/stacks/monitoring/main.go b/stacks/monitoring/main.go new file mode 100644 index 0000000..ab3dcc3 --- /dev/null +++ b/stacks/monitoring/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "meshed/kubernetes" + + corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1" + metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1" + "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + clusterStack, err := pulumi.NewStackReference(ctx, "scott-the-programmer/meshed/cluster", nil) + if err != nil { + return err + } + config := clusterStack.GetStringOutput(pulumi.String("kubeconfig")) + + provider, err := kubernetes.NewKubernetesProvider(ctx, config) + if err != nil { + return err + } + + ns, err := corev1.NewNamespace(ctx, "monitoring", + &corev1.NamespaceArgs{ + Metadata: metav1.ObjectMetaArgs{ + Name: pulumi.String("monitoring"), + }}, pulumi.Provider(provider)) + if err != nil { + return err + } + + _, err = yaml.NewConfigFile(ctx, "monitoring-deployment", + &yaml.ConfigFileArgs{ + File: "grafana.yaml", + }, + pulumi.Provider(provider), pulumi.Parent(ns)) + if err != nil { + return err + } + + return nil + }) +}