Skip to content

Latest commit

 

History

History
143 lines (103 loc) · 5.04 KB

README.md

File metadata and controls

143 lines (103 loc) · 5.04 KB

☸️ Orchestration Exercise

This repository contains the code for an assignment as part of the course Orchestration at Polytech Montpellier.

Table of contents

  1. Instructions
  2. The application
  3. Architecture
  4. Install guide (Taskfile)
  5. Install guide (manual)
  6. Development
  7. Known issues
  8. License

Instructions

Click to see the exercise instructions

The application

This application simply consists of a list of drinks and a button to add a new random drink to the list. The list of drinks is stored in a PostgreSQL database and the API is used to retrieve and add drinks to the database.

Click to see a demo

Architecture

Applications

  • The web application has been made using SvelteKit as it allows users to create SSR only routes which is required for this assignment.
    • Latest image: ghcr.io/do3-2023/nta-kube/webapp:main
    • Source code: webapp
  • The API has been built using Go and the API library named go-chi.
    • Latest image: ghcr.io/do3-2023/nta-kube/api:main
    • Source code: api
  • The database is a simple PostgreSQL database.
  • Each application is built and pushed as an image to Github Container Registry (ghcr.io) using Github Actions.

Infrastructure

  • Each application has its own namespace as required by the assignment.
  • Since each application is deployed in its own namespace, they can't share the same Secrets or ConfigMaps. Consequently, each namespace has its own Secret and ConfigMap with identical values.
  • The applications communicate with each other using the cluster's internal DNS. This means that they use the following URLs: <app-name>.<namespace>.svc.cluster.local.
  • The database uses a PersistentVolumeClaim (PVC) to store its data. This PVC is backed by a PersistentVolume (PV) which resides on a local volume on the host machine. In this case, the volume is stored in the /tmp/nta-kube directory.
  • The web application doesn't have an Ingress and needs to be port forwarded to be accessed.
  • The API has a replica count of 3 to demonstrate that it can be scaled.

k8s infrastructure

Install guide (Taskfile)

This project features a Taskfile which automates the creation of the cluster and the deployment of the applications. You can find out about all the available tasks by running task --list.

Requirements

Steps

  1. Create the k3d cluster with everything deployed and ready to go.
task deploy
  1. Port forward the web application to your local machine. This should make the web application available here. You may need to wait a few dozen seconds for the web application to be ready.
task port-forward
  1. Delete the cluster (when you're done).
task delete

Install guide (manual)

Requirements

Steps

  1. Create a k3d cluster named nta-kube.
k3d cluster create nta-kube
  1. Create the namespaces for the applications. This has to be done before deploying the applications.
kubectl apply -f infra/namespaces
  1. Deploy the PostgreSQL database.
kubectl apply -f infra/db
  1. Deploy the API.
kubectl apply -f infra/api
  1. Deploy the web application.
kubectl apply -f infra/webapp
  1. Port forward the web application to your local machine. This should make the web application available here. You may need to wait for the web application to be ready. It can take up to a minute.
kubectl port-forward -n webapp svc/webapp 8080:3000

Development

A docker-compose file is available to run the applications locally. This docker-compose file doesn't include the web application which needs to be run separately using npm run dev.

  • Using the Taskfile:
task dev
  • Without the task command:
docker-compose up -d

Known issues

  • The web application sometimes has trouble loading and fetching data on the first load. This issue seems to happen only on Firefox. A simple refresh fixes the issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.