Skip to content

Commit

Permalink
add monitoring stack
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-the-programmer committed Jul 29, 2023
1 parent 98f46ce commit 699afe2
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions stacks/monitoring/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: meshed
runtime:
name: go
description: A collection of monitoring applications

88 changes: 88 additions & 0 deletions stacks/monitoring/grafana.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions stacks/monitoring/main.go
Original file line number Diff line number Diff line change
@@ -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
})
}

0 comments on commit 699afe2

Please sign in to comment.