Skip to main content
Version: Pasley (2.1)

The Sample Project

All the tutorials use the Sample Kubernetes Project on GitHub. For the remainder of these tutorials, you will need:

  1. A Kubernetes cluster
  2. The Codezero CLI installed
  3. The sample project cloned locally
note

Tutorials are a work in progress and do not represent everything you can do with Codezero. If you are new to Codezero, it is best that you go through the tutorials in the order they are presented.

Objectives

In this tutorial, you will learn:

  • How to perform local development against an application running in a Kubernetes cluster

By the end of the tutorial you should have successfully run the application locally, and also in your cluster.

Architecture

The following diagram depicts all the components of the sample project:

Tutorial

If you haven't already, clone the Sample Kubernetes Project repo on GitHub, and set up a Kubernetes cluster. For development, we recommend using either Civo or DigitalOcean, but any k8s or k3s Kubernetes cluster will do.

Getting to know Kubernetes and setting up a cluster is beyond the scope of this tutorial, however you can check out the beginner articles on our Blog.

Kubernetes Setup

Once your cluster is set up, install the sample project in-cluster. From the root of the repo, run:

kubectl create ns sample-project
kubectl -n sample-project apply -k ./k8s

Set Up Ingress - Optional

The above commands will install all the services and deployment, but will not set up ingress. If you are not able to setup Ingress, you will be able to use Codezero to access the frontend using Consume. You may choose any form of Ingress you prefer. We have implemented the following:

  • Traefik
  • Ingress
  • LoadBalance

If you're using TraefikV2, run the following:

kubectl -n sample-project apply -f ./k8s/traefik

Or if you use an Ingress Controller, run the following:

kubectl -n sample-project apply -f ./k8s/ingress

To use a generic LoadBalance service (for example if your cluster is on DigitalOcean), run the following:

kubectl -n sample-project apply -f ./k8s/loadbalance

Once configured, you will then need to obtain the appropriate external IP address. You will not need to setup a DNS record for the tutorial. When you launch the application in the browser, you should see the following page. The application Frontend Service polls and retrieved data from the other services and renders their values.

Local Setup - Optional

note

You can skip the local setup if you do not intend to make code changes or if you would rather use a framework other than NodeJS. All the services above are quite simple and because Codezero is language agnostic, any language that can return JSON via HTTP would suffice.

This project requires NodeJS 16+ and yarn, has been tested on macOS (BigSur), Linux, and Windows Subsystem for Linux (WSL).

npm install -g yarn

All microservices can run locally with minimal requirements. After you clone the project, you can build and run all the services locally. From the repo's root, run the following (yarn is required):

yarn install
yarn start

Open http://localhost:3030 in a browser to view the running services.

note

If you aren't running MongoDB locally you won't see the database service running, but we'll get this working in a cluster in the next section.

Hit Ctrl-C now to stop the services and exit.

You are now ready for the tutorials.