From 10b82768c2a0747d967a73ede506f5147d9f6ed3 Mon Sep 17 00:00:00 2001 From: Carlos de Paula Date: Wed, 18 Mar 2020 11:12:53 -0300 Subject: [PATCH] Add SMTP relay as optional. Adjust formatting. --- Readme.md | 7 +++++-- main.jsonnet | 13 ++++++++----- smtp_server.jsonnet => smtp_relay.jsonnet | 0 vars.jsonnet | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) rename smtp_server.jsonnet => smtp_relay.jsonnet (100%) diff --git a/Readme.md b/Readme.md index fdfd115..1057e68 100644 --- a/Readme.md +++ b/Readme.md @@ -19,7 +19,7 @@ Components included in this package: * kube-state-metrics * CoreDNS * Grafana -* SMTP relay to Gmail for Grafana notifications +* SMTP relay to Gmail for Grafana notifications (optional) There are additional modules (disabled by default) to monitor other components of the infra-structure. These can be disabled on `vars.jsonnet` file by setting the module in `installModules` to `false`. @@ -46,6 +46,7 @@ For the ingresses, edit `suffixDomain` to have your cluster URL suffix. This wil To deploy the stack, run: ```bash +$ make vendor $ make deploy # Or manually: @@ -57,7 +58,7 @@ $ kubectl apply -f manifests/ $ until kubectl get customresourcedefinitions servicemonitors.monitoring.coreos.com ; do date; sleep 1; echo ""; done $ until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done -$ kubectl apply -f manifests/ # This command sometimes may need to be done twice (to workaround a race condition). +$ kubectl apply -f manifests/ # This command sometimes may need to be done twice (to workaround a race condition) ``` If you get an error from applying the manifests, run the `make deploy` or `kubectl apply -f manifests/` again. Sometimes the resources required to apply the CRDs are not deployed yet. @@ -90,6 +91,8 @@ $ kubectl apply -f manifests/ # This command sometimes may need to be done twice If you get an error from applying the manifests, run the `make deploy` or `kubectl apply -f manifests/` again. Sometimes the resources required to apply the CRDs are not deployed yet. +If you enable the SMTP relay for Gmail in `vars.jsonnet`, the pod will be in an error state after deployed since it would not find the user and password on the "smtp-account" secret. To generate, run the `scripts/create_gmail_auth.sh` script. + ## Ingress Now you can open the applications: diff --git a/main.jsonnet b/main.jsonnet index 330077f..6459ed1 100644 --- a/main.jsonnet +++ b/main.jsonnet @@ -1,13 +1,12 @@ -local vars = import 'vars.jsonnet'; local utils = import 'utils.libsonnet'; +local vars = import 'vars.jsonnet'; local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + (import 'kube-prometheus/kube-prometheus-anti-affinity.libsonnet') + (import 'kube-prometheus/kube-prometheus-kops-coredns.libsonnet') + (import 'kube-prometheus/kube-prometheus-kubeadm.libsonnet') // Use http Kubelet targets. Comment to revert to https - + (import 'kube-prometheus/kube-prometheus-insecure-kubelet.libsonnet') - + (import 'smtp_server.jsonnet') + // + (import 'kube-prometheus/kube-prometheus-insecure-kubelet.libsonnet') // Additional modules are loaded dynamically from vars.jsonnet + utils.join_objects([module.file for module in vars.modules if module.enabled]) // Load K3s customized modules @@ -20,7 +19,12 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') // Generate core modules { ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } -{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +{ + ['0prometheus-operator-' + name]: kp.prometheusOperator[name] + for name in std.filter((function(name) name != 'serviceMonitor'), std.objectFields(kp.prometheusOperator)) +} + +// serviceMonitor is separated so that it can be created after the CRDs are ready +{ 'prometheus-operator-serviceMonitor': kp.prometheusOperator.serviceMonitor } + { ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) } { ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } { ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } @@ -28,7 +32,6 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') { ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } { ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } { ['ingress-' + name]: kp.ingress[name] for name in std.objectFields(kp.ingress) } -{ ['smtp-server-' + name]: kp.smtpServer[name] for name in std.objectFields(kp.smtpServer) } { // Dynamically generate additional modules from vars.jsonnet [std.asciiLower(module.name) + '-' + name]: kp[module.name][name] diff --git a/smtp_server.jsonnet b/smtp_relay.jsonnet similarity index 100% rename from smtp_server.jsonnet rename to smtp_relay.jsonnet diff --git a/vars.jsonnet b/vars.jsonnet index 1a3334b..fab5553 100644 --- a/vars.jsonnet +++ b/vars.jsonnet @@ -1,9 +1,15 @@ { _config+:: { - namespace: 'monitoring' - }, + namespace: 'monitoring', + }, // Enable or disable additional modules modules: [ + { + // After deployment, run the create_gmail_auth.sh script from scripts dir. + name: 'smtpRelay', + enabled: false, + file: import 'smtp_relay.jsonnet', + }, { name: 'armExporter', enabled: false, @@ -33,15 +39,15 @@ k3s: { enabled: false, - master_ip: ['192.168.164.120'] + master_ip: ['192.168.15.15'], }, // Domain suffix for the ingresses - suffixDomain: '192.168.99.100.nip.io', + suffixDomain: '192.168.15.15.nip.io', // If TLSingress is true, a self-signed HTTPS ingress with redirect will be created TLSingress: true, - # If UseProvidedCerts is true, provided files will be used on created HTTPS ingresses. - # Use a wildcard certificate for the domain like ex. "*.192.168.99.100.nip.io" + // If UseProvidedCerts is true, provided files will be used on created HTTPS ingresses. + // Use a wildcard certificate for the domain like ex. "*.192.168.99.100.nip.io" UseProvidedCerts: false, TLSCertificate: importstr 'server.crt', TLSKey: importstr 'server.key',