From abd76d847a6ef8784ef76db9609205239517f200 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Mon, 4 Feb 2019 17:24:49 -0200 Subject: [PATCH] Add SMTP relay for Gmail --- create_gmail_auth.sh | 10 ++++++++ smtp_server.jsonnet | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 create_gmail_auth.sh create mode 100644 smtp_server.jsonnet diff --git a/create_gmail_auth.sh b/create_gmail_auth.sh new file mode 100755 index 0000000..f29ae38 --- /dev/null +++ b/create_gmail_auth.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "Please enter your Gmail account"; +read username; + +echo "Please enter your Gmail password"; +read -s password; + +echo "Creating secret" +kubectl create secret generic smtp-account -n monitoring --from-literal=username=${username} --from-literal=password=${password} diff --git a/smtp_server.jsonnet b/smtp_server.jsonnet new file mode 100644 index 0000000..f0ca3de --- /dev/null +++ b/smtp_server.jsonnet @@ -0,0 +1,57 @@ +local k = import 'ksonnet/ksonnet.beta.3/k.libsonnet'; + +local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + + (import 'image_sources_versions.jsonnet') + + { + _config+:: { + namespace: 'monitoring', + }, + + smtpServer+:: { + deployment: + local deployment = k.apps.v1beta2.deployment; + local container = k.apps.v1beta2.deployment.mixin.spec.template.spec.containersType; + local containerPort = container.portsType; + + local podLabels = { run: 'smtp-server' }; + + local smtpServer = + container.new('smtp-server', $._config.imageRepos.smtpServer + ':' + $._config.versions.smtpServer) + + container.withPorts(containerPort.newNamed('smtp', 25)) + + container.withEnv([ + { + name: 'GMAIL_USER', + valueFrom: { + secretKeyRef: { name: 'smtp-account', key: 'username' }, + }, + }, + { + name: 'GMAIL_PASSWORD', + valueFrom: { + secretKeyRef: { name: 'smtp-account', key: 'password' }, + }, + }, + {name: 'DISABLE_IPV6', + value: 'True'}, + {name: 'RELAY_DOMAINS', value: ':192.168.0.0/24:10.0.0.0/16'}, + ]); + + local c = [smtpServer]; + + deployment.new('smtp-server', 1, c, podLabels) + + deployment.mixin.metadata.withNamespace($._config.namespace) + + deployment.mixin.metadata.withLabels(podLabels) + + deployment.mixin.spec.selector.withMatchLabels(podLabels), + + service: + local service = k.core.v1.service; + local servicePort = k.core.v1.service.mixin.spec.portsType; + local smtpServerPorts = servicePort.newNamed('smtp', 25, 'smtp'); + + service.new('smtp-server', $.smtpServer.deployment.spec.selector.matchLabels, smtpServerPorts) + + service.mixin.metadata.withNamespace($._config.namespace) + + service.mixin.metadata.withLabels({ 'run': 'smtp-server' }) + }, +}; + +{ ['smtp-server-' + name]: kp.smtpServer[name] for name in std.objectFields(kp.smtpServer) } \ No newline at end of file