k8s poc

A very prilimiary project for proof of concept on following items,

  1. Support multiplie user login
    (re-implement session managment logic without spring-session and spring-security)

  2. Concurrent update control

Prerequisites

JDK 11+

Gradle 6.8

NodeJS v14

H2 DB v1.4.199

Redis 3.2

MariaDB Server 10.6 (Optional)

MySQL Workbench 8.0 CE

Docker Desktop (Optional)

To setup the environment and run the demo

Add below entry at C:\Windows\System32\drivers\etc\hosts

1
2
3
4
5
6
7
127.0.0.1	xxx.local.hk
127.0.0.1 session-service.local.hk
127.0.0.1 login-service.local.hk
127.0.0.1 profile-service.local.hk
127.0.0.1 redis-server.local.hk
127.0.0.1 mariadb-server.local.hk
127.0.0.1 h2db-server.local.hk

MariaDB (Optional)

  • Download and install MariaDB
  • Run the scripts in file config\MariaDB\create-db.txt to create database and data initialization.

H2 DB

  • Go to config\h2 folder and run the script h2_server.bat in command prompt
  • Run below scripts to create database file in baseDir defined in h2_server.bat
    java -cp h2-1.4.199.jar org.h2.tools.Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Welcome to H2 Shell 1.4.199 (2019-03-13)
Exit with Ctrl+C
[Enter] jdbc:h2:tcp://localhost/~/test
URL jdbc:h2:c:/Users/user/test
[Enter] org.h2.Driver
Driver
[Enter] sa
User
Password
Type the same password again to confirm database creation.
Password
Connected
Commands are case insensitive; SQL statements end with ';'
help or ? Display this help
list Toggle result list / stack trace mode
maxwidth Set maximum column width (default is 100)
autocommit Enable or disable autocommit
history Show the last 20 statements
quit or exit Close the connection and exit
  • Run the scripts in file config\MariaDB\create-db.txt to create tables and data initialization.

Redis

  • Download and install Redis
  • Backup the redis.windows-service.conf file in Redis Installation folder and replace it with config\redis\redis.windows-service.conf
  • Run following commands with Adminstrator permission
    net stop redis && net start redis

Go to session-service directory and run below script in command prompt

gradle build && java -Dcommon.properties=..\config\common.properties -jar build\libs\session-service-1.0.war

Go to login-service directory and run below script in command prompt

gradle build && java -Dcommon.properties=..\config\common.properties -jar build\libs\login-service-1.0.war

Go to profile-service directory and run below script in command prompt

gradle build && java -Dcommon.properties=..\config\common.properties -jar build\libs\profile-service-1.0.war

Go to frontend directory and run below script in command prompt

1
2
npm install
npm start

The project is also able to build and run with docker

  • Build the services session-service, login-service and profile-service respectively by using Gradle
  • Go to directory container and run following commands
  • Build all images by command build-all.bat
  • Startup the application by command startup-all.bat
  • Create tables USER and SESSION, and corresponding records in MariaDB via MySQL Workbench
  • Refer to above H2 DB section, create database, table and records

Test the application

  • Open a new browser tab or window with the URL http://xxx-poc:3000/login in your address bar.
  • To view the database structure open MySQL Workbench and input connection information from file config\mariadb\create-db.sql.

Next…

Deploy the code to OKD, minikube, CodeReady Containers and KinD later

Fix problem of PullImageErr even successfully validate new docker image from external registry for deployment

Add imagePullSecret under below YAML

1
2
3
4
Administrator -> User Management -> Service Accounts -> default -> YAML
imagePullSecrets:
- name: default-dockercfg-49c54
- name: repo-secrect (it comes from Workloads -> Secrets)

Or run following script

openshift-deploy-an-application-from-private-registry
service_accounts in openshift
image-pull-secrets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
oc create secret docker-registry repo-secrect \
--docker-server=repo.lab.company.com \
--docker-username=<user_name> \
--docker-password=<password> \
--docker-email=unused
```

`oc secrets link default repo-secrect --for=pull`

## Manage and deploy containers in OKD platform
* Following commands come from
https://design.jboss.org/redhatdeveloper/marketing/openshift_cheatsheet/cheatsheet/images/openshift_cheat_sheet_r2v1.pdf
https://gist.github.com/rafaeltuelho/111850b0db31106a4d12a186e1fbc53e

oc login
oc status
oc logs
oc describe pod
oc describe svc
oc get is
oc get pods
oc get svc
oc get routes
oc get deployment
oc del is
oc del pod
oc exec cat /opt/app-root/myapp.config
oc rsh
oc debug dc

Redeploy images from repo.lab.company.com

oc delete deployment frontend
oc delete svc frontend
oc delete is frontend
oc delete route frontend

Check service account

oc describe sa

Create deployment

oc new-app repo.lab.company.com/myname/xxx-poc/login-service:latest –name=my-application
oc delete deployment application

1
2
3
4

* odo commands from
https://odo.dev/docs/getting-started/basics
https://docs.openshift.com/container-platform/4.9/cli_reference/developer_cli_odo/understanding-odo.html

odo login -umyname
odo project create quickstart
odo catalog list services

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

* add configmap
```
oc create configmap xxx-poc-config --from-env-file=common.properties --dry-run=client -o yaml > configMap.yml
oc create configmap xxx-poc-config --from-file=common.properties
oc apply -f configMap.yml

oc describe configmap xxx-poc-config

oc get configmap xxx-poc-config -o yaml

----
oc delete configmap xxx-poc-config2

oc get deployment session-service -o yaml > orig-deployment.txt
oc apply -f add-configmap-deployment.yaml