sigs.k8s.io/cluster-api@v1.7.1/docs/book/src/developer/architecture/controllers/control-plane.md (about)

     1  # Control Plane Controller
     2  
     3  ![](../../../images/control-plane-controller.png)
     4  
     5  The Control Plane controller's main responsibilities are:
     6  
     7  * Managing a set of machines that represent a Kubernetes control plane.
     8  * Provide information about the state of the control plane to downstream
     9    consumers.
    10  * Create/manage a secret with the kubeconfig file for accessing the workload cluster.
    11  
    12  A reference implementation is managed within the core Cluster API project as the
    13  Kubeadm control plane controller (`KubeadmControlPlane`). In this document,
    14  we refer to an example `ImplementationControlPlane` where not otherwise specified.
    15  
    16  ## Contracts
    17  
    18  ### Control Plane Provider
    19  
    20  The general expectation of a control plane controller is to instantiate a
    21  Kubernetes control plane consisting of the following services:
    22  
    23  #### Required Control Plane Services
    24  
    25  * etcd
    26  * Kubernetes API Server
    27  * Kubernetes Controller Manager
    28  * Kubernetes Scheduler
    29  
    30  #### Optional Control Plane Services
    31  
    32  * Cloud controller manager
    33  * Cluster DNS (e.g. CoreDNS)
    34  * Service proxy (e.g. kube-proxy)
    35  
    36  #### Prohibited Services
    37  
    38  * CNI - should be left to user to apply once control plane is instantiated.
    39  
    40  ### Relationship to other Cluster API types
    41  
    42  The Cluster controller will set an OwnerReference on the Control Plane. The Control Plane controller should normally take no action during reconciliation until it sees the ownerReference.
    43  
    44  A Control Plane controller implementation should exit reconciliation until it sees `cluster.spec.controlPlaneEndpoint` populated.
    45  
    46  The Cluster controller bubbles up `status.ready` into `status.controlPlaneReady`  and `status.initialized` into a `controlPlaneInitialized` condition from the Control Plane CR.
    47  
    48  The `ImplementationControlPlane` *must* rely on the existence of
    49  `status.controlplaneEndpoint` in its parent [Cluster](./cluster.md) object.
    50  
    51  ### CRD contracts
    52  
    53  The CRD name must have the format produced by `sigs.k8s.io/cluster-api/util/contract.CalculateCRDName(Group, Kind)`.
    54  The same applies for the name of the corresponding ControlPlane template CRD.
    55  
    56  #### Required `spec` fields for implementations using replicas
    57  
    58  * `replicas` - is an integer representing the number of desired
    59    replicas. In the KubeadmControlPlane, this represents the desired
    60    number of control plane machines.
    61  
    62  * `scale` subresource with the following signature:
    63  
    64  ``` yaml
    65  scale:
    66    labelSelectorPath: .status.selector
    67    specReplicasPath: .spec.replicas
    68    statusReplicasPath: .status.replicas
    69  status: {}
    70  ```
    71  
    72  More information about the [scale subresource can be found in the Kubernetes
    73  documentation][scale].
    74  
    75  #### Required `spec` fields for implementations using version
    76  
    77  * `version` - is a string representing the Kubernetes version to be used
    78    by the control plane machines. The value must be a valid semantic version;
    79    also if the value provided by the user does not start with the v prefix, it
    80    must be added.
    81  
    82  #### Required `spec` fields for implementations using Machines
    83  
    84  * `machineTemplate` - is a struct containing details of the control plane
    85    machine template.
    86  
    87  * `machineTemplate.metadata` - is a struct containing info about metadata for control plane
    88    machines.
    89  
    90  * `machineTemplate.metadata.labels` - is a map of string keys and values that can be used
    91    to organize and categorize control plane machines.
    92  
    93  * `machineTemplate.metadata.annotations` - is a map of string keys and values containing
    94    arbitrary metadata to be applied to control plane machines.
    95  
    96  * `machineTemplate.infrastructureRef` - is a corev1.ObjectReference to a custom resource
    97    offered by an infrastructure provider. The namespace in the ObjectReference must
    98    be in the same namespace of the control plane object.
    99  
   100  * `machineTemplate.nodeDrainTimeout` - is a *metav1.Duration defining the total amount of time
   101    that the controller will spend on draining a control plane node.
   102    The default value is 0, meaning that the node can be drained without any time limitations.
   103  
   104  * `machineTemplate.nodeVolumeDetachTimeout` - is a *metav1.Duration defining how long the controller
   105    will spend on waiting for all volumes to be detached.
   106    The default value is 0, meaning that the volume can be detached without any time limitations.
   107  
   108  * `machineTemplate.nodeDeletionTimeout` - is a *metav1.Duration defining how long the controller
   109    will attempt to delete the Node that is hosted by a Machine after the Machine is marked for
   110    deletion. A duration of 0 will retry deletion indefinitely. It defaults to 10 seconds on the
   111    Machine.
   112  
   113  #### Required `status` fields
   114  
   115  The `ImplementationControlPlane` object **must** have a `status` object.
   116  
   117  The `status` object **must** have the following fields defined:
   118  
   119  <table>
   120    <tr>
   121      <th> Field </th>
   122      <th> Type </th>
   123      <th> Description </th>
   124      <th> Implementation in Kubeadm Control Plane Controller </th>
   125    </tr>
   126    <tr>
   127      <td><code>initialized</code></td>
   128      <td>Boolean</td>
   129      <td>
   130        a boolean field that is true when the target cluster has
   131        completed initialization such that at least once, the
   132        target's control plane has been contactable.
   133      </td>
   134      <td>
   135        Transitions to initialized when the controller detects that kubeadm has uploaded
   136        a kubeadm-config configmap, which occurs at the end of kubeadm provisioning.
   137      </td>
   138    </tr>
   139    <tr>
   140      <td><code>ready</code></td>
   141      <td>Boolean</td>
   142      <td>
   143        Ready denotes that the target API Server is ready to receive requests.
   144      </td>
   145      <td></td>
   146    </tr>
   147  </table>
   148  
   149  #### Required `status` fields for implementations using replicas
   150  
   151  Where the `ImplementationControlPlane` has a concept of replicas, e.g. most
   152  high availability control planes, then the `status` object **must** have the
   153  following fields defined:
   154  
   155  <table>
   156    <tr>
   157      <th> Field </th>
   158      <th> Type </th>
   159      <th> Description </th>
   160      <th> Implementation in Kubeadm Control Plane Controller </th>
   161    </tr>
   162    <tr>
   163      <td><code>readyReplicas</code></td>
   164      <td>Integer</td>
   165      <td>Total number of fully running and ready control plane instances.</td>
   166      <td>Is equal to the number of fully running and ready control plane machines</td>
   167    </tr>
   168    <tr>
   169      <td><code>replicas</code></td>
   170      <td>Integer</td>
   171      <td>Total number of non-terminated control plane instances,
   172        i.e. the state machine for this instance
   173        of the control plane is able to transition to ready.</td>
   174      <td>Is equal to the number of non-terminated control plane machines</td>
   175    </tr>
   176    <tr>
   177      <td><code>selector</code></td>
   178      <td>String</td>
   179      <td>`selector` is the label selector in string format to avoid
   180        introspection by clients, and is used to provide the CRD-based integration
   181        for the scale subresource and additional integrations for things like
   182        kubectl describe. The string will be in the same format as the query-param
   183        syntax. More info about label selectors: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
   184      </td>
   185      <td></td>
   186    </tr>
   187    <tr>
   188      <td><code>unavailableReplicas</code></td>
   189      <td>Integer</td>
   190      <td>
   191        Total number of unavailable control plane instances targeted by this control plane, equal
   192        to the desired number of control plane instances - ready instances.
   193      </td>
   194      <td>
   195        Total number of unavailable machines targeted by this control
   196        plane. This is the total number of machines that are still required
   197        for the deployment to have 100% available capacity. They may either
   198        be machines that are running but not yet ready or machines that still
   199        have not been created.
   200      </td>
   201    </tr>
   202    <tr>
   203      <td>
   204        <code>updatedReplicas</code>
   205      </td>
   206      <td>integer</td>
   207      <td>
   208        Total number of non-terminated machines targeted by this
   209        control plane that have the desired template spec.
   210      </td>
   211      <td>
   212        Total number of non-terminated machines targeted by this
   213        control plane that have the desired template spec.
   214      </td>
   215    </tr>
   216  </table>
   217  
   218  #### Required `status` fields for implementations using version
   219  
   220  * `version` - is a string representing the minimum Kubernetes version for the
   221    control plane machines in the cluster.
   222    NOTE: The minimum Kubernetes version, and more specifically the API server
   223    version, will be used to determine when a control plane is fully upgraded
   224    (`spec.version == status.version`) and for enforcing [Kubernetes version
   225    skew policies](https://kubernetes.io/releases/version-skew-policy/) in managed topologies.
   226  
   227  #### Optional `status` fields
   228  
   229  The `status` object **may** define several fields:
   230  
   231  * `failureReason` - is a string that explains why an error has occurred, if possible.
   232  * `failureMessage` - is a string that holds the message contained by the error.
   233  * `externalManagedControlPlane` - is a bool that should be set to true if the Node objects do not
   234    exist in the cluster. For example, managed control plane providers for AKS, EKS, GKE, etc, should
   235    set this to `true`. Leaving the field undefined is equivalent to setting the value to `false`.
   236  
   237  ## Example usage
   238  
   239  ```yaml
   240  apiVersion: controlplane.cluster.x-k8s.io/v1beta1
   241  kind: KubeadmControlPlane
   242  metadata:
   243    name: kcp-1
   244    namespace: default
   245  spec:
   246    machineTemplate:
   247      infrastructureRef:
   248        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
   249        kind: DockerMachineTemplate
   250        name: docker-machine-template-1
   251        namespace: default
   252    replicas: 3
   253    version: v1.21.2
   254  ```
   255  
   256  [scale]: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#scale-subresource
   257  
   258  ## Kubeconfig management
   259  
   260  Control Plane providers are expected to create and maintain a Kubeconfig
   261  secret for operators to gain initial access to the cluster.
   262  The given secret must be labelled with the key-pair `cluster.x-k8s.io/cluster-name=${CLUSTER_NAME}`
   263  to make it stored and retrievable in the cache used by CAPI managers. If a provider uses
   264  client certificates for authentication in these Kubeconfigs, the client
   265  certificate should be kept with a reasonably short expiration period and
   266  periodically regenerated to keep a valid set of credentials available. As an
   267  example, the Kubeadm Control Plane provider uses a year of validity and
   268  refreshes the certificate after 6 months.