KubeCube Documentation

repository·main·Indexed 19 days ago

https://github.com/kubecube-io/kubecube

KubeCube is an enterprise-grade container platform for visualized management of Kubernetes resources and unified multi-cluster, multi-tenant management. It provides resource isolation via Tenants, Projects, and Spaces, along with observability, application lifecycle management, and a distributed architecture consisting of a central management cluster and Warden agents deployed in business clusters.

Tokens
9.5K
Snippets
33
Records
42
Agent score
65%

What's inside KubeCube

  1. Overview of KubeCube features and capabilities

    main

    KubeCube is an enterprise-level container platform designed for visualized management of Kubernetes resources and unified multi-cluster, multi-tenant management.

    Key capabilities include:

    • Multi-tenant Management: Provides three levels of resource isolation (Tenants, Projects, and Spaces) with associated quota management and RBAC.
    • Multi-Cluster Management: A central management panel to import and manage multiple Kubernetes clusters with unified identity authentication.
    • Cluster Autonomy: Business clusters remain operational and support access control even if the KubeCube service is down for maintenance.
    • Hot Plug Functionality: Allows users to enable or switch functions/plugins at any time without restarting the KubeCube service.
    • Observability: Provides monitoring, alarms, and log collection at both the cluster and application dimensions.
    • Multi-access: Supports an Open API for integration with existing systems and maintains compatibility with Kubernetes native APIs (e.g., kubectl).
  2. Overview of KubeCube capabilities

    main

    KubeCube is an enterprise-grade container platform designed for Kubernetes resource visualization and unified multi-cluster, multi-tenant management. It simplifies application deployment, lifecycle management, and provides monitoring and log auditing interfaces.

    Key Capabilities:

    • Multi-tenant Management: Uses a hierarchical model of Tenants, Projects, and Spaces to provide resource isolation, quota management, and permission control.
    • Multi-Cluster Management: Provides a central management panel for multiple Kubernetes clusters, supporting cluster import and unified identity authentication.
    • Access Control: Extends native Kubernetes RBAC capabilities to provide unified access control across multiple clusters.
    • Plugin Architecture: Features a minimal installation with hot-pluggable functionality that can be enabled or disabled without restarting services.
    • Integration Options: Supports an Open API for custom system integration and remains compatible with native Kubernetes APIs (e.g., kubectl).
    • Cluster Autonomy: Managed clusters can maintain normal access control and business Pod operations even if the KubeCube management cluster is undergoing maintenance.
  3. Understand the KubeCube architecture

    main

    KubeCube follows a distributed architecture consisting of a management cluster and multiple business clusters.

    Core Components:

    • KubeCube Service: The central management component.
    • Warden: An authentication agent deployed in each managed Kubernetes cluster.
    • CloudShell: Provides command-line access to clusters.
    • AuditLog Server: Handles operation auditing.

    Deployment Model:

    • The Warden component is the only part deployed within the individual business clusters.
    • All other components (KubeCube Service, CloudShell, AuditLog Server) are deployed in the central management cluster.
    • The architecture interacts with the Kubernetes API Server, Prometheus for monitoring, and internal log collection components.
  4. How KubeCube architecture works

    main

    KubeCube's architecture is composed of several key components distributed between a management cluster and managed business clusters:

    • KubeCube Service, CloudShell, and AuditLog Server: These components are deployed in the management cluster.
    • Warden: This component is deployed in each managed Kubernetes cluster, acting as an authentication proxy.

    The architecture facilitates interaction between users, the Kubernetes API Server, Prometheus monitoring, and proprietary log collection components.

  5. Quick Start guide for KubeCube

    main

    To get started with KubeCube, follow these steps in order:

    1. Check Environment Requirements: Ensure your infrastructure meets the necessary prerequisites.
    2. All In One Installation: Use the minimized 'All In One' deployment mode for quick setup.
    3. Quick Experience: Follow the guided experience to explore the platform features.
  6. How resource conversion works in the wrapped client

    main

    The conversion wrapper intercepts standard Kubernetes client operations and applies the following logic using a SingleVersionConverter:

    1. Pre-operation (Write/Update/Patch/Delete):

      • The client checks if the object needs conversion via ObjectGreeting.
      • If conversion is required, it calls DirectConvert to transform the object to the recommended version.
      • If convertBack is enabled, after a successful write, the client attempts to convert the resulting object from the server back to the user's original version.
    2. Post-operation (Get/List):

      • The client retrieves the object from the API server.
      • It then converts the retrieved object into the version expected by the user's code using DirectConvert.

    If the converter determines that no conversion is necessary (IsNeedConvert is not returned), the operation proceeds as a standard pass-through to the underlying client.

  7. Configure KubeCube via YAML configuration files

    main

    KubeCube loads its configuration from a YAML file named kubecube.yaml. The system searches for this file in the following locations in order:

    1. /etc/kubecube/kubecube.yaml
    2. The current working directory (./kubecube.yaml)

    Configuration is unmarshaled into a structured CubeOptions object which controls various components including the API Server, Controller Manager, Client Manager, Authentication Manager, and Logger.

    # Example configuration structure (conceptual)
    # The file should be named kubecube.yaml
    
    # Configuration is loaded from:
    # /etc/kubecube/kubecube.yaml
    # or ./kubecube.yaml
  8. Warden configuration structure

    main

    The WardenOptions struct defines the configuration schema for the warden command. It aggregates two primary configuration blocks:

    1. GenericWardenOpts: A *warden.Config object containing the core operational settings for the Warden component.
    2. CubeLoggerOpts: A *clog.Config object used to configure the clog logging system.

    Use NewWardenOptions() to initialize a new options instance with default configurations for both Warden and the logger.

    // Initialize default options
    opts := NewWardenOptions()
  9. Initialize a fake multi-cluster client with NewFakeClientsFor

    main

    Use NewFakeClientsFor to create a mgrclient.Client by providing a customization function. This pattern is useful when you need fine-grained control over the internal fields of the FakerClient (such as discovery or restMapper) that are not exposed via the standard Options struct.

    client := fake.NewFakeClientsFor(func(c *fake.FakerClient) {
        // Customize the FakerClient fields here
        // e.g., c.discovery = myDiscovery
    })
  10. Initialize a fake multi-cluster client with NewFakeClients

    main

    Use NewFakeClients to create a mgrclient.Client implementation for testing multi-cluster operations. This function allows you to pre-populate the fake client with specific Kubernetes objects, lists, and runtime objects using an Options struct. This is useful for simulating a cluster state in unit tests without requiring a real Kubernetes API server.

    opts := &fake.Options{
        Scheme: myScheme,
        Objs:   []client.Object{myObject},
        Lists:  []client.ObjectList{myList},
        ClientRuntimeObjs: []runtime.Object{obj1},
        ClientSetRuntimeObjs: []runtime.Object{obj2},
        MetricsRuntimeObjs: []runtime.Object{metricObj},
    }
    client := fake.NewFakeClients(opts)
  11. Initialize a multi-cluster Client with NewClientFor

    main

    Use NewClientFor to create a Client instance for managing Kubernetes resources. This function initializes a suite of clients including a direct client, a cache, a metrics client, a standard Kubernetes ClientSet, and discovery clients.

    It automatically applies configuration settings (QPS, Burst, Timeout) from the environment via env.GetClusterClientConfig(). If ClusterCacheSyncEnable is true in the cluster configuration, it also starts a background routine to periodically refresh the discovery cache based on ClusterCacheSyncInterval.

    import (
    	"context"
    	"k8s.io/client-go/rest"
    	"github.com/kubecube-io/kubecube/pkg/multicluster/client"
    )
    
    // Assuming cfg is a valid *rest.Config
    ctx := context.Background()
    client, err := client.NewClientFor(ctx, cfg)
    if err != nil {
    	// handle error
    }
    // Use client.Direct() or client.Cache() to interact with the cluster
  12. Wrap a controller-runtime cache for resource conversion

    main

    Use WrapCache to wrap a sigs.k8s.io/controller-runtime/pkg/cache.Cache. The wrapped cache will use a SingleVersionConverter to automatically convert objects retrieved via Get or List operations into the recommended version.

    import (
    	"sigs.k8s.io/controller-runtime/pkg/cache"
    	"github.com/kubecube-io/kubecube/pkg/conversion"
    )
    
    // cac is an existing controller-runtime cache
    // converter is a SingleVersionConverter implementation
    wrappedCache := conversion.WrapCache(cac, converter)