Skip to content

Commit

Permalink
HPA example. Upgrade helm-application dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacchi committed Oct 15, 2024
1 parent 044c80c commit 5a74ab6
Show file tree
Hide file tree
Showing 8 changed files with 1,750 additions and 58 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ examples-clean:
rm -f examples/gwcStatefulSet/charts/*.tgz
rm -f examples/jdbc/charts/*.tgz
rm -f examples/pgconfig-acl/charts/*.tgz
rm -f examples/pgconfig-wms-hpa/charts/*.tgz
${HELM} uninstall gs-cloud-common || /bin/true
${HELM} uninstall gs-cloud-datadir || /bin/true
${HELM} uninstall gs-cloud-statefulset || /bin/true
${HELM} uninstall gs-cloud-jdbc || /bin/true
${HELM} uninstall gs-cloud-pgconfig-acl || /bin/true
${HELM} uninstall gs-cloud-pgconfig-wms-hpa || /bin/true


.PHONY: dependencies
Expand All @@ -26,11 +28,13 @@ gen-expected: dependencies
${HELM} dependency update examples/jdbc
${HELM} dependency update examples/pgconfig-acl
${HELM} dependency update examples/gwcStatefulSet
${HELM} dependency update examples/pgconfig-wms-hpa
${HELM} template --namespace=default gs-cloud-common examples/common > tests/expected-common.yaml
${HELM} template --namespace=default gs-cloud-datadir examples/datadir > tests/expected-datadir.yaml
${HELM} template --namespace=default gs-cloud-jdbc examples/jdbc > tests/expected-jdbc.yaml
${HELM} template --namespace=default gs-cloud-pgconfig-acl examples/pgconfig-acl > tests/expected-pgconfig-acl.yaml
${HELM} template --namespace=default gs-cloud-statefulset examples/gwcStatefulSet > tests/expected-statefulset.yaml
${HELM} template --namespace=default gs-cloud-pgconfig-wms-hpa examples/pgconfig-wms-hpa > tests/expected-pgconfig-wms-hpa.yaml
sed -i 's/[[:blank:]]\+$$//g' tests/expected*.yaml

.PHONY: example-common
Expand Down Expand Up @@ -62,3 +66,8 @@ example-common-no-nfs: dependencies
example-pgconfig-acl: example-common-no-nfs
${HELM} dependency update examples/pgconfig-acl
${HELM} upgrade --install gs-cloud-pgconfig-acl examples/pgconfig-acl

.PHONY: example-pgconfig-wms-hpa
example-pgconfig-wms-hpa: example-common-no-nfs
${HELM} dependency update examples/pgconfig-wms-hpa
${HELM} upgrade --install gs-cloud-pgconfig-wms-hpa examples/pgconfig-wms-hpa
15 changes: 15 additions & 0 deletions examples/pgconfig-wms-hpa/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
appVersion: '1.0'
description: Basic example with Horizontal Pod Autoscaling applied to WMS instances in geoserver-cloud using pgconfig as catalog persistence component
name: gs-cloud-hpa
version: 0.1.0
dependencies:
- name: geoservercloud
repository: file://../../
version: 0.1.0
# Postgres dependency used for pgconfig database
# Note: bitnami postgres chart is updated at initialization to add Postgis extension
- name: 'postgresql'
version: 14.0.0
repository: 'https://charts.bitnami.com/bitnami'
condition: postgresql.enabled
88 changes: 88 additions & 0 deletions examples/pgconfig-wms-hpa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# HPA example

This example allows to create a very simple GeoserverCloud deployment in your local cluster, which allows to evaluate and understand how Horizontal Pod Autoscaling (HPA) works.

The setup includes:

- a unique WebUI instance, (to allow see catalog configuration)
- the gateway, (access to the GeoserverCloud solution)
- 2 WMS instances, (the initial 2 instances which serve the WMS OGC protocol)
- a REST API instance, (used by attached script that allows to create a minimal catalog for testing)
- a local Postgres and (used along with PgConfig profile, since we want to minimize startup time, so we focus on reducing catalog reading)
- RabbitMQ (the bus event communication across instances)

Following steps mentioned in next section you will be able to see how HPA works automatically (up to 100 containers created!), when the cluster is stressed by the attached script defined for that.

# Considerations

- Read documentation in ../README.md file (since for running this demo, it's required to have a local cluster installed, along with kubectl)
- Execution of this kind of tests could freeze your machine, if your hardware/setup is not adequate.
- If in doubt, change values in the HPA section on the values.yaml file, so you can determine which is the value for maxReplicas (by default = 100)

# Steps

At repository base folder level, follow next steps:

1. Execute

```shell
make example-wms-hpa
```

2. Use

```shell
kubectl get po
```

in order to check that all the pods are up and running (that is, all of them with values STATUS = Running and READY = 1/1)
ie.

```shell
NAME READY STATUS RESTARTS AGE
gs-cloud-pgconfig-wms-hpa-gsc-gateway-76b46b9c7f-gs976 1/1 Running 0 12m
gs-cloud-pgconfig-wms-hpa-postgresql-0 1/1 Running 0 12m
gs-cloud-pgconfig-wms-hpa-gsc-rest-7fdbcf799f-qshn5 1/1 Running 0 12m
gs-cloud-pgconfig-wms-hpa-gsc-webui-6cf8f88695-646xt 1/1 Running 0 12m
gs-cloud-common-rabbitmq-0 1/1 Running 0 12m
gs-cloud-pgconfig-wms-hpa-gsc-wms-758dfd8765-qs946 1/1 Running 0 11m
gs-cloud-pgconfig-wms-hpa-gsc-wms-758dfd8765-pth59 1/1 Running 0 10m
```

3. Define a DNS alias (used in scripts to avoid local references. Note: you can edit scripts if you prefer)

```shell
kubectl get ingress --no-headers gs-cloud-pgconfig-wm-geoserver-host1 | awk '{printf("%s\t%s\n",$4,$3 )}' | sudo tee -a /etc/hosts
```

3. Execute

```shell
./examples/pgconfig-wms-hpa/init-catalog.sh
```

4. Execute

```shell
watch kubectl get po
```

in order to see list of pods (and watch every 2 secs)

5. In a different console, execute

```shell
./examples/pgconfig-wms-hpa/stress-server.sh
```

so you will trigger 1000 simultaneous request to the cluster.

At this point you will be able to see (in console 1) how the list of pods are increased and decreased during execution of the stress-server.sh script.

6. Execute

```shell
make examples-clean
```

so you get your environment clean, and deployment down.
38 changes: 38 additions & 0 deletions examples/pgconfig-wms-hpa/init-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

GEOSERVER_URL="http://gscloud.local/geoserver-cloud"
USER="admin"
PASSWORD="geoserver"

WORKSPACE="hpa-test"
DATASTORE="swisstopo_wms"
WMS_URL="https://wms.geo.admin.ch/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities"
LAYER_NAME="ch.bafu.grundwasserkoerper"

echo -e "\n------------------------------------"
echo -e "Preparing initialization process ..."
curl -u $USER:$PASSWORD -X DELETE "$GEOSERVER_URL/rest/workspaces/$WORKSPACE?recurse=true"

echo -e "------------------------------------"
echo -e "Creating workspace '$WORKSPACE'..."
if ! curl -u $USER:$PASSWORD -X POST -H "Content-Type: text/xml" -d "<workspace><name>$WORKSPACE</name></workspace>" $GEOSERVER_URL/rest/workspaces --fail; then
echo -e "Error creating workspace\n"
exit 1
fi

echo -e "\n------------------------------------"
echo -e "Creating WMS datastore '$DATASTORE'..."
if ! curl -u $USER:$PASSWORD -X POST -H "Content-Type: text/xml" -d "<wmsStore><type>WMS</type><name>$DATASTORE</name><workspace>$WORKSPACE</workspace><capabilitiesURL>$WMS_URL</capabilitiesURL><enabled>true</enabled></wmsStore>" $GEOSERVER_URL/rest/workspaces/$WORKSPACE/wmsstores --fail; then
echo -e "\nError creating datastore"
exit 1
fi

echo -e "\n------------------------------------"
echo -e "Publishing layer '$LAYER_NAME' from datastore '$DATASTORE'..."
if ! curl -u $USER:$PASSWORD -X POST -H "Content-Type: text/xml" -d "<wmsLayer><name>$LAYER_NAME</name><defaultStyle><name>raster</name></defaultStyle></wmsLayer>" $GEOSERVER_URL/rest/workspaces/$WORKSPACE/wmsstores/$DATASTORE/wmslayers --fail; then
echo -e "Error publishing layer\n"
exit 1
fi

echo -e "\n------------------------------------"
echo -e "Catalog initialized successfully.\n"
10 changes: 10 additions & 0 deletions examples/pgconfig-wms-hpa/stress-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

WMS_URL="http://gscloud.local/geoserver-cloud/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&STYLES&LAYERS=hpa-test%3Ach.bafu.grundwasserkoerper&exceptions=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A2056&WIDTH=769&HEIGHT=359&BBOX=2628297.2396917907%2C1161127.5666655225%2C2745623.985655881%2C1215846.1146757442"

for _ in {1..1000}
do
curl -s "$WMS_URL" > /dev/null &
done

wait
119 changes: 119 additions & 0 deletions examples/pgconfig-wms-hpa/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
postgresql:
enabled: true
global:
postgresql:
auth:
# this should be replaced by your existing secret
# existingSecret: your-secret-name
postgresPassword: g30s3rv3r

additionalVolumes: &additional-volumes
cache:
emptyDir: {}

additionalVolumeMounts: &additional-volume-mounts
/mnt/cache:
name: 'cache'

env: &env-override
PG_PASSWORD:
type: secret
name: 'gs-cloud-pgconfig-wms-hpa-postgresql'
key: 'postgres-password'
RABBITMQ_HOST:
value: 'gs-cloud-common-rabbitmq'
RABBITMQ_USER:
value: 'geoserver'
RABBITMQ_PASSWORD:
type: secret
name: 'gs-cloud-common-rabbitmq'
key: 'rabbitmq-password'
SPRING_PROFILES_ACTIVE:
value: standalone,pgconfig
GEOWEBCACHE_CACHE_DIR:
value: '/mnt/cache'
JAVA_OPTS:
value: '$(JAVA_OPTS_DEFAULT) -XshowSettings:system'
PGCONFIG_HOST:
value: gs-cloud-pgconfig-wms-hpa-postgresql-hl
PGCONFIG_PORT:
value: '5432'
PGCONFIG_DATABASE:
value: postgres
PGCONFIG_SCHEMA:
value: pgconfig
PGCONFIG_USERNAME:
value: postgres
PGCONFIG_PASSWORD:
type: secret
name: 'gs-cloud-pgconfig-wms-hpa-postgresql'
key: 'postgres-password'
PGCONFIG_MAXCONNECTIONS:
value: '10'

additional-stuff: &additional-stuff
volumes:
<<: *additional-volumes
containers:
spring:
env:
<<: *env-override
volumeMounts:
<<: *additional-volume-mounts

geoservercloud:
global:
profile: standalone,pgconfig
image:
pullPolicy: IfNotPresent
geoserver:
ingress:
enabled: true
hostGroups:
host1:
tls:
enabled: false
hosts:
- gscloud.local
services:
gateway:
ingress:
enabled: true
<<: *additional-stuff
webui:
<<: *additional-stuff
wms:
replicaCount: 2
hpa:
enabled: true
minReplicas: 2
maxReplicas: 100
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
<<: *additional-stuff
rest:
replicaCount: 1
<<: *additional-stuff
wcs:
enabled: false
replicaCount: 0
<<: *additional-stuff
wfs:
enabled: false
replicaCount: 0
<<: *additional-stuff
gwc:
enabled: false
replicaCount: 0
<<: *additional-stuff
wps:
enabled: false
replicaCount: 0
<<: *additional-stuff
acl:
enabled: false
Loading

0 comments on commit 5a74ab6

Please sign in to comment.