Skip to content
Draft
Show file tree
Hide file tree
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
93 changes: 93 additions & 0 deletions cross_cutting/k8s/basic_example/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
== Run Example

UPDATE

In this example, a server (Original Server) inside the cluster connects to a database inside the cluster. To access data of the original server, another server(Access Server) inside the cluster is used. The aceess server can be accessed from outside the cluster. The access server will communicate to the original server to retrieve data and sends it to the user.

image::./docs/img/ClusterOverviewSimple.drawio.svg["ClusterOverviewSimple"]

image::./docs/img/ClusterOverview.png["ClusterOverview"]

=== Requirements

- link:https://maven.apache.org/download.cgi[Maven] installed
- link:https://taskfile.dev/installation/[Taskfile] installed
- link:https://rancherdesktop.io/[Rancher Desktop] installed with link:https://github.com/devonfw/ide[DevonIDE]
- locale Kubernetes Cluster started
- Behind VPN's activate wsl-vpnkit

=== Installation
[tabs]
====
Docker::
+
--
- Run `task deployDocker`
--
Nerdctl::
+
--
- Run `task deployNerd`
--
Docker behind VPN::
+
--
- Run `task deployDockerVPN`
--
Nerdctl behind VPN::
+
--
- Run `task deployNerdVPN`
--
====

=== Uninstallation
[tabs]
====
Docker::
+
--
- Run `task removeDocker`
--
Nerdctl::
+
--
- Run `task removeNerd`
--
Docker behind VPN::
+
--
- Run `task removeDockerVPN`
--
Nerdctl behind VPN::
+
--
- Run `task removeNerdVPN`
--
====

=== Using VPN
Using inside a VPN is currently only working with a work around:
When running `kubectl` commands prepend `wsl`

1. Start Rancher Desktop with vpn disabled
2. Enable VPN
3. Test connection with `wsl kubectl get all`

=== What happened

1. For the original and access Server, a Dockerimage got created into a locale image repository
2. The helm chart inside openapi_helm_chart got installed
3. The Server and Database started and connected to each other
4. When using a vpn the helm commands got routed through the wsl vpn kit

=== Test
At `http://localhost:5030/guest` there is a list of invited guests

If localhost is not working run

```
kubectl get servie
```

Use the External Ip of the `openapi-server-access-service` instead of localhost
59 changes: 59 additions & 0 deletions cross_cutting/k8s/basic_example/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: '3'

tasks:
deployNerd:
cmds:
- mvn -f ./server/access_server/pom.xml clean install
- mvn -f ./server/original_server/pom.xml clean install
- nerdctl build -t original-server-spring --namespace k8s.io ./server/original_server/
- nerdctl build -t access-server-spring --namespace k8s.io ./server/access_server/
- helm install openapi-example ./openapi_helm_chart/

removeNerd:
cmds:
- nerdctl image rm original-server-spring --namespace k8s.io -f
- nerdctl image rm access-server-spring --namespace k8s.io -f
- helm uninstall openapi-example

deployDocker:
cmds:
- mvn -f ./server/access_server/pom.xml clean install
- mvn -f ./server/original_server/pom.xml clean install
- docker build -t original-server-spring ./server/original_server/
- docker build -t access-server-spring ./server/access_server/
- helm install openapi-example ./openapi_helm_chart/

removeDocker:
cmds:
- docker image rm original-server-spring -f
- docker image rm access-server-spring -f
- helm uninstall openapi-example


deployNerdVPN:
cmds:
- mvn -f ./server/access_server/pom.xml clean install
- mvn -f ./server/original_server/pom.xml clean install
- nerdctl build -t original-server-spring --namespace k8s.io ./server/original_server/
- nerdctl build -t access-server-spring --namespace k8s.io ./server/access_server/
- wsl helm install openapi-example ./openapi_helm_chart/

removeNerdVPN:
cmds:
- nerdctl image rm original-server-spring --namespace k8s.io -f
- nerdctl image rm access-server-spring --namespace k8s.io -f
- wsl helm uninstall openapi-example

deployDockerVPN:
cmds:
- mvn -f ./server/access_server/pom.xml clean install
- mvn -f ./server/original_server/pom.xml clean install
- docker build -t original-server-spring ./server/original_server/
- docker build -t access-server-spring ./server/access_server/
- wsl helm install openapi-example ./openapi_helm_chart/

removeDockerVPN:
cmds:
- docker image rm original-server-spring -f
- docker image rm access-server-spring -f
- wsl helm uninstall openapi-example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions cross_cutting/k8s/basic_example/openapi_helm_chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions cross_cutting/k8s/basic_example/openapi_helm_chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: openapi-example
description: A Helm chart for Kubernetes to depoy the open api server example

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: openapi-server-access-config
data:
mythaiapi_host_uri: "http://openapi-server-original-service.default.svc.cluster.local:5031/api/v1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-initdb-config
data:
init.sql: |
CREATE DATABASE IF NOT EXISTS db_example;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: mysql-database-secret
data:
mysql_root_username: cm9vdA==
mysql_root_password: cGFzc3dvcmQ=
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: openapi-server-original-config
data:
mysql_host: "mysql.default.svc.cluster.local"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: openapi-server-access-deployment
labels:
app: openapi-server-access
spec:
replicas: 1
selector:
matchLabels:
app: openapi-server-access
template:
metadata:
labels:
app: openapi-server-access
spec:
containers:
- name: spring-access-server-spring
image: access-server-spring
imagePullPolicy: Never
ports:
- containerPort: 8080
env:
- name: MYTHAIAPI_HOST_URI
valueFrom:
configMapKeyRef:
name: openapi-server-access-config
key: mythaiapi_host_uri

---
apiVersion: v1
kind: Service
metadata:
name: openapi-server-access-service
spec:
type: LoadBalancer
selector:
app: openapi-server-access
ports:
- protocol: TCP
port: 5030
targetPort: 8080


Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: openapi-server-original-deployment
labels:
app: openapi-server-original
spec:
replicas: 1
selector:
matchLabels:
app: openapi-server-original
template:
metadata:
labels:
app: openapi-server-original
spec:
containers:
- name: spring-original-server-spring
image: original-server-spring
imagePullPolicy: Never
ports:
- containerPort: 8080
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: openapi-server-original-config
key: mysql_host

- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-database-secret
key: mysql_root_password

- name: MYSQL_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mysql-database-secret
key: mysql_root_username

---
apiVersion: v1
kind: Service
metadata:
name: openapi-server-original-service
spec:
selector:
app: openapi-server-original
ports:
- protocol: TCP
port: 5031
targetPort: 8080

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
Loading