In this tutorial, you'll learn how to use Sveltos to manage and deploy add-ons across multiple clusters, offering centralized control and automation to enhance your Kubernetes experience.

Sveltos is an open-source Kubernetes deployment and management software used to distribute applications and add-ons across multiple Kubernetes cluster.

Sveltos runs from a cluster known as a management cluster, which provides centralized control and automation for managing applications and add-ons across multiple clusters.

Sveltos supports various add-on formats, including Helm charts, Kustomize, and YAML manifests. Key features of Sveltos include ClusterProfile and Profile as Custom Resource Definitions (CRDs), precise deployment control, event-driven deployment, and configuration drift detection. These key features of Sveltos enhance flexibility and maintain consistency across multiple clusters.

Sveltos on Civo Kubernetes

In this tutorial, you'll learn about Sveltos, the installation steps, cluster registration, add-on deployment using ClusterProfiles, and the benefits of using Sveltos.

Prerequisites

Before we begin, there are some prerequisites you’ll need to have in place:

Creating your Kubernetes Clusters

To create your first cluster using the Civo CLI, run the following command:

civo k3s create --region NYC1 --create-firewall --nodes 1 -m --save --switch --wait kube-bench

In this command, the - m flag merges the kubeconfig for the new cluster with your existing kubeconfig, and the --switch flag points your new cluster to the access application cluster.

You'll need to repeat those steps 3 more times to create 3 additional clusters for this tutorial. The purpose of the multiple clusters is to understand how Sveltos can manage multiple clusters from the management cluster.

Installing Sveltos on Civo

This tutorial will explore installing Sveltos on Civo through the CLI. However, you are able to install it through the Civo Marketplace on this page.

To install Sveltos v0.29.0 on your cluster through the Civo CLI, use the following commands:

kubectl apply -f https://raw.githubusercontent.com/projectsveltos/sveltos/main/manifest/manifest.yaml
kubectl apply -f https://raw.githubusercontent.com/projectsveltos/sveltos/main/manifest/default-classifier.yaml

This will deploy Sveltos on your cluster, and this cluster will serve as your management cluster. The management cluster is responsible for running Sveltos and deploying and managing add-ons across multiple clusters where you wish to deploy add-ons, including the management cluster itself.

You can now register Sveltos to the rest of the clusters. To do this, you’ll need to run these commands in your management cluster:

sveltosctl register cluster --namespace=demo --cluster=civo --kubeconfig=<civo-demo-kubeconfig>
sveltosctl register cluster --namespace=test --cluster=civo --kubeconfig=<civo-test-kubeconfig>
sveltosctl register cluster --namespace=run --cluster=civo --kubeconfig=<civo-run-kubeconfig>

After that, a Sveltos instance will be deployed in each of your clusters, all managed by the Sveltos management cluster.

Next, you’ll need to add labels to your clusters to ensure you identify each clusterSelector when you want to deploy add-ons on any cluster.

To add labels to your clusters, use the following commands:

kubectl label sveltoscluster -n civo civo-demo env=production
kubectl label sveltoscluster -n civo civo-test env=production
kubectl label sveltoscluster -n civo civo-run env=production

After the labels have been created for each cluster, use this command to see the labels added to your clusters:

kubectl get sveltoscluster -A --show-labels

You’ll get a similar result to this:

NAMESPACE   NAME   READY   VERSION        LABELS
demo         civo   true    v1.28.2+k3s1   env=production,sveltos-agent=present
test   civo   true    v1.28.2+k3s1   env=production,sveltos-agent=present
run          civo   true    v1.28.2+k3s1   env=production,sveltos-agent=present

After that, you can deploy add-ons with Sveltos, you'll need to use ClusterProfiles(CRDs) to define which add-ons you want to deploy and the respective clusters to which you wish to deploy the add-ons. If you are interested in deploying add-ons with Sveltos, check out this tutorial from Gianluca.

Troubleshooting

If you encounter any errors when installing Sveltos on your cluster, you can troubleshoot with the following steps:

Step 1: Verify if Sveltos is installed correctly in the projectsveltos namespace by using this command:

kubectl get pods -n projectsveltos

If pods are in different states and not in the Running state, then use these commands to have a look at the event section of your pods to know what the error may be:

kubectl describe pod <pod-name> -n projectsveltos
kubectl logs <pod-name> -n projectsveltos -f

Step 2: Check your clusters where you registered Sveltos:

kubectl get sveltosclusters -A

If your clusters are healthy, you'll get a READY=true state on your clusters, but it will be absent in unhealthy clusters. If a cluster is unhealthy, ensure you have used the right path of your kubeconfig. Use the following commands:

export KUBECONFIG=<directory of the provided cluster kubeconfig>
kubectl get nodes
kubectl get pods -A

If you can access the cluster resources with the kubeconfig, troubleshoot the network and firewall setup in your environment to ensure the flow of traffic from the management cluster to the managed cluster.

Step 3: Next, check the labels used on your registered clusters. use this command:

kubectl get sveltosclusters -A --show-labels

If the cluster labels are incorrect, you can overwrite them with the below command:

kubectl label sveltoscluster <cluster-name> -n <cluster namespace> env=dev --overwrite

env=dev is the new label set to the cluster.

What are the benefits of using Sveltos?

Let’s explore the benefits of Sveltos:

Terminology Description
Centralized Management Sveltos provides centralized management for your clusters. This allows you to manage multiple clusters from a single interface, ensuring consistency.
Automated Deployment Sveltos automates the deployment of add-ons and applications across multiple Kubernetes clusters.
Customization and Flexibility With Sveltos, you have the flexibility to customize add-on deployments based on specific cluster requirements. Sveltos also supports various formats for configuring ClusterProfiiles such as Helm charts, Kustomize, or YAML.
Enhanced Visibility and Control Sveltos provides you with the visibility of knowing add-ons installed on each cluster, allowing you to maintain and manage the cluster environments properly.
Integration with CI/CD Pipelines Sveltos can be integrated with continuous integration/continuous deployment (CI/CD) pipelines, enabling automated deployment of add-ons and applications.
Multi-tenancy Feature You can define ClusterProfiles specific to individual namespaces, ensuring that each tenant operates in its isolated environment. This feature prevents interference between workloads and provides isolation, security, and resource management.

Clean up(optional)

After you are done with this tutorial, you can remove your resources through the following ways:

  1. Civo CLI
  2. Civo UI

Civo CLI

To remove a cluster through the Civo CLI, use this command:

civo k3s delete civo-demo

You will need to repeat the steps to remove each cluster you created for this tutorial. Each time, replace the cluster name; civo-demo with the name of the specific cluster you wish to remove.

Civo UI

To remove a cluster through the Civo UI, log on to your Civo dashboard, and navigate to the ‘Kubernetes’ tab on the left-hand side of your UI, then choose the cluster you wish to delete.

Removing Sveltos from Civo Kubernetes using UI

After that click on the 'Delete' button. In the next pop-up, enter the name of your cluster and click the 'Delete' button. Repeat for each cluster you wish to delete.

Result of Removing Sveltos from Civo Kubernetes using UI

Summary

We covered Kubernetes Management with Sveltos and how it simplifies Kubernetes administration across multiple clusters. By leveraging Sveltos' features like ClusterProfile and Profile CRDs, precise deployment control, and event-driven deployment, you can easily distribute and manage add-ons and applications in a Kubernetes cluster. Sveltos ensures Kubernetes clusters become more efficient and flexible, and enables faster development cycles and improved infrastructure scalability.

Additional resources

If you want to know more about Sveltos, take a look at these resources: