Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions kubernetes-ts-guestbook/simple/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Guestbook Monitoring Assignment

## Features
- Pulumi deployment
- Prometheus monitoring
- Grafana dashboards
- ServiceMonitor
- Guestbook metrics

## Deployment

npm install
pulumi up

## Grafana

URL:
http://localhost:32000

Username:
admin

Password:
admin123

## Verify Metrics

kubectl port-forward svc/prometheus-operated 9090 -n monitoring

Open:
http://localhost:9090/targets
118 changes: 113 additions & 5 deletions kubernetes-ts-guestbook/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,97 @@ import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const isMinikube = config.getBoolean("isMinikube");

const monitoringNs = new k8s.core.v1.Namespace("monitoring", {
metadata: {
name: "monitoring",
},
});

// Prometheus initialization

const prometheus = new k8s.helm.v3.Chart("prometheus", {

chart: "kube-prometheus-stack",

fetchOpts: {
repo: "https://prometheus-community.github.io/helm-charts",
},

namespace: monitoringNs.metadata.name,

values: {
grafana: {
enabled: false,
},

prometheus: {
prometheusSpec: {
serviceMonitorSelectorNilUsesHelmValues: false,
},
},
},
});

// Grafana implementation

const grafana = new k8s.helm.v3.Chart("grafana", {

chart: "grafana",

fetchOpts: {
repo: "https://grafana.github.io/helm-charts",
},

namespace: monitoringNs.metadata.name,

values: {

adminUser: "admin",
adminPassword: "admin123",

service: {
type: "NodePort",
nodePort: 32000,
},
},
});

// Grafana Monitor Service

const serviceMonitor = new k8s.apiextensions.CustomResource("guestbook-monitor", {

apiVersion: "monitoring.coreos.com/v1",

kind: "ServiceMonitor",

metadata: {
name: "guestbook-monitor",
namespace: "monitoring",
},

spec: {

selector: {
matchLabels: {
app: "frontend",
},
},

namespaceSelector: {
any: true,
},

endpoints: [
{
port: "http",
path: "/metrics",
interval: "15s",
},
],
},
});


//
// REDIS LEADER.
//
Expand Down Expand Up @@ -85,11 +176,20 @@ const redisReplicaService = new k8s.core.v1.Service("redis-replica", {

const frontendLabels = { app: "frontend" };
const frontendDeployment = new k8s.apps.v1.Deployment("frontend", {
spec: {
selector: { matchLabels: frontendLabels },
replicas: 3,
template: {
metadata: { labels: frontendLabels },
spec: {
selector: { matchLabels: frontendLabels },
replicas: 3,
template: {
metadata: {

labels: frontendLabels,

annotations: {
"prometheus.io/scrape": "true",
"prometheus.io/port": "80",
"prometheus.io/path": "/metrics",
},
},
spec: {
containers: [
{
Expand Down Expand Up @@ -125,3 +225,11 @@ if (isMinikube) {
} else {
frontendIp = frontendService.status.loadBalancer.ingress[0].ip;
}


// Add pulumi vars
export const grafanaUrl = "http://localhost:32000";

export const grafanaUser = "admin";

export const grafanaPassword = "admin123";
Loading