Scaling Event-Driven Applications Made Easy with Sveltos Kubernetes Cross-Cluster Configuration
Event-driven architectures are becoming increasingly popular as a way to build scalable, decoupled, and resilient systems. Sveltos is an open-source to deploy add-ons in tens of #Kubernetes clusters. Sveltos also has a built-in event-driven framework that makes it easy to deploy add-ons on Kubernetes clusters as a result of events.
What is Sveltos?
Sveltos is a powerful open-source project that makes managing Kubernetes add-ons a breeze. It automatically discovers ClusterAPI-powered clusters and allows you to easily register any other cluster (like GKE). Then, it seamlessly manages Kubernetes add-ons across all your clusters.
But that’s not all! Sveltos comes loaded with features like event-driven add-on deployment (using Lua scripts), configuration drift detection, and multi-tenancy to easily manage permissions for tenant admins. You can even preview changes with a dry run and rollback configurations with ease.
Event-driven
Sveltos' event-driven framework enables the deployment of add-ons in response to events occurring in managed Kubernetes clusters. Events are defined in the form of Lua scripts, which provide a flexible and powerful way to define complex event conditions.
Add-ons are expressed as templates that define the desired state of the resources that will be created in response to the event. These templates can be instantiated using information from resources in the managed clusters, such as labels or annotations, making it easy to dynamically generate new resources based on specific conditions.
With Sveltos, you can create highly scalable and flexible event-driven systems that can automatically respond to changes in your managed Kubernetes clusters. Whether you’re deploying new resources or modifying existing ones, Sveltos makes it easy to manage your infrastructure in a highly automated and efficient way, all while maintaining the reliability and scalability that Kubernetes is known for.
Sveltos' event-driven framework is covered here.
Cross-cluster configuration
Sveltos’ event-driven framework is designed to also enable communication and coordination between multiple Kubernetes clusters, which makes it ideal for cross-cluster configuration. By leveraging Sveltos’ cross-cluster configuration, you can create distributed event-driven systems that span multiple clusters, enabling you to build more complex and scalable applications.
Sveltos by default will deploy add-ons in the very same cluster an event is detected. Sveltos though can also be configured for cross-cluster configuration: watch for events in a cluster and deploy add-ons in a set of different clusters.
EventBasedAddOn CRD has a field called destinationClusterSelector, a Kubernetes label selector. This field is optional and not set by default. In such a case, Svelto's default behavior is to deploy add-ons in the same cluster where the event was detected.
If this field is set, Svelto's behavior will change. When an event is detected in a cluster, add-ons will be deployed in all the clusters matching the label selector destinationClusterSelector.
Imagine you’re managing two Kubernetes clusters — one on GKE and another provisioned by ClusterAPI. How do you ensure they’re working in harmony? That’s where Sveltos comes in. With Sveltos, you can create an EventSourcethat matches any Service with a load balancer IP, and an EventBasedAddOnthat references the EventSource and deploys a selector-less Service and corresponding Endpoints in any cluster matching destinationClusterSelector.
In simpler terms, Sveltos allows you to watch for specific events (like load balancer services), and respond to them by automatically deploying new resources across multiple clusters. By defining templates that specify how resources should be instantiated, Sveltos can create new Services and Endpoints on the fly, making it easy to manage complex, distributed systems.
For example, in the GKE cluster, you can create a deployment and a Service of type LoadBalancer. The Service will be assigned an IP address and match the EventSource, triggering Sveltos to deploy the selector-less Service and Endpoints in the other cluster — the ClusterAPI provisioned cluster. And just like that, a pod in the ClusterAPI provisioned cluster can now reach the service in the GKE cluster, thanks to Sveltos’ cross-cluster configuration.
Here are the YAMLs:
apiVersion: lib.projectsveltos.io/v1alpha1
kind: EventSource
metadata:
name: load-balancer-service
spec:
collectResources: true
group: ""
version: "v1"
kind: "Service"
script: |
function evaluate()
hs = {}
hs.matching = false
hs.message = ""
if obj.status.loadBalancer.ingress ~= nil then
hs.matching = true
end
return hs
end
apiVersion: lib.projectsveltos.io/v1alpha1
kind: EventBasedAddOn
metadata:
name: service-policy
spec:
sourceClusterSelector: env=production
destinationClusterSelector: dep=eng
eventSourceName: load-balancer-service
oneForEvent: true
policyRefs:
- name: service-policy
namespace: default
kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
metadata:
name: service-policy
namespace: default
data:
service.yaml: |
kind: Service
apiVersion: v1
metadata:
name: external-{{ .Resource.metadata.name }}
namespace: external
spec:
selector: {}
ports:
{{ range $port := .Resource.spec.ports }}
- port: {{ $port.port }}
protocol: {{ $port.protocol }}
targetPort: {{ $port.targetPort }}
{{ end }}
endpoint.yaml: |
kind: Endpoints
apiVersion: v1
metadata:
name: external-{{ .Resource.metadata.name }}
namespace: external
subsets:
- addresses:
- ip: {{ (index .Resource.status.loadBalancer.ingress 0).ip }}
ports:
{{ range $port := .Resource.spec.ports }}
- port: {{ $port.port }}
{{ end }}
Sveltos is a powerful tool for managing distributed Kubernetes clusters and building scalable, reliable applications that can seamlessly span multiple clusters. With Sveltos, you can create event-driven systems that respond automatically to changes in your infrastructure, making it easy to build complex, distributed systems that work together seamlessly.
Summary
Sveltos’ event-driven framework can be configured for cross-cluster deployment, allowing resources to be deployed across multiple clusters.
An EventSource can be defined to watch for specific events, such as load balancer services in any cluster.
An EventBasedAddOn can be configured to respond to those events by deploying new resources in other clusters.
Sveltos can use templates to instantiate new resources, making it easy to manage complex distributed systems.
With Sveltos, you can build scalable, reliable applications that can seamlessly span multiple clusters, making it a powerful tool for managing Kubernetes infrastructure.
Subscribe to my newsletter
Read articles from Gianluca Mardente directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gianluca Mardente
Gianluca Mardente
I am a Principal Engineer at Cisco Systems. I am also an open-source enthusiast and maintainer. I’m currently working on projectsveltos Ask me about policy distribution, golang, Kubernetes, ginkgo/gomega, C++