sigs.k8s.io/cluster-api@v1.7.1/docs/proposals/20230407-flexible-managed-k8s-endpoints.md (about)

     1  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
     2  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
     3  **Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*
     4  
     5  - [Flexible Managed Kubernetes Endpoints](#flexible-managed-kubernetes-endpoints)
     6    - [Glossary](#glossary)
     7    - [Summary](#summary)
     8    - [Motivation](#motivation)
     9      - [Goals](#goals)
    10      - [Non-Goals](#non-goals)
    11      - [Future Work](#future-work)
    12    - [Proposal](#proposal)
    13      - [User Stories](#user-stories)
    14        - [Story 1](#story-1)
    15        - [Story 2](#story-2)
    16        - [Story 3](#story-3)
    17        - [Story 4](#story-4)
    18        - [Story 5](#story-5)
    19        - [Story 6](#story-6)
    20        - [Story 7](#story-7)
    21      - [Design](#design)
    22        - [Core Cluster API changes](#core-cluster-api-changes)
    23        - [Infra Providers API changes](#infra-providers-api-changes)
    24        - [Core Cluster API Controllers changes](#core-cluster-api-controllers-changes)
    25        - [Provider controller changes](#provider-controller-changes)
    26      - [Guidelines for infra providers implementation](#guidelines-for-infra-providers-implementation)
    27    - [Implementation History](#implementation-history)
    28  
    29  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
    30  
    31  ---
    32  title: Flexible Managed Kubernetes Endpoints
    33  authors:
    34    - "@jackfrancis"
    35  reviewers:
    36    - "@richardcase"
    37    - "@pydctw"
    38    - "@mtougeron"
    39    - "@CecileRobertMichon"
    40    - "@fabriziopandini"
    41    - "@sbueringer"
    42    - "@killianmuldoon"
    43    - "@mboersma"
    44    - "@nojnhuh"
    45  creation-date: 2023-04-07
    46  last-updated: 2023-04-07
    47  status: provisional
    48  see-also:
    49    - "/docs/proposals/20220725-managed-kubernetes.md"
    50  ---
    51  
    52  # Flexible Managed Kubernetes Endpoints
    53  
    54  ## Glossary
    55  
    56  Refer to the [Cluster API Book Glossary](https://cluster-api.sigs.k8s.io/reference/glossary.html).
    57  
    58  The following terms will be used in this document.
    59  
    60  - Managed Kubernetes
    61    - Managed Kubernetes refers to any Kubernetes Cluster provisioning and maintenance abstraction, usually exposed as an API, that is natively available in a Cloud provider. For example: [EKS](https://aws.amazon.com/eks/), [OKE](https://www.oracle.com/cloud/cloud-native/container-engine-kubernetes/), [AKS](https://azure.microsoft.com/en-us/products/kubernetes-service), [GKE](https://cloud.google.com/kubernetes-engine), [IBM Cloud Kubernetes Service](https://www.ibm.com/cloud/kubernetes-service), [DOKS](https://www.digitalocean.com/products/kubernetes), and many more throughout the Kubernetes Cloud Native ecosystem.
    62  - `ControlPlane Provider`
    63    - When we say `ControlPlane Provider` we refer to a solution that implements a solution for the management of a Kubernetes [control plane](https://kubernetes.io/docs/concepts/#kubernetes-control-plane) according to the Cluster API contract. Please note that in the context of managed Kubernetes, the `ControlPlane Provider` usually wraps the corresponding abstraction for a specific Cloud provider. Concrete example for Microsoft Azure is the `AzureManagedControlPlane`, for AWS the `AWSManagedControlPlane`, for Google the `GCPManagedControlPlane` etc.
    64  - _Kubernetes Cluster Infrastructure_
    65    - When we refer to _Kubernetes Cluster Infrastructure_ (abbr. _Cluster Infrastructure_) we refer to the **infrastructure that supports a Kubernetes cluster**, like e.g. VPC, security groups, load balancers etc. Please note that in the context of Managed Kubernetes some of those components are going to be provided by the corresponding abstraction for a specific Cloud provider (EKS, OKE, AKS etc), and thus Cluster API should not take care of managing a subset or all those components.
    66  - `<Infra>Cluster`
    67    - When we say `<Infra>Cluster` we refer to any provider that provides Kubernetes Cluster Infrastructure for a specific Cloud provider. Concrete example for Microsoft Azure is the `AzureCluster` and the `AzureManagedCluster`, for AWS the `AWSCluster` and the `AWSManagedCluster`, for Google Cloud the `GCPCluster` and the `GCPManagedCluster`).
    68  - e.g.
    69    - This just means "For example:"!
    70  
    71  ## Summary
    72  
    73  This proposal aims to address the lesson learned by running Managed Kubernetes solution on top of Cluster API, and make this use case simpler and more straight forward both for Cluster API users and for the maintainers of the Cluster API providers.
    74  
    75  More specifically we would like to introduce first class support for two scenarios:
    76  
    77  - Permit omitting the `<Infra>Cluster` entirely, thus making it simpler to use with Cluster API all the Managed Kubernetes implementations which do not require any additional Kubernetes Cluster Infrastructure (network settings, security groups, etc) on top of what is provided out of the box by the managed Kubernetes primitive offered by a Cloud provider.
    78  - Allow the `ControlPlane Provider` component to take ownership of the responsibility of creating the control plane endpoint, thus making it simpler to use with Cluster API all the Managed Kubernetes implementations which are taking care out of the box of this piece of Cluster Infrastructure.
    79  
    80  The above capabilities can be used alone or in combination depending on the requirements of a specific Managed Kubernetes or on the specific architecture/set of Cloud components being implemented.
    81  
    82  ## Motivation
    83  
    84  The implementation of Managed Kubernetes scenarios by Cluster API providers occurred after the architectural design of Cluster API, and thus that design process did not consider these Managed Kubernetes scenarios as a user story. In practice, Cluster API's specification has allowed Managed Kubernetes solutions to emerge that aid running fleets of clusters at scale, with CAPA's `AWSManagedCluster` and `AzureManagedCluster` being notable examples. However, because these Managed Kubernetes solutions arrived after the Cluster API contract was defined, providers have not settled on a consistent rendering of how a "Service-Managed Kubernetes" specification fits into a "Cluster API-Managed Kubernetes" surface area.
    85  
    86  One particular part of the existing Cluster API surface area that is inconsistent with most Managed Kubernetes user experiences is the accounting of the [Kubernetes API server](https://kubernetes.io/docs/concepts/overview/components/#kube-apiserver). In the canonical "self-managed" user story that Cluster API addresses, it is the provider implementation of Cluster API (e.g., CAPA) that is responsible for scaffolding the necessary _Kubernetes Cluster Infrastructure_ that is required in order to create the Kubernetes API server (e.g., a Load Balancer and a public IP address). This provider responsibility is declared in the `<Infra>Cluster` resource, and carried out via its controllers; and then finally this reconciliation is synchronized with the parent `Cluster` Cluster API resource.
    87  
    88  Because there exist Managed Kubernetes scenarios that handle a subset or all _Kubernetes Cluster Infrastructure_ responsibilities themselves, Cluster API's requirement of a `<Infra>Cluster` resource leads to undesirable implementation decisions, because in these scenarios there is no actual work for a Cluster API provider to do to scaffold _Kubernetes Cluster Infrastructure_.
    89  
    90  Finally, for Managed Kubernetes scenarios that _do_ include additional, user-exposed infra (e.g., GKE and EKS as of this writing), we want to make it easier to account for the representation of the Managed Kubernetes API server endpoint, which is not always best owned by a `<Infra>Cluster` resource.
    91  
    92  ### Goals
    93  
    94  - Build upon [the existing Cluster API Managed Kubernetes proposal](https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20220725-managed-kubernetes.md). Any net new recommendations and/or proposals will be a continuation of the existing proposal, and consistent with its original conclusions.
    95  - Identify and document API changes and controllers changes required to omit the `<Infra>Cluster` entirely, where this is applicable.
    96  - Identify and document API changes and controllers changes required to allow the `ControlPlane Provider` component to take ownership of the responsibility of creating the control plane endpoint.
    97  - Ensure any changes to the current behavioral contract are backwards-compatible.
    98  
    99  ### Non-Goals
   100  
   101  - Introduce new "Managed Kubernetes" data types in Cluster API.
   102  - Invalidate [the existing Cluster API Managed Kubernetes proposal and concluding recommendations](https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20220725-managed-kubernetes.md).
   103  
   104  ### Future Work
   105  
   106  - Detailed documentation that references the flavors of Managed Kubernetes scenarios and how they can be implemented in Cluster API, with provider examples.
   107  
   108  ## Proposal
   109  
   110  ### User Stories
   111  
   112  #### Story 1
   113  
   114  As a cluster operator, I want to use Cluster API to provision and manage the lifecycle of a control plane that utilizes my service provider's managed Kubernetes control plane (i.e. EKS, AKS, GKE), so that I don’t have to worry about the management/provisioning of control plane nodes, and so I can take advantage of any value add services offered by my cloud provider.
   115  
   116  #### Story 2
   117  
   118  As a cluster operator, I want to be able to provision both "unmanaged" and "managed" Kubernetes clusters from the same management cluster, so that I can support different requirements and use cases as needed whilst using a single operating model.
   119  
   120  #### Story 3
   121  
   122  As a Cluster API provider implementor, I want to be able to return the control plane endpoint created by the `ControlPlane Provider`, so that it fits naturally with how most of the native Managed Kubernetes implementations works.
   123  
   124  #### Story 4
   125  
   126  As a Cluster API provider developer, I want guidance on how to incorporate a managed Kubernetes service into my provider, so that its usage is compatible with Cluster API architecture/features and its usage is consistant with other providers.
   127  
   128  #### Story 5
   129  
   130  As a Cluster API provider developer, I want to enable the ClusterClass feature for a Managed Kubernetes service, so that users can take advantage of an improved UX with ClusterClass-based clusters.
   131  
   132  #### Story 6
   133  
   134  As a cluster operator, I want to use Cluster API to provision and manage the lifecycle of worker nodes that utilizes my cloud providers' managed instances (if they support them), so that I don't have to worry about the management of these instances.
   135  
   136  #### Story 7
   137  
   138  As a service provider I want to be able to offer Managed Kubernetes clusters by using CAPI referencing my own managed control plane implementation that satisfies Cluster API contracts.
   139  
   140  ### Design
   141  
   142  Below we are documenting API changes and controllers changes required to omit the `<Infra>Cluster` entirely and to allow the `ControlPlane Provider` component  to take ownership of the responsibility of creating the control plane endpoint.
   143  
   144  #### Core Cluster API changes
   145  
   146  This proposal does not introduce any breaking changes for the existing "core" API. More specifically:
   147  
   148  The existing Cluster API types are already able to omit the `<Infra>Cluster`:
   149  
   150  - The `infrastructureRef` field on the Cluster object is already a pointer and thus it could be set to nil, and in fact we are already creating Clusters without `infrastructureRef` when we use a cluster class).
   151  - The `infrastructure.Ref` field on the ClusterClass objects already a pointer and thus it could be set to nil, but in this case it is required to change the validation webhook to allow the user to not specify it; on top of that, when validating inline patches, we should reject patches targeting the infrastructure template objects if not specified.
   152  
   153  In order to allow the `ControlPlane Provider` component to take ownership of the responsibility of creating the control plane endpoint we are going to introduce a new `ClusterEndpoint` CRD, below some example:
   154  
   155  ```yaml
   156  apiVersion: cluster.x-k8s.io/v1beta1
   157  kind: ClusterEndpoint
   158  metadata:
   159     labels:
   160        cluster.x-k8s.io/cluster-name: my-cluster
   161  spec:
   162    cluster: my-cluster
   163    host: "my-cluster-1234567890.region.elb.amazonaws.com"
   164    port: 1234
   165    type: ExternalControlPlaneEndpoint
   166  ```
   167  
   168  ```yaml
   169  apiVersion: cluster.x-k8s.io/v1beta1
   170  kind: ClusterEndpoint
   171  metadata:
   172     labels:
   173        cluster.x-k8s.io/cluster-name: my-cluster-2
   174  spec:
   175    cluster: my-cluster-2
   176    host: "10.40.85.102"
   177    port: 1234
   178    type: ExternalControlPlaneEndpoint
   179  ```
   180  
   181  This is how the type specification would look:
   182  
   183  ```go
   184  // ClusterEndpointType describes the type of cluster endpoint.
   185  type ClusterEndpointType string
   186  
   187  // ClusterEndpoint represents a reachable Kubernetes API endpoint serving a particular cluster function.
   188  type ClusterEndpoint struct {
   189    metav1.TypeMeta   `json:",inline"`
   190  	metav1.ObjectMeta `json:"metadata,omitempty"`
   191  
   192    Spec ClusterEndpointSpec   `json:"spec,omitempty"`
   193  }
   194  
   195  // ClusterEndpointSpec defines the desired state of the Cluster endpoint.
   196  type ClusterEndpointSpec struct {
   197  	// The Host is the DNS record or the IP address that the endpoint is reachable on.
   198  	Host string `json:"host"`
   199  
   200  	// The port on which the endpoint is serving.
   201  	Port int32 `json:"port"`
   202  
   203    // Cluster is a reference to the cluster name that this endpoint is reachable on.
   204    Cluster string `json:"cluster"`
   205  
   206    // Type describes the function that this cluster endpoint serves.
   207    // +kubebuilder:validation:Enum=apiserver
   208    Type ClusterEndpointType `json:"type"`
   209  }
   210  ```
   211  
   212  The `<Infra>Cluster` object which is currently using the `spec.controlPlaneEndpoint` for the same scope will continue to work because "core" Cluster API controllers will continue to recognize when this field is set and take care of generating the `ClusterEndpoint` automatically; however this mechanism should be considered as a temporary machinery to migrate to the new CRD, and it will be removed in future versions of Cluster API. In addition, once the legacy behavior is removed, we will deprecate and eventually remove the `spec.controlPlaneEndpoint` field from the `Cluster` CustomResourceDefinition, and recommend that providers do the same for their `<Infra>Cluster` CustomResourceDefinitions as well.
   213  
   214  Future Notes:
   215  
   216  - A future `type` field can be introduced to enable CAPI to extend the usage of this CRD to address https://github.com/kubernetes-sigs/cluster-api/issues/5295 in a future iteration
   217  - The current implementation originates from the `Cluster.spec.ControlPlaneEndpoint` field, which defines the info we need for this proposal; but in future iterations we might consider to support more addressed or more ports for each ClusterEndpoint, similarly what is implemented in the core v1 Endpoint type.
   218  
   219  #### Infra Providers API changes
   220  
   221  This proposal does not introduce any breaking changes for the provider's API.
   222  
   223  However, Infra providers will be made aware that `spec.controlPlaneEndpoint` will be scheduled for deprecation in `<Infra>Cluster` resources in a future CAPI API version, with corresponding warning messages in controller logs. We will recommend that they remove it in a future API version of their provider.
   224  
   225  #### Core Cluster API Controllers changes
   226  
   227  - All the controllers working with ClusterClass objects must take into account that the `infrastructure.Ref` field could be omitted; most notably:
   228    - The ClusterClass controller must ignore nil `infrastructure.Ref` fields while adding owner references to all the objects referenced by a ClusterClass.
   229    - The Topology controller must skip the generation of the `<Infra>Cluster` objects when the `infrastructure.Ref` field in a ClusterClass is empty.
   230  
   231  - All the controllers working with Cluster objects must take into account that the `infrastructureRef` field could be omitted; most notably:
   232    - The Cluster controller must use skip reconciling this external reference when the `infrastructureRef` is missing; also, the `status.InfrastructureReady` field must be automatically set to true in this case.
   233  
   234  - A controller (details TBD) will reconcile the new `ClusterEndpoint` CR. Please note that:
   235    - The value from the `ClusterEndpoint` CRD must surface on the `spec.ControlPlaneEndpoint` field on the `Cluster` object.
   236    - If both are present, the value from the `ClusterEndpoint` CRD must take precedence on the value from `<Infra>Cluster` objects still using the `spec.controlPlaneEndpoint`.
   237  
   238  - The Cluster controller must implement the temporary machinery to migrate to the new CRD existing Clusters and to deal with `<Infra>Cluster` objects still using the `spec.controlPlaneEndpoint` field as a way to communicate the ClusterAddress to "core" Cluster API controllers:
   239    - If there is the `spec.ControlPlaneEndpoint` on the `Cluster` object but not a corresponding `ClusterEndpoint` CR, the CR must be created.
   240  
   241  #### Provider controller changes
   242  
   243  - All the `<Infra>Cluster` controllers who are responsible for creating a control plane endpoint
   244    - As soon as the `spec.controlPlaneEndpoint` field in the `<Infra>Cluster` object will removed, the `<Infra>Cluster` controller must instead create a `ClusterEndpoint` CR to communicate the control plane endpoint to the Cluster API core controllers
   245      - NOTE: technically it is possible to start creating the `ClusterEndpoint` CR *before* the removal of the `spec.controlPlaneEndpoint` field, because the new CR will take precedence on the value read from the field, but this is up to the infra provider maintainers.
   246    - The `ClusterEndpoint` CR must have an owner reference to the `<Infra>Cluster` object from which it is originated.
   247  
   248  - All the `ControlPlane Provider` controllers who are responsible for creating a control plane endpoint
   249    - Must no longer wait for the `spec.ControlPlaneEndpoint` field on the `Cluster` object to be set before starting to provision the control plane.
   250    - As soon as the Managed Kubernetes Service-provided control plane endpoint is available, the controller must create a `ClusterEndpoint` CR to communicate this to the control plane endpoint to the Cluster API core controllers
   251    - The `ClusterEndpoint` CR must have an owner reference to the `ControlPlane` object from which is originated.
   252  
   253  ### Guidelines for infra providers implementation
   254  
   255  Let's consider following scenarios for an hypothetical `cluster-api-provider-foo` infra provider:
   256  
   257  _Scenario 1._
   258  
   259  If the `Foo` cloud provider has a `FKS` managed Kubernetes offering that is taking care of _the entire Kubernetes Cluster infrastructure_, the maintainers of the `cluster-api-provider-foo` provider:
   260  - Must not implement a `FKSCluster` CRD and the corresponding `FKSClusterTemplate` CRD (nor the related controllers)
   261  - Must implement a `FKRControlControlplane provider`, a `FKRControlControlplane` CRD, the corresponding `FKRControlControlplane` and related controllers
   262  - The `FKRControlControlplane` controller:
   263    - Must not wait for `spec.ControlPlaneEndpoint` field on the `Cluster` object to be set before starting to provision the `FKS` managed Kubernetes instance.
   264    - As soon as the control plane endpoint is available, Must create a `ClusterEndpoint` CR to communicate the control plane endpoint to the Cluster API core controllers; the `ClusterEndpoint` CR must have an owner reference to the `FKRControlControlplane` object from which is originated.
   265    - Must set the `status.Ready` field on the `FKRControlControlplane` object when the provisioning is complete
   266  
   267  _Scenario 2._
   268  
   269  If the `Foo` cloud provider has a `FKS` managed Kubernetes offering that is taking care of _only of a subset of the Kubernetes Cluster infrastructure_, or it is required to provision some additional pieces of infrastructure on top of what provisioned out of the box, e.g. a SSH bastion host, the maintainers of the `cluster-api-provider-foo` provider:
   270  - Must implement a `FKSCluster` CRD and the corresponding `FKSClusterTemplate` CRD and the related controllers
   271    - The `FKSCluster` controller
   272      - Must create only the additional piece of the _Kubernetes Cluster infrastructure_ not provisioned by the `FKS` managed Kubernetes instance (in this example a SSH bastion host)
   273      - Must not create a `ClusterEndpoint` CR (nor set the `spec.controlPlaneEndpoint` field in the `FKSCluster` object), because provisioning the control plane endpoint is not responsibility of this controller.
   274      - Must set the `status.Ready` field on the `FKSCluster` object when the provisioning is complete
   275  - Must implement a `FKRControlControlplane provider`, a `FKRControlControlplane` CRD, the corresponding `FKRControlControlplane` and related controllers
   276    - The `FKRControlControlplane` controller:
   277      - Must wait for `status.InfrastructureReady` field on the `Cluster` object to be set to true before starting to provision the control plane.
   278      - Must not wait for `spec.ControlPlaneEndpoint` field on the `Cluster` object to be set before starting to provision the control plane.
   279      - As soon as the control plane endpoint is available, Must create a `ClusterEndpoint` CR to communicate the control plane endpoint to the Cluster API core controllers; the `ClusterEndpoint` CR must have an owner reference to the `FKRControlControlplane` object from which is originated.
   280      - Must set the `status.Ready` field on the `FKRControlControlplane` object when the provisioning is complete
   281  
   282  _Scenario 3._
   283  
   284  If the `Foo` cloud provider has a `FKS` managed Kubernetes offering that is not taking care of the control plane endpoint e.g. because it requires an existing `FooElasticIP`, a `FooElacticLoadBalancer` to be provisioned before creating the `FKS` managed Kubernetes cluster, the maintainers of the `cluster-api-provider-foo` provider:
   285  - Must implement a `FKSCluster` CRD and the corresponding `FKSClusterTemplate` CRD and the related controllers; those controllers must create a `ClusterEndpoint` CR as soon as the control plane endpoint is available
   286    - The `FKSCluster` controller
   287      - Must create only the additional piece of the _Kubernetes Cluster infrastructure_ not provisioned by the `FKS` managed Kubernetes instance (in this example `FooElasticIP`, a `FooElacticLoadBalancer`)
   288      - As soon as the control plane endpoint is available, Must create a `ClusterEndpoint` CR; the `ClusterEndpoint` CR must have an owner reference to the `FKSCluster` object from which is originated.
   289      - Must set the `status.Ready` field on the `FKSCluster` object when the provisioning is complete
   290  - Must implement a `FKRControlControlplane provider`, a `FKRControlControlplane` CRD, the corresponding `FKRControlControlplane` and related controllers
   291    - The `FKRControlControlplane` controller:
   292      - Must wait for `status.InfrastructureReady` field on the `Cluster` object to be set to true before starting to provision the `FKS` managed Kubernetes instance.
   293      - Must wait for `spec.ControlPlaneEndpoint` field on the `Cluster` object to be set before starting to provision the `FKS` managed Kubernetes instance.
   294      - Must set the `status.Ready` field on the `FKRControlControlplane` object when the provisioning is complete
   295  
   296  Please note that this scenario is equivalent to what is implemented for a non managed Kubernetes `FooCluster`, backed by Cluster API managed `FooMachines`, with the only difference that in this case it possible to rely on `KCP` as `ControlControlplane provider`, and thus point 2 of the above list do not apply.
   297  
   298  ## Implementation History
   299  
   300  - [x] 01/11/2023: Compile a Google Doc to organize thoughts prior to CAEP [link here](https://docs.google.com/document/d/1rqzZfsO6k_RmOHUxx47cALSr_6SeTG89e9C44-oHHdQ/)
   301  
   302  [managedKubernetesRecommendation]: https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20220725-managed-kubernetes.md#option-3-two-kinds-with-a-managed-control-plane-and-managed-infra-cluster-with-better-separation-of-responsibilities