2. Initialize a Project
With the Garden CLI installed, we'll kick off by configuring a simple example project for use with Garden.
Start by cloning our repo and finding the example project:
1
git clone https://github.com/garden-io/garden.git
2
cd garden/examples/demo-project-start
Copied!
This directory contains two directories, with one container service each, backend and frontend. We'll first define a boilerplate Garden project, and then a Garden module for each of the services.
To initialize the project, we can use a helper command:
1
garden create project
Copied!
This will create a basic boilerplate project configuration in the current directory, making it our project root. With the comments stripped out, it should look something like this:
1
kind: Project
2
name: demo-project
3
environments:
4
- name: default
5
providers:
6
- name: local-kubernetes
Copied!
We have one environment (default) and a single provider. We'll get back to this later.
Next, let's create module configs for each of our two modules, starting with backend:
1
cd backend
2
garden create module
3
cd ..
Copied!
You'll get a suggestion to make it a container module. Pick that, and give it the default name as well. Then do the same for the frontend module:
1
cd frontend
2
garden create module
3
cd ..
Copied!
This is now enough configuration to build the project. Before we can deploy, we need to configure services in each module configuration, as well as set up a local cluster or connect to a remote cluster.
Starting with the former, go ahead and open the newly created backend/garden.yml file. You'll find a number of commented-out fields, which reveal all the options available for the container module type. One of the is the services field. Just to keep things simple for now, go ahead and replace that block (or append to the file) the following:
1
services:
2
- name: backend
3
ports:
4
- name: http
5
containerPort: 8080
6
servicePort: 80
7
ingresses:
8
- path: /hello-backend
9
port: http
Copied!
This is enough information for Garden to be able to deploy and expose the backend service. Now do the same for the frontend service, with the following block:
1
services:
2
- name: frontend
3
ports:
4
- name: http
5
containerPort: 8080
6
ingresses:
7
- path: /hello-frontend
8
port: http
9
- path: /call-backend
10
port: http
11
dependencies:
12
- backend
Copied!
This does the same for the frontend service, with the addition of declaring a runtime dependency on the backend service.
Now, let's move on to our next section, and connect to a Kubernetes cluster.
Last modified 1yr ago
Copy link