Skip to content

Commit dab4ad3

Browse files
committed
docs: restructure book sections and improve cluster creation tutorial
Signed-off-by: Carlos Salas <[email protected]>
1 parent 5938bd1 commit dab4ad3

File tree

14 files changed

+254
-64
lines changed

14 files changed

+254
-64
lines changed

docs/book/src/SUMMARY.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
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+
- [General Topics](./topics/index.md)
715
- [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)
1316
- [Machine Locations](./topics/machine-locations.md)
1417
- [Preemptible VMs](./topics/preemptible-vms.md)
15-
- [Flannel](./topics/flannel.md)
1618
- [Developer Guide](./developers/index.md)
1719
- [Development](./developers/development.md)
1820
- [Try unreleased changes with Nightly Builds](./developers/nightlies.md)

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.
File renamed without changes.

docs/book/src/topics/prerequisites.md renamed to docs/book/src/prerequisites.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Prerequisites
22

3-
## Requirements
3+
Before provisioning clusters via CAPG, there are a few extra tasks you need to take care of, including **configuring the GCP network** and **building images for GCP virtual machines**.
44

5-
- Linux or MacOS (Windows isn't supported at the moment).
6-
- A [Google Cloud](https://console.cloud.google.com) account.
7-
- [Packer](https://www.packer.io/intro/getting-started/install.html) and [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) to build images
8-
- Make to use `Makefile` targets
9-
- Install `coreutils` (for timeout) on *OSX*
10-
11-
### Setup environment variables
5+
### Set environment variables
126

137
```bash
148
export GCP_REGION="<GCP_REGION>"
@@ -21,7 +15,7 @@ export GCP_NETWORK_NAME=<GCP_NETWORK_NAME or default>
2115
export CLUSTER_NAME="<CLUSTER_NAME>"
2216
```
2317

24-
### Setup a Network and Cloud NAT
18+
### Configure Network and Cloud NAT
2519

2620
Google Cloud accounts come with a `default` network which can be found under
2721
[VPC Networks](https://console.cloud.google.com/networking/networks).
@@ -55,16 +49,6 @@ gcloud compute routers nats create "${CLUSTER_NAME}-mynat" --project="${GCP_PROJ
5549
--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips
5650
```
5751

58-
### Create a Service Account
59-
60-
To create and manage clusters, this infrastructure provider uses a service account to authenticate with GCP's APIs.
61-
62-
From your cloud console, follow [these instructions](https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating) to create a new service account with `Editor` permissions.
63-
64-
If you plan to use GKE the service account will also need the `iam.serviceAccountTokenCreator` role.
65-
66-
Afterwards, generate a JSON Key and store it somewhere safe.
67-
6852
### Building images
6953

7054
> NB: The following commands should not be run as `root` user.

docs/book/src/quick-start.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Getting started with CAPG
2+
3+
In this section we'll cover the basics of how to prepare your environment to use Cluster API Provider for GCP.
4+
5+
<aside class="note">
6+
7+
<h1>Tip</h1>
8+
9+
This covers the specifics of CAPG but won't go into detail of core CAPI basics. For more information on how CAPI works and how to interact with different providers, you can refer to [CAPI Quick Start](https://cluster-api.sigs.k8s.io/user/quick-start).
10+
11+
</aside>
12+
13+
Before installing CAPG, your Kubernetes cluster has to be transformed into a CAPI management cluster. If you have already done this, you can jump directly to the next section: [Installing CAPG](#installing-capg). If, on the other hand, you have an existing Kubernetes cluster that is not yet configured as a CAPI management cluster, you can follow the guide from the [CAPI book](https://cluster-api.sigs.k8s.io/user/quick-start#initialize-the-management-cluster).
14+
15+
## Requirements
16+
17+
- Linux or MacOS (Windows isn't supported at the moment).
18+
- A [Google Cloud](https://console.cloud.google.com) account.
19+
- [Packer](https://www.packer.io/intro/getting-started/install.html) and [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) to build images
20+
- `make` to use `Makefile` targets
21+
- Install `coreutils` (for timeout) on *OSX*
22+
23+
### Create a Service Account
24+
25+
To create and manage clusters, this infrastructure provider uses a service account to authenticate with GCP's APIs.
26+
27+
From your cloud console, follow [these instructions](https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating) to create a new service account with `Editor` permissions.
28+
29+
If you plan to use GKE the service account will also need the `iam.serviceAccountTokenCreator` role.
30+
31+
Afterwards, generate a JSON Key and store it somewhere safe.
32+
33+
34+
### Installing CAPG
35+
36+
There are two major provider installation paths: using `clusterctl` or the `Cluster API Operator`.
37+
38+
`clusterctl` is a command line tool that provides a simple way of interacting with CAPI and is usually the preferred alternative for those who are getting started. It automates fetching the YAML files defining provider components and installing them.
39+
40+
The `Cluster API Operator` is a Kubernetes Operator built on top of `clusterctl` and designed to empower cluster administrators to handle the lifecycle of Cluster API providers within a management cluster using a declarative approach. It aims to improve user experience in deploying and managing Cluster API, making it easier to handle day-to-day tasks and automate workflows with GitOps. Visit the CAPI Operator quickstart if you want to experiment with this tool.
41+
42+
You can opt for the tool that works best for you or explore both and decide which is best suited for your use case.
43+
44+
#### clusterctl
45+
46+
The Service Account you created will be used to interact with GCP and it must be base64 encoded and stored in a environment variable before installing the provider via `clusterctl`.
47+
48+
```
49+
export GCP_B64ENCODED_CREDENTIALS=$( cat /path/to/gcp-credentials.json | base64 | tr -d '\n' )
50+
```
51+
Finally, let's initialize the provider.
52+
```
53+
clusterctl init --infrastructure gcp
54+
```
55+
This process may take some time and, once the provider is running, you'll be able to see the `capg-controller-manager` pod in your CAPI management cluster.
56+
57+
#### Cluster API Operator
58+
59+
You can refer to the Cluster API Operator book [here](https://cluster-api-operator.sigs.k8s.io/01_user/02_quick-start) to learn about the basics of the project and how to install the operator.
60+
61+
When using Cluster API Operator, secrets are used to store credentials for cloud providers and not environment variables, which means you'll have to create a new secret containing the base64 encoded version of your GCP credentials and it will be referenced in the yaml file used to initialize the provider. As you can see, by using Cluster API Operator, we're able to manage provider installation declaratively.
62+
63+
Create GCP credentials secret.
64+
```
65+
export CREDENTIALS_SECRET_NAME="gcp-credentials"
66+
export CREDENTIALS_SECRET_NAMESPACE="default"
67+
export GCP_B64ENCODED_CREDENTIALS=$( cat /path/to/gcp-credentials.json | base64 | tr -d '\n' )
68+
69+
kubectl create secret generic "${CREDENTIALS_SECRET_NAME}" --from-literal=GCP_B64ENCODED_CREDENTIALS="${GCP_B64ENCODED_CREDENTIALS}" --namespace "${CREDENTIALS_SECRET_NAMESPACE}"
70+
```
71+
Define CAPG provider declaratively in a file `capg.yaml`.
72+
```
73+
apiVersion: v1
74+
kind: Namespace
75+
metadata:
76+
name: capg-system
77+
---
78+
apiVersion: operator.cluster.x-k8s.io/v1alpha2
79+
kind: InfrastructureProvider
80+
metadata:
81+
name: gcp
82+
namespace: capg-system
83+
spec:
84+
version: v1.8.0
85+
configSecret:
86+
name: gcp-credentials
87+
```
88+
After applying this file, Cluster API Operator will take care of installing CAPG using the set of credentials stored in the specified secret.
89+
```
90+
kubectl apply -f capg.yaml
91+
```

docs/book/src/topics/flannel.md renamed to docs/book/src/self-managed/cni.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Flannel
1+
# CNI
22

3-
This document describes how to use [Flannel](https://github.com/flannel-io/flannel) as your CNI solution. By default, the CNI plugin is not installed for self-managed clusters, so you have to [install your own](https://cluster-api.sigs.k8s.io/user/quick-start.html#deploy-a-cni-solution) (e.g. Calico with VXLAN)
3+
By default, no CNI plugin is installed when a self-managed cluster is provisioned. As a user, you need to [install your own](https://cluster-api.sigs.k8s.io/user/quick-start.html#deploy-a-cni-solution) CNI (e.g. Calico with VXLAN) for the control plane of the cluster to become ready.
4+
5+
This document describes how to use [Flannel](https://github.com/flannel-io/flannel) as your CNI solution.
46

57
## Modify the Cluster resources
68

0 commit comments

Comments
 (0)