In this article, we’ll develop and deploy apps onto a remote Google Kubernetes Engine (GKE) cluster using Garden.
Garden is a developer tool that automates your workflows and makes developing, testing and deploying Kubernetes applications faster and easier than ever.
Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications running on Kubernetes clusters using Google infrastructure.
Sections in the article
- Before you begin
- Garden Features
- GKE Features
- Garden Setup
- GKE cluser setup
- Garden configuration to remote GKE cluster
- Other resources
Before you begin:
- Create a Google Cloud Platform (GCP) project, or use an existing one.
- Ensure you have gcloud installed, following the steps here.
- If you haven’t, follow the steps here to install kubectl.
- Clone the source code from GitHub.
Garden Features
Garden has so many awesome features, I’ll be listing just a few, you can click here for more.
- Develop and iterate as quickly with remote clusters as you do locally, and share development clusters with your team. With remote clusters you can even run Garden without Kubernetes or Docker installed on your machine!
- Hot reload lets you near-instantaneously update code and static files in containers as they run, for services that support in-place reloading.
- The built-in web dashboard gives you a full overview of your stack (and many more UI features are planned to further aid with development).
- Build, test and deploy Docker containers, Helm charts, OpenFaaS functions and more.
GKE Features
Google Kubernetes Engine has some great features for Developer to Operators to System Administrators, you can get details here.
- Load-balancing for Compute Engine instances.
- Node Pools to designate subsets of nodes within a cluster for additional flexibility.
- Automatic scaling of your cluster’s node instance count.
- Automatic upgrades for your cluster’s node software.
- Node auto-repair to maintain node health and availability.
- Logging and Monitoring with Stackdriver for visibility into your cluster.
Garden setup
To install Garden locally, run the following command:
curl -sL https://get.garden.io/install.sh | bash
If you’ll be working with a local kubernetes cluster, you’ll need to install Docker and Kubernetes.
GKE cluster setup
Ensure you have a GCP project created already. If you are a first time GCP user, you can get $300 credit for free to explore Google Cloud products here.
Login to gcloud using the command below, this would open a browser window for you to login. You could also set a default project after login.
gcloud auth login
To setup a GKE cluster, click here OR navigate as follows on the GCP Console: Kubernetes Engine > Clusters > Create Cluster
I’ll be creating a cluster with name: my-dev-cluster Feel free to use other configuration options as you wish.
Alternatively, you create the cluster with the gcloud command below:
gcloud container clusters create my-dev-cluster
Find the created cluster here, click on connect and copy the command. This would help you get authentication credentials, which configures kubectl and allows you to manage the cluster, also ensure that your terminal has both kubectl and gcloud installed. The following is my own connection command:
gcloud container clusters get-credentials my-dev-cluster --zone us-central1-c
One of Garden’s most powerful features is the ability to build images in your Kubernetes development cluster, do ensure that your cluster has the minimum requirements as specified here.
Garden configuration to remote GKE cluster
The first step to using Garden is to create a project. You can use the garden create project
helper command, or manually create a garden.yml
file in the root directory of your project.
Garden is configured via garden.yml
configuration files. The project-wide garden.yml
file should be located in the top-level directory of the project's Git repository.
We’ll be using multiple modules in the same configuration file, this is possible by using a document separator (---
) between the module definitions.
Learn more about Garden configuration files here.
Below is my Garden configuration file, you can find it on GitHub gist here.
# garden.yml
kind: Project
name: flask-app
environments:
- name: dev
providers:
- name: kubernetes
context: gke_fullstackgcp_us-central1-c_my-dev-cluster
buildMode: cluster-docker
defaultEnvironment: dev
---
kind: Module
name: backend
description: My App Backend
type: container
services:
# Service provides a running instance of your module.
- name: backend
ports:
- name: http
containerPort: 8080
Change _gke_fullstackgcp_us-central1-cmy-cluster to your cluster’s context name. To get yours, execute the command: **_kubectl config view_**
The configuration is for a simple container module. We assume that the the Dockerfile and source files are in the same directory as the garden.yml
file.
A module can correspond to a Dockerfile and its associated code, a remote Docker image, a Helm chart, an OpenFaaS function, and more, all depending on the module type.
Garden includes a container
module type, which provides a high-level abstraction around container-based services, that's easy to understand and use. Learn more about Garden container modules here.
Once you have ensured you have a Dockefile and your garden.yml configuration which connects to your GKE cluster using it’s context name. You need to initialize the cluster-wide system services, before deploying to this cluster, do so by executing the following command:
**garden — env=dev plugins kubernetes cluster-init**
Now you can start an iterative development on the GKE cluster which watches your project for changes then re-builds and re-deploys, with the command:
garden dev
This builds and deploys the Docker image for backend
service. While it runs, you can go ahead and make a change to any of the files in the project, Garden would trigger rebuild and redeploy automatically. The changes will be reflected when you reload the forwarded localhost url.
To deploy services, which also builds modules and dependencies if needed, run the command:
garden deploy
To learn more about Garden CLI commands and usage information, click here.
“With Garden you can completely get rid of your local Kubernetes cluster, and still enjoy rapid feedback while you write your code. “ — Jon Edvald
Thanks for reading, be sure to give Garden a star on GitHub.
Other Resources
- Garden Documentation
- Google Kubernetes Engine Documentation
- Introduction to Google Kubernetes Engine (FullStackGCP Blog)
- You Don’t Need Kubernetes on Your Laptop (Medium Article)
- GKE & Cloud SQL: A Step-by-Step Guide with Garden and Terraform (Medium Article)