Skip to content

Commit b8a360d

Browse files
committed
add terraform quickstart blog
1 parent afe72f3 commit b8a360d

File tree

6 files changed

+1843
-0
lines changed

6 files changed

+1843
-0
lines changed
Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
---
2+
slug: terraform-quickstart
3+
title: Terraform deployment quickstart
4+
authors: [bill]
5+
tags: [educates, terraform]
6+
---
7+
8+
Hi all, we are happy to announce we are now sharing the [Educates Terraform Modules project](https://github.com/educates/educates-terraform-modules) that provides support for deploying Educates on Amazon and Google Cloud providers.
9+
10+
Its [release versions](https://github.com/educates/educates-terraform-modules/releases) are independent from the [Educates Training Platform releases](https://github.com/educates/educates-training-platform/releases);
11+
however, it is currently tested and verified to work on Educates 3.2.x and 3.3.x on Kubernetes version 1.32.
12+
13+
We've provided the quick start here so you can experiment with it and give feedback.
14+
15+
<!-- truncate -->
16+
17+
---
18+
19+
## Why?
20+
21+
If you read the [*Installing Educates on a cloud provider* article](/blog/install-educates-cloud-cli) and/or watched the accompanying [video](https://www.youtube.com/watch?v=C6vCd6Nhf5M),
22+
you would notice that Educates requires a preliminary setup of a Kubernetes cluster before you can install Educates.
23+
24+
You *could* install Kubernetes (K8s) yourself,
25+
especially if are a Certified Kubernetes Administrator (CKA).
26+
But really it is more convenient to automate the K8s cluster provisioning as much as possible.
27+
28+
We selected [Terraform](https://developer.hashicorp.com/terraform) given its widespread use in DevOps and Platform Engineering domains.
29+
30+
---
31+
32+
## What is provided and supported?
33+
34+
The [Educates Terraform Modules project](https://github.com/educates/educates-terraform-modules) include several modules:
35+
36+
1. **Infrastructure modules**: deploy K8s cluster
37+
- [EKS cluster for Educates](https://github.com/educates/educates-terraform-modules/tree/main/infrastructure/eks-for-educates): Deploy K8s on Amazon EKS
38+
- [GKE cluster for Educates](https://github.com/educates/educates-terraform-modules/tree/main/infrastructure/gke-for-educates): Deploy K8s on Google GKE
39+
- [Kubeconfig generation support](https://github.com/educates/educates-terraform-modules/tree/main/infrastructure/token-sa-kubeconfig): Create a service account and secret for kubeconfig access
40+
41+
1. **Platform**
42+
- [Educates](https://github.com/educates/educates-terraform-modules/tree/main/platform/educates): Deploy Educates Ingress related prerequisites, Lookup Service, and Educates Training Platform
43+
44+
1. **Root Modules**: Reference implementations for installing Educates using Infrastructure and Platform modules
45+
- [Educates on EKS](https://github.com/educates/educates-terraform-modules/tree/main/root-modules/educates-on-eks)
46+
- [Educates on GKE](https://github.com/educates/educates-terraform-modules/tree/main/root-modules/educates-on-gke)
47+
48+
The [Educates Terraform Module project](https://github.com/educates/educates-terraform-modules) is released independently from the [Educates Training Platform](https://github.com/educates/educates-training-platform);
49+
however, is currently tested and verified to work on Educates 3.2.x and 3.3.x.
50+
51+
You can see the project releases [here](https://github.com/educates/educates-terraform-modules/releases).
52+
53+
:::note
54+
55+
Consider the **Root Modules** reference implementation only.
56+
You should build your own using the infrastructure and platform modules,
57+
using the reference implementations as inspiration.
58+
59+
We'll discuss limitations later in this article.
60+
61+
:::
62+
---
63+
64+
## Quick start
65+
66+
Getting started is easy.
67+
68+
In this example, we'll walk through deploying Educates on GKE using Terraform,
69+
from your development workstation.
70+
71+
You'll need some set up first.
72+
73+
### What you should know before running it?
74+
75+
We expect that you have a basic understanding of the following:
76+
77+
- Kubernetes (K8s)
78+
79+
- Your Cloud Provider (Amazon or Google): You should understand how to manage network,
80+
compute, storage, IAM users, policies and roles, K8s, and basic billing concepts
81+
82+
- Terraform
83+
84+
- Educates installation process - we recommend you have already reviewed the following:
85+
- [How the installer works](/blog/how-installer-works-part-1)
86+
- Installing Educates on a cloud provider parts [one](/blog/install-educates-cloud-cli) and [two](/blog/verify-educates-cloud-install).
87+
88+
### How much will running this cost?
89+
90+
If you've followed the instructions in the [Configure Terraform variables](#configure-terraform-variables) section,
91+
and use the `main.tfvars.example` template,
92+
your cluster and compute costs will be low.
93+
94+
You should be able to setup, test, and tear down your Educates cluster within a 24 hour period,
95+
and stay within a $5-10 USD range.
96+
97+
### Prerequisites
98+
99+
You'll need the following before you start:
100+
101+
1. **Amazon or Google Cloud IAM account**:
102+
With sufficient privileges to create/update/delete (for this example we use Google):
103+
- VPC/Network resources
104+
- K8s cluster
105+
- Compute and Storage
106+
- DNS Zones
107+
108+
2. **Educates Cluster Ingress DNS Zone configuration**:
109+
You'll need DNS configuration for your Educates cluster.
110+
You can read more about configuring that:
111+
- [Prerequisites](/blog/install-educates-cloud-cli#prerequisites)
112+
- [Cloud DNS Prerequisites](/blog/install-educates-cloud-cli#example-using-google-cloud)
113+
114+
3. **Developer workstation**:
115+
- Mac OSX
116+
- Linux distribution
117+
- Windows Subsystem for Linux (WSL)
118+
119+
4. **Cloud provider CLI**:
120+
For this example, [install and use `gcloud`](https://cloud.google.com/sdk/docs/install).
121+
You will also need to authenticate via an IAMS per #1 interactively,
122+
and also for the sdk:
123+
124+
```bash
125+
gcloud auth login
126+
... # auth interactively
127+
gcloud auth application-default login
128+
... # auth interactively
129+
```
130+
131+
5. **Terraform CLI**:
132+
You can install or manage specific versions of terraform with [`tfenv`](https://github.com/tfutils/tfenv).
133+
134+
The following installs, sets and verifies the version of terraform we are using in the quick start:
135+
136+
```bash
137+
tfenv install 1.12.1
138+
tfenv use 1.12.1
139+
terraform version
140+
```
141+
142+
You should see Terraform version successfully installed:
143+
144+
```no-highlight
145+
Terraform v1.12.1
146+
on {platform}
147+
```
148+
149+
6. [`kubectl`](https://kubernetes.io/docs/tasks/tools/#kubectl):
150+
We'll need access to the cluster after deployment.
151+
152+
7. **Educates CLI**:
153+
We'll need to deploy/manage a workshop to verify the cluster by either method:
154+
- Download the [Educates CLI directly](https://github.com/educates/educates-training-platform/releases/tag/3.3.2),
155+
- Use the [Educatesenv tool to manage the installation of Educates](/blog/managing-multiple-versions-of-educates-cli).
156+
Here we will deploy Educates 3.3.2.
157+
158+
### Root Module Reference implementations
159+
160+
We'll use the GKE reference implementation Terraform plan [here](https://github.com/educates/educates-terraform-modules/tree/main/root-modules/educates-on-gke).
161+
You can read how to run it [here](https://github.com/educates/educates-terraform-modules/blob/main/root-modules/educates-on-gke/README.md).
162+
163+
Alternatively, you could use the one for Amazon Elastic Kubernetes Service (EKS) [here](https://github.com/educates/educates-terraform-modules/tree/main/root-modules/educates-on-eks).
164+
165+
To prepare for running the quick start,
166+
do the following:
167+
168+
1. Open a bash or zsh terminal.
169+
170+
1. Set up a project directory of your choice on your developer workstation,
171+
and change your current directory to it.
172+
173+
For example:
174+
175+
```bash
176+
mkdir ~/workspace
177+
cd ~/workspace
178+
```
179+
180+
1. Fork/clone the Educates Terraform modules repo:
181+
182+
```bash
183+
git clone https://github.com/educates/educates-terraform-modules.git
184+
```
185+
186+
1. Change your working directory to the GKE root module directory
187+
(from where we will run the terraform plan):
188+
189+
```bash
190+
cd educates-terraform-modules/root-modules/educates-on-gke
191+
```
192+
193+
### Configure Terraform variables
194+
195+
Review the [Configuration examples](https://github.com/educates/educates-terraform-modules/tree/main?tab=readme-ov-file#configuration-examples).
196+
197+
For this example,
198+
we'll use the [`main.tfvars.example`](https://github.com/educates/educates-terraform-modules/blob/main/root-modules/educates-on-gke/examples/main.tfvars.example) as a template from which to build the `main.tfvars`.
199+
200+
1. Copy the example template to `main.tfvars` file:
201+
202+
```bash
203+
cp ./examples/main.tfvars.example ./main.tfvars
204+
```
205+
206+
1. Configure the placeholder variables in the `main.tfvars` file:
207+
- `gcp_project_id`: your Google Cloud project id where you will deploy the cluster
208+
- `gcp_region`: Google Cloud region where you will deploy the cluster
209+
- `cluster_name`: Pick a name for your cluster (should be between 6-12 characters)
210+
- `educates_ingress_domain`: the domain associated with the DNS zone configured for your Educates cluster
211+
212+
1. Notice the `deploy_educates` configuration flag.
213+
By default, the root modules assume you want to deploy Educates using the [Educates Platform module](https://github.com/educates/educates-terraform-modules/tree/main/platform/educates).
214+
It uses the [Carvel *Kapp Controller*](https://carvel.dev/kapp-controller/) for reconciliation of Educates components into the cluster.
215+
216+
If you prefer to install Educates via the CLI as in [Installing Educates on a cloud provider article](/blog/install-educates-cloud-cli),
217+
set the `deploy_educates` flag to `false`.
218+
The Educates module will not be deployed.
219+
220+
### Prepare and run the plan to deploy cluster
221+
222+
1. Initialize terraform in your development workspace:
223+
224+
```bash
225+
terraform init
226+
```
227+
228+
You can see a similar output:
229+
230+
<AsciinemaPlayer src="/asciinemas/terraform-init.cast" autoPlay={true} loop={true} />
231+
232+
1. Run the plan (this step is optional, but useful if you need to cache the plan in a CI/CD workflow):
233+
234+
```bash
235+
terraform plan -var-file ./main.tfvars
236+
```
237+
238+
You can see a similar output:
239+
240+
<AsciinemaPlayer src="/asciinemas/terraform-plan.cast" autoPlay={true} loop={true} />
241+
242+
1. Apply the plan:
243+
244+
```bash
245+
terraform apply -var-file ./main.tfvars
246+
```
247+
248+
Depending on your network connection speed/bandwidth,
249+
as well as Google's resource constraints,
250+
the plan may take 15-20 minutes to apply.
251+
252+
You can see a similar output:
253+
254+
<AsciinemaPlayer src="/asciinemas/terraform-apply.cast" autoPlay={true} loop={true} />
255+
256+
:::warning
257+
Note that when running `terraform` cli commands,
258+
you will be caching state of the plan in the working directory on your workstation into the following
259+
directories/files:
260+
261+
- `.terraform`
262+
- `.terraform.lock.hcl`
263+
- `terraform.state`
264+
- `terraform.state.backup`
265+
266+
State of the terraform plan and the associated cluster deployment workflow is not automatically saved elsewhere,
267+
so if you were to modify or delete these resources,
268+
you would not be able to update or destroy your cluster using Terraform.
269+
270+
This is one of the reasons these are just example reference implementations,
271+
and it's up to you to know what you're doing.
272+
You should use the released modules in your own plans,
273+
taking inspiration from these reference implementations,
274+
but guaranteeing to properly save the state of your plan executions.
275+
276+
:::
277+
278+
### Setup K8s access
279+
280+
The terraform plan will generate a kubeconfig file for you,
281+
with a naming pattern of `kubeconfig-${cluster_name}-token.yaml`.
282+
We'll verify K8s access here:
283+
284+
285+
1. Set KUBECONFIG to point to it in your terminal session:
286+
287+
```bash
288+
export KUBECONFIG=./kubeconfig-YOUR_CLUSTER_NAME-token.yaml
289+
```
290+
291+
1. Verify you can access cluster pods using your existing Google Cloud IAM session
292+
and provided `kubeconfig` access:
293+
294+
```bash
295+
kubectl get pods -A
296+
```
297+
298+
You can see a similar output:
299+
300+
<AsciinemaPlayer src="/asciinemas/terraform-verify-k8s-pods.cast" autoPlay={true} loop={true} />
301+
302+
### Deploy a workshop and verify
303+
304+
You can verify the platform installation per the [Installing Educates on a cloud provider (Part 2 - Verification) article](/blog/verify-educates-cloud-install)
305+
306+
### Tear down cluster
307+
308+
When you are done with the cluster,
309+
tear it down as follows:
310+
311+
```bash
312+
terraform destroy -var-file ./main.tfvars
313+
```
314+
315+
Given we are not using `-auto-approve`,
316+
you will be prompted to review the plan.
317+
318+
Confirm with "yes".
319+
320+
You can see a similar output:
321+
322+
<AsciinemaPlayer src="/asciinemas/terraform-destroy.cast" autoPlay={true} loop={true} />
323+
324+
325+
:::warning
326+
327+
If you removed your terraform state files,
328+
you will not be able to run the `terraform destroy` command.
329+
330+
You would need to clean up your cluster resources manually in the following order:
331+
332+
- Educates portals and lookup service configuration resources
333+
- Educates deployment
334+
- Node pools
335+
- GKE cluster
336+
- Volumes
337+
- VPC resources
338+
- Custom policies/roles
339+
340+
:::
341+
342+
---
343+
344+
## Limitations
345+
346+
Note the following limitations of the provided [Educates Terraform root modules](https://github.com/educates/educates-terraform-modules/tree/main/root-modules):
347+
348+
1. Terraform state is not handled explicitly - it relies on the user to handle externally.
349+
1. Continuous integration or continuous delivery pipelines are currently not supported.
350+
1. They have not yet been tested in either commercial, enterprise, or large scale implementations.
351+
1. They are currently considered reference implementation only.
352+
1. Currently only Amazon EKS and Google GKE providers are supported.
353+
354+
We encourage you to give feedback through issues or pull requests so we can improve the deployment automation
355+
experience.
356+
357+
---
358+
359+
## Conclusion
360+
361+
In this article,
362+
we walked through provisioning Educates using Terraform on Google Cloud.
363+
364+
If you are an Amazon user, we encourage you to walk through the EKS root module provisioning.
365+
366+
Hopefully we've shown you the value of using Terraform to streamline your Educates deployment
367+
workflow.

0 commit comments

Comments
 (0)