Skip to content

Commit

Permalink
Add Traefik Dashboard (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis authored Sep 13, 2021
1 parent a0b3d90 commit 8d1ae18
Show file tree
Hide file tree
Showing 4 changed files with 1,407 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/kubernetes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ jobs:

- name: Get qhub-config.yaml full path
run: echo "QHUB_CONFIG_PATH=`realpath ./local-deployment/qhub-config.yaml`" >> $GITHUB_ENV

- name: Sleep to see if it fixes flaky Kubernetes Tests
run: sleep 60

- name: Cypress run
uses: cypress-io/github-action@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ resource "kubernetes_service" "main" {
}
}

resource "kubernetes_service" "traefik_internal" {
wait_for_load_balancer = true

metadata {
name = "${var.name}-traefik-internal"
namespace = var.namespace
annotations = {
"prometheus.io/scrape" = "true"
"prometheus.io/path" = "/metrics"
"prometheus.io/port" = 9000
}
labels = {
"app.kubernetes.io/component" = "traefik-internal-service"
"app.kubernetes.io/part-of" = "traefik-ingress"
}
}

spec {
selector = {
"app.kubernetes.io/component" = "traefik-ingress"
}

port {
name = "http"
protocol = "TCP"
port = 9000
target_port = 9000
}

type = "ClusterIP"
}
}

resource "kubernetes_deployment" "main" {
metadata {
Expand Down Expand Up @@ -189,6 +221,8 @@ resource "kubernetes_deployment" "main" {
"--entryPoints.traefik.address=:9000",
"--entrypoints.web.http.redirections.entryPoint.to=websecure",
"--entrypoints.web.http.redirections.entryPoint.scheme=https",
# Enable Prometheus Monitoring of Traefik
"--metrics.prometheus=true",
# Enable debug logging. Useful to work out why something might not be
# working. Fetch logs of the pod.
"--log.level=${var.loglevel}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ resource "helm_release" "kube-prometheus-stack-helm-deployment" {
chart = "kube-prometheus-stack"
version = "16.12.0"

values = [<<EOT
prometheus:
prometheusSpec:
additionalScrapeConfigs:
# This job will scrape from any service with the label app.kubernetes.io/component=traefik-internal-service
# and the annotation app.kubernetes.io/scrape=true
- job_name: 'traefik'
kubernetes_sd_configs:
- role: service
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
EOT
]

set {
name = "grafana.grafana\\.ini.server.domain"
value = var.external-url
Expand All @@ -19,7 +47,26 @@ resource "helm_release" "kube-prometheus-stack-helm-deployment" {
name = "grafana.grafana\\.ini.server.server_from_sub_path"
value = "true"
}
}

resource "kubernetes_manifest" "traefik_dashboard_configmap" {
provider = kubernetes-alpha

manifest = {
apiVersion = "v1"
kind = "ConfigMap"
metadata = {
name = "grafana-traefik-dashboard"
namespace = var.namespace
labels = {
# grafana_dashboard label needed for grafana to pick it up automatically
grafana_dashboard = "1"
}
}
data = {
"traefik-dashboard.json" = file("${path.module}/traefik.json")
}
}
}

resource "kubernetes_manifest" "grafana-strip-prefix-middleware" {
Expand Down
Loading

0 comments on commit 8d1ae18

Please sign in to comment.