Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create monitoring Prometheus with operator #79

Merged
merged 5 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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) }