Skip to content

Commit

Permalink
Merge pull request #52 from canonical/MK-879/gcp
Browse files Browse the repository at this point in the history
Add GCP cluster template
  • Loading branch information
neoaggelos authored Dec 1, 2022
2 parents 7b08d3e + b22c975 commit 8a8b424
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,37 @@ microk8s kubectl apply -f cluster-azure.yaml

> **Note**: Make sure you have the secret to include the password of the Service Principal identity. This secret will be referenced by the AzureClusterIdentity used by the AzureCluster.
#### GCP

> *NOTE*: Ensure that you have properly deployed the GCP infrastructure provider prior to executing the commands below. See [Initialization for common providers](https://cluster-api.sigs.k8s.io/user/quick-start.html#initialization-for-common-providers)
Prior to generate a cluster template, you need to create a VM image for use in the cluster. The MicroK8s provider works with any stock Ubuntu image. Use the Ubuntu 22.04 LTS image with:

```bash
gcloud compute images create ubuntu-2204 --source-image-project ubuntu-os-cloud --source-image-family ubuntu-2204-lts
```

Make note of the name of the image `ubuntu-2204`, which we then feed into the cluster template.

Generate a cluster template with:

```bash
# review list of variables needed for the cluster template
clusterctl generate cluster microk8s-gcp --from ./templates/cluster-template-gcp.yaml --list-variables

# set environment variables (edit the file as needed before sourcing it)
source ./templates/cluster-template-gcp.rc

# generate the cluster
clusterctl generate cluster microk8s-gcp --from ./templates/cluster-template-gcp.yaml > cluster-gcp.yaml
```

Then, deploy the cluster with:

```bash
microk8s kubectl apply -f cluster-gcp.yaml
```

## Development

The two MicroK8s CAPI providers, the bootstrap and control plane, serve distinct purposes:
Expand Down
15 changes: 15 additions & 0 deletions templates/cluster-template-gcp.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Kubernetes cluster configuration
export KUBERNETES_VERSION=1.25.0
export CONTROL_PLANE_MACHINE_COUNT=1
export WORKER_MACHINE_COUNT=1

# GCP configuration
export GCP_REGION="europe-west"
export GCP_NETWORK_NAME="default"
export GCP_PROJECT="my-gcp-project-name"

# GCP machine configuration
export GCP_PUBLIC_IP=true # set to false if you have configured a cloud NAT
export GCP_CONTROL_PLANE_MACHINE_TYPE=n1-standard-2
export GCP_NODE_MACHINE_TYPE=n1-standard-2
export IMAGE_ID=projects/$GCP_PROJECT/global/images/ubuntu-2204
103 changes: 103 additions & 0 deletions templates/cluster-template-gcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Based on https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v1.5.0/cluster-template.yaml
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
spec:
clusterNetwork:
apiServerPort: 6443
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPCluster
name: ${CLUSTER_NAME}
controlPlaneRef:
kind: MicroK8sControlPlane
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
name: ${CLUSTER_NAME}-control-plane
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPCluster
metadata:
name: ${CLUSTER_NAME}
spec:
project: "${GCP_PROJECT}"
region: "${GCP_REGION}"
network:
name: "${GCP_NETWORK_NAME}"
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: MicroK8sControlPlane
metadata:
name: "${CLUSTER_NAME}-control-plane"
spec:
controlPlaneConfig:
initConfiguration:
joinTokenTTLInSecs: 900000
IPinIP: true
addons:
- dns
- ingress
clusterConfiguration:
portCompatibilityRemap: true
machineTemplate:
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
name: "${CLUSTER_NAME}-control-plane"
replicas: ${CONTROL_PLANE_MACHINE_COUNT:=1}
version: "v${KUBERNETES_VERSION}"
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
metadata:
name: ${CLUSTER_NAME}-control-plane
spec:
template:
spec:
instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}"
image: "${IMAGE_ID}"
publicIP: ${GCP_PUBLIC_IP}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: "${CLUSTER_NAME}-md-0"
spec:
clusterName: "${CLUSTER_NAME}"
replicas: ${WORKER_MACHINE_COUNT:=1}
selector:
matchLabels:
template:
spec:
clusterName: "${CLUSTER_NAME}"
version: "${KUBERNETES_VERSION}"
bootstrap:
configRef:
name: "${CLUSTER_NAME}-md-0"
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: MicroK8sConfigTemplate
infrastructureRef:
name: "${CLUSTER_NAME}-md-0"
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
metadata:
name: ${CLUSTER_NAME}-md-0
spec:
template:
spec:
instanceType: "${GCP_NODE_MACHINE_TYPE}"
image: "${IMAGE_ID}"
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: MicroK8sConfigTemplate
metadata:
name: "${CLUSTER_NAME}-md-0"
spec:
template:
spec:
clusterConfiguration:
portCompatibilityRemap: true

0 comments on commit 8a8b424

Please sign in to comment.