Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 37 additions & 76 deletions docs/lab-5.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,53 @@
# Configuration and Storage in Kubernetes
# Configuration and Storage

Lab Session 5 - 20 Nov, 2024
Lab Session 5 - 30 Oct, 2025

## Introduction

The goal of this lab session is to let you practice the basics of
configuration and storage in Kubernetes, which includes the creation of
ConfigMap and Secret to configure your application, the usage of
Kubernetes Service and Java Database Connectivity (JDBC) to connect to a
stateful application, such as MySQL Database.
In this session, you are going to deploy a new AI service for the
PetClinic project so that users can have an online assistant for their
questions. The goal of this lab session is to train you in configuring
and developing workloads in Kubernetes. It lets you practice the
management of ConfigMap, the creation of Secret, and the knowledge
learned from the previous chapters.

To submit the answers to this lab session, please fill in your answers
in this document in-place. This should be done before the end of next
week (1 Dec, 2024 at midnight).
## Exercise 1 - Create Secret

## Exercise 1 - Setup MySQL Cluster
Create a Secret called “openai” in Kubernetes. This Secret should
contain one single key called “api-key”.

Use the Kubernetes manifest `k8s/mysql.yaml` to setup the MySQL cluster
as a StatefulSet. The manifest is missing some resources, please
complete them. You can inspect the status of different resources in the
Kubernetes cluster. The missing resources should be written directly to
the file `k8s/mysql.yaml`. You are expected to have one pod running
under that StatefulSet. The database `weekend_db` should initialized,
similar to what have been done in Lab Session 1. Once the setup is done,
please verify the connectivity to the MySQL Database using the pod
`mysql-client`. Share the step(s) of the verification below and commit
the configuration changes to the `k8s` directory.


> [!IMPORTANT]
> Don’t commit sensitive information into a ConfigMap,
> such as username and password. Consider using another type of resource
> for security concerns.

> [!TIP]
> Inside the MySQL client pod, you can connect to MySQL
> database using the service ClusterIP exposed by the database. See more
> details in [DNS for Services and Pods \|
> Kubernetes](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/)
> or [“ClusterIP DNS” in the previous lecture \|
> Mincong](https://mincong.io/esigelec/4).
>
> mysql -h $DNS_FOR_POD_OR_SERVICE -u root [...]

### Answer

<!-- Please write your answer here -->

## Exercise 2 - Connect Java Application and MySQL

Connect your backend service `weekend-server` to the MySQL Database
`weekend_db`. The answer of the request “whether today is the weekend”
should come from the database, rather than being hard-coded in Java. You
are expected to provide two API endpoints for the weekend-server:

GET /
``` sh
# TODO: enter command and verification here
```

The default (existing) endpoint answering whether today is the weekend.
The data structure of the response of this endpoint should remain the
same, but the content should be fetched from the database.


GET /mappings
## Exercise 2 - Create Workload

A new endpoint listing all the days of week and whether that day is the
weekend. Here is the expected structure:
Develop a solution for running the AI service in Kubernetes. You can
find the Spring Boot application image from Docker Hub:
[`springcommunity/spring-petclinic-genai-service`](https://hub.docker.com/r/springcommunity/spring-petclinic-genai-service)
and the related source code on GitHub
([link](https://github.com/spring-petclinic/spring-petclinic-microservices/tree/main/spring-petclinic-genai-service)).
You can also visit the section [“Integrating the Spring AI
Chatbot”](https://github.com/spring-petclinic/spring-petclinic-microservices/tree/main?tab=readme-ov-file#integrating-the-spring-ai-chatbot)
in the documentation to learn more about its setup. Most importantly,
you need to start the workload with the following configuration as an
environment variable:

``` json
{
"1": "No.",
"2": "No.",
"3": "No.",
"4": "Soon.",
"5": "Almost, but not yet.",
"6": "It's the weekend!",
"7": "It's the weekend!"
}
``` sh
OPENAI_API_KEY='sk-...'
```

In this report, please briefly describe what modifications you did to
the Java application and Kubernetes to make it work. Prove that your
solution is working correctly. For any code changes, please commit to
the related directories.
Please commit your changes to the file `k8s/lab5.microservices.yaml`.
However, DO NOT commit the API key to GitHub. You should reference the
Secret created in Exercise 1.

> [!TIP]
> Using any ORM framework, such as Hibernate or Java
> Persistence API (JPA), may significantly slow down your integration.
> Consider avoid using any framework, and relying directly on Java
> Database Connectivity (JDBC) to facilitate the work.


### Answer

<!-- Please write your answer here -->
``` sh
# TODO: develop the whole solution and describe what you do here.
# Commit the manifests changes to the file "${REPO}/k8s/lab5.microservices.yaml"
```