Skip to content

Commit

Permalink
use prometheus stack helm chart as pre-requisite
Browse files Browse the repository at this point in the history
  • Loading branch information
katzefudder committed Jun 19, 2023
1 parent efd73d3 commit 61ba404
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/local_k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ jobs:
# hack: for having CRDs available, install helm chart then remove right after
- name: Install kube-prometheus-stack helm chart
run: helm repo add prometheus-community https://prometheus-community.github.io/helm-charts && helm repo update && helm install prometheus-stack prometheus-community/kube-prometheus-stack && helm uninstall prometheus-stack


- name: Create monitoring namespace
run: kubectl create ns monitoring

#### Terraforming
- name: 'Terragrunt Init'
run: cd $tf_working_dir && terragrunt init
Expand Down
2 changes: 1 addition & 1 deletion environments/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.7
1.5.0
2 changes: 1 addition & 1 deletion environments/.terragrunt-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.36.6
0.47.0
2 changes: 1 addition & 1 deletion environments/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ generate "provider" {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.20.0"
version = "2.21.1"
}
helm = {
source = "hashicorp/helm"
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ As I use nginx as my ingress controller, I needed to disable Traefik on K3D.
The cluster's load balancer will be available via ports 80 and 443
`k3d cluster create -p "80:80@loadbalancer" -p "443:443@loadbalancer" --k3s-arg="--disable=traefik@server:0"`

For the sake of having some ears and eyes for what's going on there on our cluster, we need some monitoring:

Install [Kube Prometheus Stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) for cluster monitoring.
`helm install -n monitoring -f terraform/modules/monitoring/config/monitoring.yaml kube-prometheus-stack prometheus-community/kube-prometheus-stack`

When your k3d backed Kubernetes is ready, you're also ready to deploy the stack using Terragrunt.

`cd environment/dev && terragrunt apply -auto-approve`
Expand Down
17 changes: 17 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

# start k3d cluster with nginx (and with disabled traefik)
echo "Starting K3d cluster"
k3d cluster create -p "80:80@loadbalancer" -p "443:443@loadbalancer" --k3s-arg="--disable=traefik@server:0" > /dev/null 2>&1 && echo "K3d cluster started"

echo "Creating Kubernetes namespace: monitoring"
kubectl create namespace monitoring > /dev/null 2>&1

# install kube prometheus stack helm chart
echo "Installing Kube Prometheus Stack"
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts && helm repo update && helm install -n monitoring -f terraform/modules/monitoring/config/monitoring.yaml kube-prometheus-stack prometheus-community/kube-prometheus-stack > /dev/null 2>&1 && echo "Kube Prometheus Stack installed"

echo "Running Terraform"
cd environments/dev && terragrunt init > /dev/null 2>&1 && terragrunt apply -auto-approve > /dev/null 2>&1 && echo "Terraform apply was successful"
3 changes: 0 additions & 3 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module "ingress" {
}

module "wordpress" {
depends_on = [
module.monitoring
]
source = "./modules/wordpress"
stage = var.stage
hostname = var.hostname
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/ingress/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ resource "helm_release" "ingress-nginx" {
atomic = true

values = [
"${file("${path.module}/templates/ingress-nginx-values.yaml")}"
file("${path.module}/templates/ingress-nginx-values.yaml")
]
}
2 changes: 1 addition & 1 deletion terraform/modules/monitoring/config/monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ grafana:
access: proxy
- name: Prometheus
type: prometheus
url: http://prometheus-community-kube-prometheus.monitoring:9090/
url: http://kube-prometheus-stack-prometheus.monitoring:9090/
access: proxy
adminUser: admin
adminPassword: a12sdf
Expand Down
8 changes: 4 additions & 4 deletions terraform/modules/monitoring/ingress.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "kubernetes_ingress_v1" "grafana" {
metadata {
name = "grafana"
namespace = kubernetes_namespace.monitoring.metadata[0].name
namespace = data.kubernetes_namespace.monitoring.metadata[0].name
annotations = {
"nginx.ingress.kubernetes.io/rewrite-target" = "/"
}
Expand All @@ -16,7 +16,7 @@ resource "kubernetes_ingress_v1" "grafana" {
path_type = "Prefix"
backend {
service {
name = "prometheus-community-grafana"
name = "kube-prometheus-stack-grafana"
port {
name = "http-web"
}
Expand All @@ -31,7 +31,7 @@ resource "kubernetes_ingress_v1" "grafana" {
resource "kubernetes_ingress_v1" "prometheus" {
metadata {
name = "prometheus"
namespace = kubernetes_namespace.monitoring.metadata[0].name
namespace = data.kubernetes_namespace.monitoring.metadata[0].name
annotations = {
"nginx.ingress.kubernetes.io/rewrite-target" = "/"
}
Expand All @@ -46,7 +46,7 @@ resource "kubernetes_ingress_v1" "prometheus" {
path_type = "Prefix"
backend {
service {
name = "prometheus-community-kube-prometheus"
name = "kube-prometheus-stack-prometheus"
port {
name = "http-web"
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/monitoring/loki.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "helm_release" "loki" {
name = "loki"
repository = "https://grafana.github.io/helm-charts"
chart = "loki-stack"
namespace = kubernetes_namespace.monitoring.metadata[0].name
namespace = data.kubernetes_namespace.monitoring.metadata[0].name
create_namespace = false
force_update = true
replace = true
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/monitoring/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "kubernetes_namespace" "monitoring" {
data "kubernetes_namespace" "monitoring" {
metadata {
name = "monitoring"
}
Expand Down
Empty file.

0 comments on commit 61ba404

Please sign in to comment.