The Email Operator for Kubernetes is a custom controller that manages email sending operations within a Kubernetes cluster. It utilizes the Kopf framework and integrates with email service providers like Mailersend to facilitate email dispatch directly from Kubernetes resources.
- Custom Resource Definitions (CRDs) for
EmailandEmailSenderConfig - Secure management of email provider credentials using Kubernetes Secrets
- Extensible architecture supporting multiple email service providers
- Full lifecycle management of email resources
- Event logging and status updates for email operations
- Kubernetes cluster (tested with v1.24+)
- Helm 3
- Docker
- Python 3.9+
- MailerSend account and API token
-
Create a MailerSend account at https://mailersend.com
-
Generate an API token from the MailerSend dashboard:
- Go to Settings → API Tokens
- Click "Create New Token"
- Give it a name and ensure it has "Email Send" permission
- Copy the generated token
-
Base64 encode your API token:
echo -n "your-api-token-here" | base64
-
Update the
values.yamlwith your encoded token:providers: - name: mailersend apiToken: <your-base64-encoded-token> senderEmail: your-verified-sender@domain.com
Note: Make sure your sender email is verified in MailerSend dashboard.
-
Clone the repository:
git clone https://github.com/teddy0605/emailsender-operator.git cd email-operator -
Configure your email provider credentials in
values.yaml -
Install the Helm chart:
helm install email-operator ./chart/emailsender-operator
-
Build the Docker image:
make build
-
Push the image to your registry:
make push
-
Deploy the operator:
make install
-
Create an
EmailSenderConfigresource:apiVersion: teddy.io/v1 kind: EmailSenderConfig metadata: name: my-email-config spec: apiTokenSecretRef: my-email-secret senderEmail: sender@example.com
-
Create an
Emailresource:apiVersion: teddy.io/v1 kind: Email metadata: name: test-email spec: senderConfigRef: my-email-config recipientEmail: recipient@example.com subject: "Test Email" body: "This is a test email sent via the Kubernetes Email Operator."
Refer to the values.yaml file in the Helm chart for configurable parameters. Key parameters include:
image.repository: Docker image repositoryimage.tag: Docker image tagresources: CPU/Memory resource requests and limitsproviders: Email provider configurations
To run the operator locally for development:
make runTo stop the local development process:
make stopFuture improvements planned for this project:
-
Observability
- Add Prometheus metrics for monitoring email operations
- Implement health check endpoints
- Enhanced logging and tracing
-
Reliability
- Add rate limiting for email sending
- Implement retry mechanism with exponential backoff
- Add circuit breaker for provider failures
-
Security
- Implement proper API token rotation
- Add support for multiple authentication methods
- Enhanced secret management
-
Features
- Support for HTML emails
- Email templates
- Attachment support
- Multiple recipient support
-
Testing
- Add unit tests
- Add integration tests
- Add E2E tests
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please file an issue on GitHub.