Skip to content

incsteps/kronopost

Repository files navigation

KronoPost: Kubernetes Cron Operator

KronoPost is a lightweight Kubernetes Operator designed to simplify the recurrent, scheduled invocation of endpoints on services deployed within your cluster. Instead of managing complex CronJob resources, KronoPost allows you to define a simple Custom Resource Definition (CRD) to handle scheduled HTTP/HTTPS requests to your services.

It's built using Java and the Micronaut framework.

Key Features

  • Simplified Scheduling: Define scheduled calls directly on a target service using a familiar cron expression.
  • Lightweight Alternative: A more streamlined and efficient alternative to creating CronJob resources that require dedicated containers running curl or similar tools.
  • Targeted Service Invocation: Directly targets internal Kubernetes Services, making it ideal for microservices that need external, recurring triggers.
  • Multiple Instances Support: Perfectly suited for applications where multiple instances require recurrent invocation (e.g., triggering a cleanup endpoint on various services).

Getting Started

Prerequisites

You need a running Kubernetes cluster and kubectl configured to interact with it.

1. Installation

KronoPost is deployed as a single Kubernetes Operator deployment.

  1. Apply CRD and RBAC: (Note: You must first apply the required CRD and RBAC configuration files.)

    kubectl apply -f crd.yaml
    kubectl apply -f rbac.yaml
  2. Deploy the Operator: Use the following manifest to deploy the KronoPost operator. This example assumes the operator will watch the default namespace.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: kronopost-operator
      name: kronopost-operator
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: kronopost-operator
      template:
        metadata:
          labels:
            app: kronopost-operator
        spec:
          serviceAccountName: kronopost-operator-sa # Replace with your created SA name
          containers:
            - image: incsteps/kronopost:0.0.1
              name: kronopost-operator
              imagePullPolicy: Always
              env:
                # Set the namespaces the operator should watch (comma-separated list)
                - name: KRONOPOST_NAMESPACES
                  value: "default" 
              resources:
                requests:
                  memory: "1024Mi"
                limits:
                  memory: "1024Mi"

    Apply the deployment:

    kubectl apply -f operator-deployment.yaml

2. Usage (Creating a Kronopost Resource)

Once the operator is running, create a Kronopost custom resource to define your scheduled call.

Here is an example Kronopost resource:

apiVersion: [incsteps.com/v1](https://incsteps.com/v1)
kind: Kronopost
metadata:
  name: kronopost-example
spec:
  # REQUIRED: The name of the Kubernetes Service to invoke.
  serviceSelector: example-service 
  
  # OPTIONAL: The protocol (http or https). Defaults to 'http'.
  protocol: http 
  
  # OPTIONAL: The path on the service to call. Defaults to '/'.
  path: /
  
  # REQUIRED: The cron expression defining the schedule.
  cron: "*/1 * * * *" # Every minute
  
  # OPTIONAL: The HTTP method (GET, POST, PUT, DELETE, etc.). Defaults to 'GET'.
  method: GET

How it works:

The KronoPost operator watches for this Kronopost object. According to the cron expression (e.g., "Every minute"), the operator will perform the specified HTTP request (e.g., GET) to the targeted service (example-service) at the defined path (/).

Apply the resource:

kubectl apply -f kronopost-resource.yaml

Configuration (CRD Spec)

Field Type Required Default Description
serviceSelector string Yes N/A Name of the target Kubernetes Service.
cron string Yes N/A Standard Cron expression (e.g., */5 * * * *).
protocol string No http The protocol to use (http or https).
path string No / The URL path to call on the service.
method string No GET The HTTP method (e.g., GET, POST).

Building and Development

If you wish to build the operator from source:

  1. Clone the repository:

    git clone [Your Repository URL]
    cd KronoPost
  2. Build the project (using Micronaut/Java):

    ./gradlew clean build
  3. Develop in a K3d local cluster: (Make sure you have Docker installed and configured.)

    k3d registry create registry.local --port 5000
    k3d cluster create --registry-config k3d-registry.yml

    where k3d-registry.yml contains:

    mirrors:
    "k3d-registry.local:5000":
    endpoint:
    - http://k3d-registry.local:5000

    You can use skaffold to deploy/debug skaffold debug

Contributing

We welcome contributions! Please feel free to submit issues and pull requests to help improve KronoPost.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

License

KronoPost is open-source software licensed under the MIT License.

About

Kronopost, a kubernetes operator to perform scheduled http calls to services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors