The Kubernetes Email Operator is a Kubernetes operator designed to manage the sending of emails using the email service providers MailerSend and Mailgun. It automates the process of configuring and sending emails from your Kubernetes cluster.
- Email Sending: Send emails from your Kubernetes cluster using MailerSend or Mailgun.
- Dynamic Configuration: Configure multiple email accounts for different purposes.
Before using or updating the Kubernetes Email Operator, ensure you have the following prerequisites installed and configured:
- Kubernetes cluster
kubectl
CLI installed and configured to access your cluster- Docker installed (if building custom Docker images)
- Go
- operator-sdk
- make
To install the Kubernetes Email Operator, follow these steps:
-
Clone the repository:
git clone https://github.com/RodrigoMatto/kubernetes-email-operator.git
-
Navigate to the project directory:
cd kubernetes-email-operator
-
Build the operator:
make docker-build docker-push IMG=<docker_hub_username>/kubernetes-email-operator:latest
-
Deploy the operator to your Kubernetes cluster:
make deploy IMG=<docker_hub_username>/kubernetes-email-operator:latest
You can also run the Kubernetes Email Operator in a test environment using the following steps:
-
Clone the repository:
git clone https://github.com/RodrigoMatto/kubernetes-email-operator.git
-
Navigate to the project directory:
cd kubernetes-email-operator
-
Create the Custom Resource Definitaions:
kubectl apply -f config/crd/bases/email-alerts.koperator.rmatto_emailsenderconfigs.yaml kubectl apply -f config/crd/bases/email-alerts.koperator.rmatto_emails.yaml
-
Run the operator:
make run
This will run the operator in your local environment for testing purposes.
Before using the Email Operator, you need to create a secret containing your API keys and domain information for MailerSend and Mailgun. You can create the secret using the provided sample file located at config/samples/email-operator-secrets.yaml.
Example secret file content:
apiVersion: v1
kind: Secret
metadata:
name: email-operator-secrets
type: Opaque
data:
mailersend-api-key: <base64_encoded_mailersend_api_key>
mailgun-api-key: <base64_encoded_mailgun_api_key>
mailgun-domain: <base64_encoded_mailgun_domain>
Replace <base64_encoded_mailersend_api_key>
, <base64_encoded_mailgun_api_key>
, and <base64_encoded_mailgun_domain>
with the base64-encoded values of your MailerSend API key, Mailgun API key, and Mailgun domain, respectively.
Once the operator is deployed and the secret is created, you can create email sender configurations and email objects to send emails.
Create EmailSenderConfig
EmailSenderConfig defines the settings for sending emails. You can create multiple EmailSenderConfig objects, each specifying the email provider and associated settings.
Example EmailSenderConfig for MailerSend:
apiVersion: email-alerts.koperator.rmatto/v1
kind: EmailSenderConfig
metadata:
name: emailsenderconfig-mailersend
spec:
emailProvider: MailerSend
apiToken:
senderEmail: [email protected]
Example EmailSenderConfig for Mailgun:
apiVersion: email-alerts.koperator.rmatto/v1
kind: EmailSenderConfig
metadata:
name: emailsenderconfig-mailgun
spec:
emailProvider: Mailgun
apiToken:
senderEmail: [email protected]
Create Email
To send an email, create an Email object specifying the recipient email address, subject, and body, along with the reference to the EmailSenderConfig.
Example Email object:
apiVersion: email-alerts.koperator.rmatto/v1
kind: Email
metadata:
name: email-sample
spec:
senderConfigRef: emailsenderconfig-mailersend
recipientEmail: [email protected]
subject: "Hello from Email Operator"
body: "This is a test email sent from the Email Operator."
This project is intended for testing purposes only and should not be used in a production environment as is.
These resources provide comprehensive documentation for integrating with the MailerSend and Mailgun APIs.