Skip to content

Commit

Permalink
feat: Create monitoring Prometheus with operator (#79)
Browse files Browse the repository at this point in the history
* feat: Create monitoring Prometheus with operator

* Remove all yaml file, replace by generating script

* Remove commentary in the template and write readme

Co-authored-by: Grumbleur <remi.gaiffe@googlemail.com>
Co-authored-by: 42Atomys <contact@atomys.fr>
  • Loading branch information
3 people authored May 4, 2022
1 parent 8497185 commit 37b17dc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cluster-initial-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ on:
type: boolean
required: true
description: (Re)set postgres password ?
install_monitoring:
type: boolean
required: true
description: (Re)set monitoring stack ?
jobs:
core_install:
runs-on: ubuntu-latest
Expand All @@ -47,6 +51,7 @@ jobs:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG_ADMIN }}
cluster-type: generic
- uses: alexdglover/jsonnet-render@v1
- run: kubectl apply -f deploy/cluster/namespaces
if: ${{ github.event.inputs.install_namespaces == 'true' }}
- run: ls -1 deploy/cluster/rbac/deployer*.yaml | xargs -l kubectl apply -f
Expand Down Expand Up @@ -78,6 +83,10 @@ jobs:
kubectl apply -f deploy/cluster/cert-manager/issuers
kubectl apply -f deploy/cluster/cert-manager/certificates
kubectl apply -f deploy/cluster/istio/gateways
- name: Install Prometheus Operator
if: ${{ github.event.inputs.install_monitoring == 'true' }}
run: |
cd ./deploy/cluster/monitoring && ./build.sh
update_secrets:
name: Install cross cluster secrets
Expand Down
9 changes: 9 additions & 0 deletions deploy/cluster/monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Monitoring

[Official documentation](https://github.com/prometheus-operator/kube-prometheus/blob/main/docs/customizing.md)

For deploy monitoring we need to generate json files with `jb` command.

Run the script `build.sh` for json files and apply in the cluster.

The script init workdir with `jb`, download some components mandatory, edit json files for scale down replicas and apply on the cluster.
23 changes: 23 additions & 0 deletions deploy/cluster/monitoring/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e
set -x
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail
# Make sure to use project tooling
PATH="$(pwd)/tmp/bin:${PATH}"

jb init
jb install github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus@main

mkdir -p manifests/setup

jsonnet -J vendor -m manifests "template.jsonnet" | xargs -I{} sh -c 'mv {} {}.json' -- {}
find manifests -type f ! -name '*.json' -delete
rm -f kustomization

sed -i -e 's/"replicas": 3/"replicas": 1/g' manifests/alertmanager-alertmanager.json
sed -i -e 's/"replicas": 2/"replicas": 1/g' manifests/prometheus-prometheus.json

kubectl apply --server-side -f manifests/setup
kubectl apply --server-side -f manifests
20 changes: 20 additions & 0 deletions deploy/cluster/monitoring/template.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local kp =
(import 'kube-prometheus/main.libsonnet') +
{
values+:: {
common+: {
namespace: 'monitoring',
},
},
};

{ 'setup/0namespace-namespace': kp.kubePrometheus.namespace } +
{
['setup/prometheus-operator-' + name]: kp.prometheusOperator[name]
for name in std.filter((function(name) name != 'serviceMonitor' && name != 'prometheusRule'), std.objectFields(kp.prometheusOperator))
} +
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }

0 comments on commit 37b17dc

Please sign in to comment.