Cluster API Operator

repository·main·Indexed 43 days ago

https://github.com/kubernetes-sigs/cluster-api-operator

A Kubernetes-native operator for the declarative management of Cluster API providers. It enables GitOps-driven lifecycles for Core, Bootstrap, ControlPlane, Infrastructure, Addon, and IPAM providers, facilitating upgrades, downgrades, and support for air-gapped environments via ConfigMap selectors.

Tokens
33.9K
Snippets
108
Records
136
Agent score
55%

What's inside Cluster API Operator

  1. What is Cluster API Operator?

    main

    The Cluster API Operator is a Kubernetes Operator that enables cluster administrators to manage the lifecycle of Cluster API providers in a management cluster using a declarative approach.

    Instead of using imperative commands, you use a declarative API to automate workflows, which is particularly useful for GitOps-driven environments. It extends the capabilities of the clusterctl CLI by providing more flexible configuration options and a way to interact with Cluster API components directly through Kubernetes resources.

  2. Understand Cluster API Operator CI Jobs

    main

    The project uses a combination of Prow, GitHub Actions, and Google Cloud Build to manage continuous integration.

  3. Key features of Cluster API Operator

    main

    The Cluster API Operator provides several capabilities for managing Cluster API providers:

    • Declarative API: Simplifies provider management and enables GitOps workflows.
    • Provider Lifecycle Management: Facilitates provider upgrades and downgrades, making it suitable for distributed teams and CI pipelines.
    • Air-gapped Support: Designed to support environments without direct access to GitHub or GitLab.
    • Flexible Configuration: Leverages the controller-runtime configuration API for setting up Cluster API providers.
    • Transparent Interaction: Provides an effective way to interact with various Cluster API components on the management cluster.
  4. Understand the role of a BootstrapProvider

    main

    A BootstrapProvider is responsible for transforming a server into a functional Kubernetes node. Its primary responsibilities include:

    1. Generating cluster certificates (if not explicitly specified otherwise).
    2. Initializing the control plane and gating the creation of subsequent nodes until initialization is complete.
    3. Joining both control plane and worker nodes to the cluster.
  5. Understand the Cluster API Operator Provider API types

    main

    The Cluster API Operator defines several specialized provider types to manage different aspects of Cluster API. These types are namespaced, which allows for RBAC restrictions and the ability to run multiple versions of controllers simultaneously within the same management cluster by grouping them into different namespaces.

    The primary provider types are:

    • CoreProvider
    • BootstrapProvider
    • ControlPlaneProvider
    • InfrastructureProvider
    • AddonProvider
    • IPAMProvider
  6. Use default fetch configurations via provider naming

    main

    The operator provides sensible defaults for fetching configurations based on the metadata.name of the provider. If you use standard Cluster API provider names such as aws, vsphere, azure, kubeadm, talos, or cluster-api, the operator will automatically fetch configuration from the corresponding official GitHub release URL without requiring an explicit fetchConfig block.

    apiVersion: operator.cluster.x-k8s.io/v1alpha2
    kind: InfrastructureProvider
    metadata:
     name: vsphere
     namespace: capv-system
    spec:
     version: v1.6.1
     configSecret:
       name: vsphere-variables
  7. How Cluster API Provider types work

    main

    The Cluster API Operator manages six types of objects: CoreProvider, BootstrapProvider, ControlPlaneProvider, InfrastructureProvider, AddonProvider, and IPAMProvider.

    Most provider types (Core, Bootstrap, ControlPlane, and Infrastructure) share the same API structure, utilizing ProviderSpec for the desired state and ProviderStatus for the observed state.

    AddonProvider is unique in that it uses AddonProviderSpec and AddonProviderStatus instead of the shared types.

    All provider CRDs are namespaced, which allows for RBAC enforcement and the ability to run multiple versions of different controllers in the same management cluster by grouping them into different namespaces.

  8. Patch provider manifests using the `patches` method

    main

    The spec.patches field is the modern, flexible way to customize provider manifests. Unlike the legacy method, it allows for explicit targeting and supports both strategic merge patches and RFC 6902 JSON patches.

    Each entry in spec.patches consists of a patch (the change to apply) and a target (the selector used to find the object).

    # Strategic merge patch example
    apiVersion: operator.cluster.x-k8s.io/v1alpha2
    kind: CoreProvider
    metadata:
      name: cluster-api
      namespace: capi-system
    spec:
      patches:
        - patch: |
            apiVersion: v1
            kind: Service
            metadata:
              labels:
                test-label: test-value
          target:
            kind: Service
  9. Patch provider manifests using JSON merge patches

    main

    You can modify the provider manifests fetched from a repository by using JSON merge patches within a CoreProvider resource. To do this, populate the spec.manifestPatches field with an array of patch strings.

    Each patch follows these matching rules:

    • Kind matching: The kind field in the patch must match the target object.
    • API Version: If apiVersion is specified in the patch, it will only be applied to objects with a matching apiVersion.
    • Broad application: If metadata.name and metadata.namespace are omitted, the patch is applied to all objects of the specified kind.
    • Cluster-scoped objects: If metadata.name is specified (but not namespace), the patch applies to the object with that name.
    • Specific objects: If both metadata.name and metadata.namespace are specified, the patch applies only to that specific object.

    Patches must follow the RFC 7396 standard for JSON merge patches.

    apiVersion: operator.cluster.x-k8s.io/v1alpha2
    kind: CoreProvider
    metadata:
      name: cluster-api
      namespace: capi-system
    spec:
      manifestPatches:
        - |
          apiVersion: v1
          kind: Service
          metadata:
            labels:
                test-label: test-value