-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Support for Multi-Cluster ClusterProfiles #430
Comments
Thank you @kahirokunn Not familiar with that. From what I read (quickly) the goal seems to be to have a unique representation for clusters (instead of using the SveltosCluster or ClusterAPI concept). Is your question related to that? If not would you mind expanding a bit? Thank you |
Hello! Thank you so much for taking the time to look into my question. Yes, it is indeed related to unifying how clusters are represented, similar to what’s described in KEP-4322. Specifically, I’d love to know if there are any plans or discussions around supporting a multi-cluster ClusterProfile in Sveltos—one that doesn’t rely solely on SveltosCluster or Cluster API. Thank you! |
Thank you @kahirokunn. The short answer is yes. If there is a new generic way of representing clusters, I will definitely have Sveltos support that. It should not be difficult to integrate. At the end of the day Sveltos just needs to:
|
Thank you for your response. I have been using ClusterAPI to create clusters, but I also wanted to manage existing on-premises clusters simultaneously. In doing so, I encountered challenges that ClusterAPI couldn't resolve, and I found the multi-cluster support of ClusterProfile to be extremely useful. If Sveltos could also support multi-cluster ClusterProfile, it would allow for managing clusters in a more standardized way. Additionally, compared to SveltosCluster, it would be great that Sveltos itself could natively integrate with many multi-cluster tools. I look forward to the continued development of Sveltos. Thank you very much! |
Thank you. It makes sense. Currently you can register on prem clusters (or any other existing cluster) with Sveltos and then Sveltos can manage add-ons and applications. I will read more about it. But if you are already familiar, can you share more about ClusterProfile? The questions I have are following
Assuming # 2 is something that can be found in the management cluster, having Sveltos support it would be really easy. Thank you again for suggesting this integration. |
The ClusterProfile API provides a standardized way to represent clusters in a multi-cluster environment. While there are three possible approaches for cluster access, let me focus on the most straightforward implementation path:
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ClusterProfile
metadata:
name: onprem-cluster-east
namespace: production-clusters
labels:
x-k8s.io/cluster-manager: sveltos
spec:
displayName: "East DC Production Cluster"
clusterManager:
name: sveltos
status:
version:
kubernetes: 1.28.0
properties:
- name: location
value: east-datacenter
- name: environment
value: production
conditions:
- type: ControlPlaneHealthy
status: "True"
lastTransitionTime: "2024-01-16T10:00:00Z"
- type: Joined
status: "True"
lastTransitionTime: "2024-01-16T09:55:00Z"
apiVersion: v1
kind: Secret
metadata:
name: cluster-east-credentials
namespace: sveltos-system
labels:
x-k8s.io/cluster-inventory-consumer: sveltos
x-k8s.io/cluster-profile: onprem-cluster-east
type: Opaque
data:
config: <base64-encoded kubeconfig> For Sveltos integration, the initial implementation would:
This approach allows you to:
|
After addressing some SIG-Multicluster content, it would be good to add Sveltos to the implementation status page at: https://multicluster.sigs.k8s.io/guides/#implementation-status |
Thanks @kahirokunn Sveltos though does not manage the creation of clusters. Once you have a Cluster, it can be registered with Sveltos and Sveltos can deploy add-ons and applications. In other words, if you have a cluster you created on your own (either on prem or somewhere else GKE, EKS, Civo, ...), you can register with Sveltos and from that point on Sveltos can deploy applications and add-ons there. So instead of Sveltos creating a multicluster.x-k8s.io/v1alpha1 ClusterProfile, what if:
This should be easy to achieve. Using Sveltos event framework, whenever a ClusterProfile is created/deleted a SveltosCluster can be created/deleted. User manages the ClusterProfile and does not care about SveltosClusters. Doing so, Sveltos can be used immediately to deploy add-ons and applications on those clusters. The reason I am suggesting this is because again Sveltos is not in the business of creating/deleting clusters. Sveltos comes once a cluster is been created. Of course we could also do the opposite, so for every SveltosCluster create a ClusterProfile. But then Sveltos, except version, would not know how to set the other properties. Let me know what you think. |
Thank you for the detailed explanation. I completely agree with your approach regarding Sveltos' role in cluster management. Your suggestion to have Sveltos recognize multicluster.x-k8s.io/v1alpha1 ClusterProfile and create corresponding SveltosClusters makes perfect sense, as it maintains a clear separation of concerns while enabling Sveltos to focus on its core strength of managing add-ons and applications. |
In addition, is there any plan to provide a plugin for Backstage, the recently popular Idp on Dashboard? |
Thanks. Will prepare something tomorrow for ClusterProfile => SveltosCluster and share. Thanks for the feedback on UI. Registering clusters via UI is something I would love to do. While I maintain all the backend for Sveltos, I am not a frontend engineer though. So I am looking for frontend engineers who want to contribute. Regarding Backstage integration, would you mind filing an enhancement request here so we don't loose track of it? Thank you |
Looking forward to it. Ok, I posted about Backstage below. |
@kahirokunn here is the necessary configuration. If you just post this (and label the SveltosCluster in the mgmt namespace with env: management), a SveltosCluster will get created for every clusterprofiles.multicluster.x-k8s.io (of course updating/deleting clusterprofiles.multicluster.x-k8s.io corresponding SveltosCluster gets also updated/deleted)
Assuming Sveltos is deployed in the management cluster and the SveltosCluter mgmt in the mgmt namespace has label
In my test I created a ClusterProfile and a Secret and automatically SveltosCluster was created and Sveltos started managing add-ons and applications in such a cluster.
Please let me know if this is sufficient. No extra pods are necessary. |
Thank you, I will try to get the code to work for me! That code is really great! ClusterProfile is used in conjunction with the ClusterProperty custom resource. Its contents are written in apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ClusterProfile
metadata:
name: generated-cluster-name
labels:
x-k8s.io/cluster-manager: some-cluster-manager
spec:
displayName: cluster-us-east
clusterManager:
name: some-cluster-manager
status:
version:
kubernetes: 1.28.0
properties:
- name: clusterset.k8s.io
value: some-clusterset
- name: location
value: apac
conditions:
- type: ControlPlaneHealthy
status: True
lastTransitionTime: "2023-05-08T07:56:55Z"
message: ""
- type: Joined
status: True
lastTransitionTime: "2023-05-08T07:58:55Z"
message: "" I thought it would be better if I could manipulate the SveltosCluster spec by referencing the contents of |
Thanks @kahirokunn Sveltos gets Kubernetes version by querying directly the APIServer of the managed cluster. And mark it ready once it can connect to it. So I think we can ignore this (unless I misunderstood your point) |
Found this code not working properly when ---
apiVersion: v1
kind: ConfigMap
metadata:
name: sveltoscluster-metadata
namespace: default
annotations:
projectsveltos.io/instantiate: ok
data:
sveltos-cluster.yaml: |
apiVersion: lib.projectsveltos.io/v1beta1
kind: SveltosCluster
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
labels:
{{ range $key, $value := .Resource.metadata.labels }}
{{ $key }}: {{ $value }}
{{end}} Trying this (it seems almost correct to me) but still not working in case of ---
apiVersion: v1
kind: ConfigMap
metadata:
name: sveltoscluster-metadata
namespace: default
annotations:
projectsveltos.io/instantiate: ok
data:
sveltos-cluster.yaml: |
apiVersion: lib.projectsveltos.io/v1beta1
kind: SveltosCluster
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
{{ if .Resource.metadata.labels }}
labels:
{{ range $key, $value := .Resource.metadata.labels }}
{{ $key }}: {{ $value }}
{{ end }}
{{ end }} Any suggestion for improvement? |
Oh my gosh, that's great! |
Thanks @bsctl good catch. This works even if there are no labels apiVersion: v1
kind: ConfigMap
metadata:
name: sveltoscluster-metadata
namespace: default
annotations:
projectsveltos.io/instantiate: ok
data:
sveltos-cluster.yaml: |
apiVersion: lib.projectsveltos.io/v1beta1
kind: SveltosCluster
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
{{- if (index .Resource.metadata `labels`) -}}
labels:
{{ range $key, $value := .Resource.metadata.labels }}
{{ $key }}: {{ $value }}
{{ end }}
{{- end -}} |
Hi @kahirokunn yes SveltosCluster can be paused (so no updates are sent to cluster). Just set the Spec.Paused field. // +optional
Paused bool `json:"paused,omitempty"` and you can also set an active window when updates can be sent |
When I try testing the if statement by giving a resource that doesn't have the key “labels”, I get an error saying “map has no entry for key ‘labels’”. Do you know anything about this? 👀
|
I got the same error with both “with” and “if”, so it didn't work. |
I tried the following code, but the Secret gets written into the ConfigMap in projectsveltos's namespace: When a Secret is written into a ConfigMap, the Secret's contents get output to the Kubernetes audit log. Additionally, from an RBAC perspective, granting ConfigMap permissions effectively means granting Secret permissions as well, which poses a high risk. Therefore, I tried the following verification, but received an error saying "failed to update ClusterProfile for EventTrigger transform-tls-secret: unsupported secret type": ---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
name: detect-tls-secret
spec:
collectResources: true
resourceSelectors:
- group: ""
version: "v1"
kind: "Secret"
namespace: mgmt
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
name: transform-tls-secret
spec:
sourceClusterSelector:
matchLabels:
role: mgmt
destinationClusterSelector:
matchLabels:
role: worker
eventSourceName: detect-tls-secret
syncMode: ContinuousWithDriftDetection
policyRefs:
- name: transform-tls-secret
namespace: mgmt
kind: Secret
---
apiVersion: v1
kind: Secret
metadata:
name: transform-tls-secret
namespace: mgmt
annotations:
projectsveltos.io/instantiate: ok
type: Opaque
stringData:
tls-secret.yaml: |
apiVersion: v1
kind: Secret
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
type: {{ .Resource.type }}
data:
{{ range $key, $value := .Resource.data }}
{{ $key }}: {{ $value }}
{{end}} If we must choose between ConfigMap and Secret, using Secret is generally better from both audit logging and RBAC perspectives. |
@kahirokunn I tried again (with version v0.46.0, last time I tried with version v0.45.0) this and it worked for me This worked both when matching Resource has no label, has one label and has more than one label apiVersion: v1
kind: ConfigMap
metadata:
annotations:
projectsveltos.io/instantiate: ok
name: sveltoscluster-metadata
namespace: default
data:
sveltosc-cluster.yaml: |
apiVersion: lib.projectsveltos.io/v1beta1
kind: SveltosCluster
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
{{- if (index .Resource.metadata `labels`) -}}
labels:
{{ range $key, $value := .Resource.metadata.labels }}
{{ $key }}: {{ $value }}
{{ end }}
{{- end -}} which version of Sveltos are you running? |
@kahirokunn if you reference a ConfigMap, then a ConfigMap is created after instantiation. If you reference a Secret (as in your example) a Secret is created after instantiation. The problem with your example is that Secret must be of type type=addons.projectsveltos.io/cluster-profile documentation In other words, Secret referenced by Sveltos custom resources, must be of type=addons.projectsveltos.io/cluster-profile |
I use the |
This format worked well!
it doesn't work. (This is used as a matter of course in helm, so it may be a pitfall. |
#430 (comment) ---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
name: detect-tls-secret
spec:
collectResources: true
resourceSelectors:
- group: ""
version: "v1"
kind: "Secret"
namespace: mgmt
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
name: transform-tls-secret
spec:
sourceClusterSelector:
matchLabels:
role: mgmt
destinationClusterSelector:
matchLabels:
role: worker
eventSourceName: detect-tls-secret
syncMode: ContinuousWithDriftDetection
policyRefs:
- name: transform-tls-secret
namespace: mgmt
kind: Secret
---
apiVersion: v1
kind: Secret
metadata:
name: transform-tls-secret
namespace: mgmt
annotations:
projectsveltos.io/instantiate: ok
type: addons.projectsveltos.io/cluster-profile
stringData:
tls-secret.yaml: |
apiVersion: v1
kind: Secret
metadata:
name: {{ .Resource.metadata.name }}
namespace: {{ .Resource.metadata.namespace }}
type: {{ .Resource.type }}
data:
{{ range $key, $value := .Resource.data }}
{{ $key }}: {{ $value }}
{{end}} However, I get an error like
|
I think this is probably an implementation that has been omitted (because, although I searched through all the source code, I couldn't find any examples of goTemplate or lua being written in Secret). As an implementation, I think it would be enough to just paste the processing done in ConfigMap into Secret as well. |
If Secret works, I believe that ClusterProfile support will be production-grade. |
Thanks @kahirokunn I believe your problem is your are not setting So in your configuration just add this oneForEvent: true apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
name: transform-tls-secret
spec:
oneForEvent: true # add this
sourceClusterSelector:
matchLabels:
role: mgmt
destinationClusterSelector:
matchLabels:
role: worker
eventSourceName: detect-tls-secret
syncMode: ContinuousWithDriftDetection
policyRefs:
- name: transform-tls-secret
namespace: mgmt
kind: Secret I tested it and it works |
Indeed it worked. |
Hello,
Thank you for your work on Sveltos!
I wanted to ask if there are any plans to support multi-cluster ClusterProfiles in Sveltos. For example, aligning with the ClusterProfile API as described in KEP-4322.
The text was updated successfully, but these errors were encountered: