sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/README.md (about) 1 # Cluster API bootstrap provider kubeadm 2 ## What is the Cluster API bootstrap provider kubeadm? 3 4 Cluster API bootstrap provider Kubeadm (CABPK) is a component of 5 [Cluster API](https://github.com/kubernetes-sigs/cluster-api/blob/master/README.md) 6 that is responsible of generating a cloud-init script to 7 turn a Machine into a Kubernetes Node; this implementation uses [kubeadm](https://github.com/kubernetes/kubeadm) 8 for kubernetes bootstrap. 9 10 ### Resources 11 12 * [design doc](https://github.com/kubernetes-sigs/cluster-api/blob/master/docs/proposals/20190610-machine-states-preboot-bootstrapping.md) 13 * [cluster-api.sigs.k8s.io](https://cluster-api.sigs.k8s.io) 14 * [The Kubebuilder Book](https://book.kubebuilder.io) 15 16 ## How to build, deploy and test CABPK 17 CABPK is built using kubebuilder. Please refer to the [The Kubebuilder Book](https://book.kubebuilder.io) for build and deploy in a cluster. 18 19 CABPK is only part of a whole and does not function in isolation. It requires coordination 20 with the core provider, Cluster API (CAPI), and an infrastructure provider; see the [CAEP](https://github.com/kubernetes-sigs/cluster-api/blob/master/docs/proposals/20190610-machine-states-preboot-bootstrapping.md) 21 document for more information. For the remainder of this document we will be referring to 22 [cluster-api-provider-docker](https://github.com/kubernetes-sigs/cluster-api-provider-docker) 23 (CAPD) as our infrastructure provider. 24 25 A convenient way to set up infrastructure for testing is to use [kind](https://kind.sigs.k8s.io/) 26 as the platform cluster to install the controllers and CRDs into. Then use a tool like 27 [tilt](https://tilt.dev/) or [skaffold](ttps://skaffold.dev/) to manage your dev environment. 28 A minimal example of a Tiltfile looks like this: 29 30 ``` 31 allow_k8s_contexts('kubernetes-admin@kubernetes') 32 33 controllers = { 34 'capi': { 35 'path': '../cluster-api', 36 'image': 'gcr.io/k8s-staging-cluster-api/cluster-api-controller:dev', 37 }, 38 'cabpk': { 39 'path': './', 40 'image': 'gcr.io/k8s-staging-cluster-api/cluster-api-bootstrap-provider-kubeadm:dev', 41 }, 42 'capd': { 43 'path': '../cluster-api-provider-docker', 44 'image': 'gcr.io/k8s-staging-cluster-api/cluster-api-provider-docker:dev', 45 }, 46 } 47 48 for name, controller in controllers.items(): 49 command = '''sed -i'' -e 's@image: .*@image: '"{}"'@' ./{}/config/default/manager_image_patch.yaml'''.format(controller['image'], controller['path']) 50 local(command) 51 52 k8s_yaml(local('kustomize build ' + controller['path'] + '/config/default')) 53 54 docker_build(controller['image'], controller['path']) 55 56 ``` 57 58 See [capi-dev](https://github.com/chuckha/capi-dev) for an example of a more complex developemt environment using [tilt](https://tilt.dev/). 59 60 ## How does CABPK work? 61 Once your test environment is in place, create a `Cluster` object and its corresponding `DockerCluster` 62 infrastructure object. 63 64 ```yaml 65 kind: DockerCluster 66 apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 67 metadata: 68 name: my-cluster-docker 69 --- 70 kind: Cluster 71 apiVersion: cluster.x-k8s.io/v1alpha2 72 metadata: 73 name: my-cluster 74 spec: 75 infrastructureRef: 76 kind: DockerCluster 77 apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 78 name: my-cluster-docker 79 ``` 80 81 Now you can start creating machines by defining a `Machine`, its corresponding `DockerMachine` object, and 82 the `KubeadmConfig` bootstrap object. 83 84 ```yaml 85 kind: KubeadmConfig 86 apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2 87 metadata: 88 name: my-control-plane1-config 89 spec: 90 initConfiguration: 91 nodeRegistration: 92 kubeletExtraArgs: 93 eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0% 94 clusterConfiguration: 95 controllerManager: 96 extraArgs: 97 enable-hostpath-provisioner: "true" 98 --- 99 kind: DockerMachine 100 apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 101 metadata: 102 name: my-control-plane1-docker 103 --- 104 kind: Machine 105 apiVersion: cluster.x-k8s.io/v1alpha2 106 metadata: 107 name: my-control-plane1 108 labels: 109 cluster.x-k8s.io/cluster-name: my-cluster 110 cluster.x-k8s.io/control-plane: "true" 111 set: controlplane 112 spec: 113 bootstrap: 114 configRef: 115 kind: KubeadmConfig 116 apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2 117 name: my-control-plane1-config 118 infrastructureRef: 119 kind: DockerMachine 120 apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 121 name: my-control-plane1-docker 122 version: "v1.14.2" 123 ``` 124 125 CABPK's main responsibility is to convert a `KubeadmConfig` bootstrap object into a cloud-init script that is 126 going to turn a Machine into a Kubernetes Node using `kubeadm`. 127 128 The cloud-init script will be saved into the `KubeadmConfig.Status.BootstrapData` and then the infrastructure provider 129 (CAPD in this example) will pick up this value and proceed with the machine creation and the actual bootstrap. 130 131 ### KubeadmConfig objects 132 The `KubeadmConfig` object allows full control of Kubeadm init/join operations by exposing raw `InitConfiguration`, 133 `ClusterConfiguration` and `JoinConfiguration` objects. 134 135 CABPK will fill in some values if they are left empty with sensible defaults: 136 137 | `KubeadmConfig` field | Default | 138 | ----------------------------------------------- | ------------------------------------------------------------ | 139 | `clusterConfiguration.KubernetesVersion` | `Machine.Spec.Version` [1] | 140 | `clusterConfiguration.clusterName` | `Cluster.metadata.name` | 141 | `clusterConfiguration.controlPlaneEndpoint` | `Cluster.status.apiEndpoints[0]` | 142 | `clusterConfiguration.networking.dnsDomain` | `Cluster.spec.clusterNetwork.serviceDomain` | 143 | `clusterConfiguration.networking.serviceSubnet` | `Cluster.spec.clusterNetwork.service.cidrBlocks[0]` | 144 | `clusterConfiguration.networking.podSubnet` | `Cluster.spec.clusterNetwork.pods.cidrBlocks[0]` | 145 | `joinConfiguration.discovery` | a short lived BootstrapToken generated by CABPK | 146 147 > IMPORTANT! overriding above defaults could lead to broken Clusters. 148 149 [1] if both `clusterConfiguration.KubernetesVersion` and `Machine.Spec.Version` are empty, the latest Kubernetes 150 version will be installed (as defined by the default kubeadm behavior). 151 152 #### Examples 153 Valid combinations of configuration objects are: 154 - at least one of `InitConfiguration` and `ClusterConfiguration` for the first control plane node only 155 - `JoinConfiguration` for worker nodes and additional control plane nodes 156 157 Bootstrap control plane node: 158 ```yaml 159 kind: KubeadmConfig 160 apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2 161 metadata: 162 name: my-control-plane1-config 163 spec: 164 initConfiguration: 165 nodeRegistration: 166 kubeletExtraArgs: 167 eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0% 168 clusterConfiguration: 169 controllerManager: 170 extraArgs: 171 enable-hostpath-provisioner: "true" 172 ``` 173 174 Additional control plane nodes: 175 ```yaml 176 kind: KubeadmConfig 177 apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2 178 metadata: 179 name: my-control-plane2-config 180 spec: 181 joinConfiguration: 182 nodeRegistration: 183 kubeletExtraArgs: 184 eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0% 185 controlPlane: {} 186 ``` 187 188 worker nodes: 189 ```yaml 190 kind: KubeadmConfig 191 apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2 192 metadata: 193 name: my-worker1-config 194 spec: 195 joinConfiguration: 196 nodeRegistration: 197 kubeletExtraArgs: 198 eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0% 199 ``` 200 201 ### Bootstrap Orchestration 202 CABPK supports multiple control plane machines initing at the same time. 203 The generation of cloud-init scripts of different machines is orchestrated in order to ensure a cluster 204 bootstrap process that will be compliant with the correct Kubeadm init/join sequence. More in detail: 205 1. cloud-config-data generation starts only after `Cluster.InfrastructureReady` flag is set to `true`. 206 2. at this stage, cloud-config-data will be generated for the first control plane machine even 207 if multiple control plane machines are ready (kubeadm init). 208 3. after `Cluster.metadata.Annotations[cluster.x-k8s.io/control-plane-ready]` is set to true, 209 the cloud-config-data for all the other machines are generated (kubeadm join/join —control-plane). 210 211 ### Certificate Management 212 The user can choose two approaches for certificate management: 213 1. provide required certificate authorities (CAs) to use for `kubeadm init/kubeadm join --control-plane`; such CAs 214 should be provided as a `Secrets` objects in the management cluster. 215 2. let CABPK to generate the necessary `Secrets` objects with a self-signed certificate authority for kubeadm 216 217 TODO: Add more info about certificate secrets 218 219 ### Additional Features 220 The `KubeadmConfig` object supports customizing the content of the config-data: 221 222 - `KubeadmConfig.Files` specifies additional files to be created on the machine 223 - `KubeadmConfig.PreKubeadmCommands` specifies a list of commands to be executed before `kubeadm init/join` 224 - `KubeadmConfig.PostKubeadmCommands` same as above, but after `kubeadm init/join` 225 - `KubeadmConfig.Users` specifies a list of users to be created on the machine 226 - `KubeadmConfig.NTP` specifies NPT settings for the machine 227 228 ## Versioning, Maintenance, and Compatibility 229 230 - We follow [Semantic Versioning (semver)](https://semver.org/). 231 - Cluster API bootstrap provider kubeadm versioning is syncronized with 232 [Cluster API](https://github.com/kubernetes-sigs/cluster-api/blob/master/README.md). 233 - The _master_ branch is where development happens, this might include breaking changes. 234 - The _release-X_ branches contain stable, backward compatible code. A new _release-X_ branch 235 is created at every major (X) release. 236 237 ## Get involved! 238 239 * Join the [Cluster API discuss forum](https://discuss.kubernetes.io/c/contributors/cluster-api). 240 241 * Join the [sig-cluster-lifecycle](https://groups.google.com/forum/#!forum/kubernetes-sig-cluster-lifecycle) 242 Google Group for access to documents and calendars. 243 244 * Join our Cluster API working group sessions 245 * Weekly on Wednesdays @ 10:00 PT on [Zoom][zoomMeeting] 246 * Previous meetings: \[ [notes][notes] | [recordings][recordings] \] 247 248 * Provider implementer office hours 249 * Weekly on Tuesdays @ 12:00 PT ([Zoom][providerZoomMeetingTues]) and Wednesdays @ 15:00 CET ([Zoom][providerZoomMeetingWed]) 250 * Previous meetings: \[ [notes][implementerNotes] \] 251 252 * Chat with us on [Slack](http://slack.k8s.io/): #cluster-api 253 254 [notes]: https://docs.google.com/document/d/1Ys-DOR5UsgbMEeciuG0HOgDQc8kZsaWIWJeKJ1-UfbY/edit 255 [recordings]: https://www.youtube.com/playlist?list=PL69nYSiGNLP29D0nYgAGWt1ZFqS9Z7lw4 256 [zoomMeeting]: https://zoom.us/j/861487554 257 [implementerNotes]: https://docs.google.com/document/d/1IZ2-AZhe4r3CYiJuttyciS7bGZTTx4iMppcA8_Pr3xE/edit 258 [providerZoomMeetingTues]: https://zoom.us/j/140808484 259 [providerZoomMeetingWed]: https://zoom.us/j/424743530