Skip to content

Commit 5093714

Browse files
authored
Merge pull request #1353 from salasberryfin/improve-book-structure
Improve book structure and add clusterclass examples
2 parents 902e324 + 899e336 commit 5093714

File tree

18 files changed

+372
-64
lines changed

18 files changed

+372
-64
lines changed

docs/book/src/SUMMARY.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Summary
22

33
[Introduction](./introduction.md)
4-
- [Getting Started](./getting-started.md)
5-
- [Topics](./topics/index.md)
6-
- [Prerequisites](./topics/prerequisites.md)
4+
- [Quick Start](./quick-start.md)
5+
- [Prerequisites](./prerequisites.md)
6+
- [Self-managed clusters](./self-managed/index.md)
7+
- [Provisioning a Cluster](./self-managed/provision.md)
8+
- [CNI](./self-managed/cni.md)
9+
- [Managed clusters - GKE](./managed/index.md)
10+
- [Provisioning a Cluster](./managed/provision.md)
11+
- [Cluster Upgrades](./managed/upgrades.md)
12+
- [Enabling](./managed/enabling.md)
13+
- [Disabling](./managed/disabling.md)
14+
- [ClusterClass](./clusterclass/index.md)
15+
- [Provisioning a Cluster](./clusterclass/provision.md)
16+
- [Enabling](./clusterclass/enabling.md)
17+
- [Disabling](./clusterclass/disabling.md)
18+
- [General Topics](./topics/index.md)
719
- [Conformance](./topics/conformance.md)
8-
- [GKE Support](./topics/gke/index.md)
9-
- [Creating a Cluster](./topics/gke/creating-a-cluster.md)
10-
- [Cluster Upgrades](./topics/gke/cluster-upgrades.md)
11-
- [Enabling](./topics/gke/enabling.md)
12-
- [Disabling](./topics/gke/disabling.md)
1320
- [Machine Locations](./topics/machine-locations.md)
1421
- [Preemptible VMs](./topics/preemptible-vms.md)
15-
- [Flannel](./topics/flannel.md)
1622
- [Developer Guide](./developers/index.md)
1723
- [Development](./developers/development.md)
1824
- [Try unreleased changes with Nightly Builds](./developers/nightlies.md)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Disabling ClusterClass Support
2+
3+
Support for ClusterClass is disabled by default when you use the GCP infrastructure provider.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Enabling ClusterClass Support
2+
3+
Enabling ClusterClass support is done via the **ClusterTopology** feature flag by setting it to true. This can be done before running `clusterctl init` by using the **CLUSTER_TOPOLOGY** environment variable:
4+
5+
```shell
6+
export CLUSTER_TOPOLOGY=true
7+
clusterctl init --infrastructure gcp
8+
```

docs/book/src/clusterclass/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ClusterClass
2+
3+
- **Feature status:** Experimental
4+
- **Feature gate:** `ClusterTopology=true`
5+
6+
[ClusterClass](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/index.html) is a collection of templates that define a topology (control plane and machine deployments) to be used to continuously reconcile one or more Clusters. It is built on top of the existing Cluster API resources and provides a set of tools and operations to streamline cluster lifecycle management while maintaining the same underlying API.
7+
8+
<aside class="note warning">
9+
10+
<h1>Warning</h1>
11+
12+
ClusterClass is an experimental core CAPI feature and, as such, it may behave unreliably until promoted to the main repository. It is expected to be graduated with the release of [CAPI v1.9](https://github.com/kubernetes-sigs/cluster-api/milestone/38).
13+
14+
</aside>
15+
16+
CAPG supports the creation of clusters via Cluster Topology for **self-managed clusters only**.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Provisioning a Cluster via ClusterClass
2+
3+
<aside class="note warning">
4+
5+
<h1>Warning</h1>
6+
7+
We recommend you take a look at the [Prerequisites](./../prerequisites.md) section before provisioning a workload cluster.
8+
9+
**You should be familiar with the ClusterClass feature and its core concepts: [CAPI book on ClusterClass and Managed Topologies](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/write-clusterclass).**
10+
11+
</aside>
12+
13+
14+
**This guide uses an example from the `./templates` folder of the CAPG repository. You can inspect the yaml file for the `ClusterClass` [here](https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-gcp/refs/heads/main/templates/cluster-template-clusterclass.yaml) and the cluster definition [here](https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-gcp/refs/heads/main/templates/cluster-template-topology.yaml).**
15+
16+
17+
## Templates and clusters
18+
19+
ClusterClass makes cluster templates more flexible and versatile as it allows users to create cluster flavors that can be reused for cluster provisioning.
20+
21+
In this case, while inspecting the sample files, you probably noticed that there are references to two different yaml:
22+
- `./templates/cluster-template-clusterclass.yaml` is the class definition. It represents the template that define a topology: control plane and machine deployment but it won't provision the cluster.
23+
- `./templates/cluster-template-topology.yaml` is the cluster definition that references the class. This workload cluster definition is considerably simpler than a regular CAPI cluster template that does not use ClusterClass, as most of the complexity of defining the control plane and machine deployment has been removed by the class.
24+
25+
## Configure ClusterClass
26+
27+
While inspecting the templates you probably noticed that they contain a number of parameterized values that must be substituted with the specifics of your use case. This can be done via environment variables and `clusterctl` and effectively make the templates more flexible to adapt to different provisioning scenarios. These are the environment variables that you'll be required to set before deploying a class and a workload cluster from it:
28+
29+
```sh
30+
export CLUSTER_CLASS_NAME=sample-cc
31+
export GCP_PROJECT=cluster-api-gcp-project
32+
export GCP_REGION=us-east4
33+
export GCP_NETWORK_NAME=default
34+
export IMAGE_ID=projects/cluster-api-gcp-project/global/images/your-image
35+
```
36+
37+
## Generate ClusterClass definition
38+
39+
The sample ClusterClass template is already prepared so that you can use it with `clusterctl` to create a CAPI ClusterClass with CAPG.
40+
41+
```bash
42+
clusterctl generate cluster capi-gcp-quickstart-clusterclass --flavor clusterclass -i gcp > capi-gcp-quickstart-clusterclass.yaml
43+
```
44+
45+
In this example, `capi-gcp-quickstart-clusterclass` will be used as class name.
46+
47+
## Create ClusterClass
48+
49+
The resulting file represents the class template definition and you simply need to apply it to your cluster to make it available in the API:
50+
51+
```
52+
kubectl apply -f capi-gcp-quickstart-clusterclass.yaml
53+
```
54+
55+
## Create a cluster from a class
56+
57+
ClusterClass is a powerful feature of CAPI because we can now create one or multiple clusters that are based on the same class that is available in the CAPI Management Cluster. This base template can be parameterized so clusters created from it can make slight changes to the original configuration and adapt to the specifics of the use case, e.g. provisioning clusters for different development, staging and production environments.
58+
59+
Now that the class is available to be referenced by cluster objects, let's configure the workload cluster and provision it.
60+
61+
```sh
62+
export CLUSTER_NAME=sample-cluster
63+
export CLUSTER_CLASS_NAME=sample-cc
64+
export KUBERNETES_VERSION=1.29.3
65+
export CONTROL_PLANE_MACHINE_COUNT=1
66+
export WORKER_MACHINE_COUNT=1
67+
export GCP_REGION=us-east4
68+
export GCP_CONTROL_PLANE_MACHINE_TYPE=n1-standard-2
69+
export GCP_NODE_MACHINE_TYPE=n1-standard-2
70+
export CNI_RESOURCES=./cni-resource
71+
```
72+
73+
You can take a look at CAPG's CNI requirements [here](./../self-managed/cni.md)
74+
75+
You can use `clusterctl` to create a cluster definition.
76+
77+
```bash
78+
clusterctl generate cluster capi-gcp-quickstart-topology --flavor topology -i gcp > capi-gcp-quickstart-topology.yaml
79+
```
80+
81+
And by simply applying the resulting template, the cluster will be provisioned based on the existing ClusterClass.
82+
83+
```
84+
kubectl apply -f capi-gcp-quickstart-topology.yaml
85+
```
86+
87+
You can now experiment with creating more clusters based on this class while applying different configurations to each workload cluster.

docs/book/src/getting-started.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.
File renamed without changes.

docs/book/src/topics/gke/index.md renamed to docs/book/src/managed/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
- **Feature status:** Experimental
44
- **Feature gate (required):** GKE=true
55

6+
<aside class="note warning">
7+
8+
<h1>Warning</h1>
9+
10+
Provisioning managed clusters (GKE) is an experimental feature and, as such, it may behave unreliably until promoted to the main repository.
11+
12+
</aside>
13+
614
## Overview
715

816
The GCP provider supports creating GKE based cluster. Currently the following features are supported:
@@ -24,4 +32,4 @@ And a new template is available in the templates folder for creating a managed w
2432
* [Enabling GKE Support](enabling.md)
2533
* [Disabling GKE Support](disabling.md)
2634
* [Creating a cluster](creating-a-cluster.md)
27-
* [Cluster Upgrades](cluster-upgrades.md)
35+
* [Cluster Upgrades](cluster-upgrades.md)

docs/book/src/managed/provision.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Provisioning a GKE cluster
2+
3+
<aside class="note warning">
4+
5+
<h1>Warning</h1>
6+
7+
We recommend you take a look at the [Prerequisites](./../prerequisites.md) section before provisioning a workload cluster.
8+
9+
</aside>
10+
11+
**This guide uses an example from the `./templates` folder of the CAPG repository. You can inspect the yaml file [here](https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-gcp/refs/heads/main/templates/cluster-template-gke.yaml).**
12+
13+
## Configure cluster parameters
14+
15+
While inspecting the cluster definition in `./templates/cluster-template-gke.yaml` you probably noticed that it contains a number of parameterized values that must be substituted with the specifics of your use case. This can be done via environment variables and `clusterctl` and effectively makes the template more flexible to adapt to different provisioning scenarios. These are the environment variables that you'll be required to set before deploying a workload cluster:
16+
17+
```sh
18+
export GCP_PROJECT=cluster-api-gcp-project
19+
export GCP_REGION=us-east4
20+
export GCP_NETWORK_NAME=default
21+
export WORKER_MACHINE_COUNT=1
22+
```
23+
24+
## Generate cluster definition
25+
26+
The sample cluster templates are already prepared so that you can use them with `clusterctl` to create a GKE cluster with CAPG.
27+
28+
To create a GKE cluster with a managed node group (a.k.a managed machine pool):
29+
30+
```bash
31+
clusterctl generate cluster capi-gke-quickstart --flavor gke -i gcp > capi-gke-quickstart.yaml
32+
```
33+
34+
In this example, `capi-gke-quickstart` will be used as cluster name.
35+
36+
## Create cluster
37+
38+
The resulting file represents the workload cluster definition and you simply need to apply it to your cluster to trigger cluster creation:
39+
40+
```
41+
kubectl apply -f capi-gke-quickstart.yaml
42+
```
43+
44+
## Kubeconfig
45+
46+
When creating an GKE cluster 2 kubeconfigs are generated and stored as secrets in the management cluster.
47+
48+
### User kubeconfig
49+
50+
This should be used by users that want to connect to the newly created GKE cluster. The name of the secret that contains the kubeconfig will be `[cluster-name]-user-kubeconfig` where you need to replace **[cluster-name]** with the name of your cluster. The **-user-kubeconfig** in the name indicates that the kubeconfig is for the user use.
51+
52+
To get the user kubeconfig for a cluster named `managed-test` you can run a command similar to:
53+
54+
```bash
55+
kubectl --namespace=default get secret managed-test-user-kubeconfig \
56+
-o jsonpath={.data.value} | base64 --decode \
57+
> managed-test.kubeconfig
58+
```
59+
60+
### Cluster API (CAPI) kubeconfig
61+
62+
This kubeconfig is used internally by CAPI and shouldn't be used outside of the management server. It is used by CAPI to perform operations, such as draining a node. The name of the secret that contains the kubeconfig will be `[cluster-name]-kubeconfig` where you need to replace **[cluster-name]** with the name of your cluster. Note that there is NO `-user` in the name.
63+
64+
The kubeconfig is regenerated every `sync-period` as the token that is embedded in the kubeconfig is only valid for a short period of time.

0 commit comments

Comments
 (0)