From 0134cb7b3244334af05901f8c9d1bab8553874d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 18:53:22 +0200 Subject: [PATCH 1/7] deploy autoscalers as part of webserver kustomize --- deploy/parts/autoscaling.sh | 6 ++++++ deploy/parts/deploy.sh | 29 ----------------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/deploy/parts/autoscaling.sh b/deploy/parts/autoscaling.sh index bd925a2..54a2dfe 100644 --- a/deploy/parts/autoscaling.sh +++ b/deploy/parts/autoscaling.sh @@ -33,5 +33,11 @@ if [ ${ENABLE_AUTOSCALING} = true ]; then yq e -i ".spec.maxReplicas=${MAX_STOREFRONT_REPLICAS}" "${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" fi +yq e -i ' + .resources += [ + "../../horizontalPodAutoscaler.yaml", + "../../horizontalStorefrontAutoscaler.yaml" + ] +' "${CONFIGURATION_TARGET_PATH}/kustomize/webserver/kustomization.yaml" echo -e "[${GREEN}OK${NO_COLOR}]" diff --git a/deploy/parts/deploy.sh b/deploy/parts/deploy.sh index 76451b5..ce2364a 100644 --- a/deploy/parts/deploy.sh +++ b/deploy/parts/deploy.sh @@ -11,7 +11,6 @@ assertVariable "DEPLOY_REGISTER_USER" assertVariable "DEPLOY_REGISTER_PASSWORD" assertVariable "BASIC_AUTH_PATH" -assertVariable "ENABLE_AUTOSCALING" assertVariable "RUNNING_PRODUCTION" FIRST_DEPLOY_LOAD_DEMO_DATA=${FIRST_DEPLOY_LOAD_DEMO_DATA:-0} @@ -158,40 +157,12 @@ if [ $DISPLAY_FINAL_CONFIGURATION -eq "1" ]; then echo "" fi -if [ ${ENABLE_AUTOSCALING} = true ]; then - echo -n " Delete previous Horizontal pod autoscaler for Backend " - runCommand "SKIP" "kubectl delete hpa webserver-php-fpm --namespace=${PROJECT_NAME}" - - echo -n " Delete previous Horizontal pod autoscaler for Storefront " - runCommand "SKIP" "kubectl delete hpa storefront --namespace=${PROJECT_NAME}" -fi - echo -n " Deploy Webserver and PHP-FPM container with Storefront" runCommand "ERROR" "kustomize build --load-restrictor LoadRestrictionsNone \"${CONFIGURATION_TARGET_PATH}/kustomize/webserver\" | kubectl apply -f -" echo -n " Waiting for start new PHP-FPM and Storefront container (In case of fail you need to manually check what is state of application)" runCommand "ERROR" "kubectl rollout status --namespace=${PROJECT_NAME} deployment/webserver-php-fpm deployment/storefront --watch" -if [ ${ENABLE_AUTOSCALING} = true ]; then - echo -n " Deploy Horizontal pod autoscaler for Backend " - - if [ ${RUNNING_PRODUCTION} -eq "0" ]; then - yq e -i '.spec.minReplicas = 2' "${CONFIGURATION_TARGET_PATH}/horizontalPodAutoscaler.yaml" - yq e -i '.spec.maxReplicas = 2' "${CONFIGURATION_TARGET_PATH}/horizontalPodAutoscaler.yaml" - fi - - runCommand "ERROR" "kubectl apply -f ${CONFIGURATION_TARGET_PATH}/horizontalPodAutoscaler.yaml" - - echo -n " Deploy Horizontal pod autoscaler for Storefront " - - if [ ${RUNNING_PRODUCTION} -eq "0" ]; then - yq e -i '.spec.minReplicas = 2' "${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" - yq e -i '.spec.maxReplicas = 2' "${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" - fi - - runCommand "ERROR" "kubectl apply -f ${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" -fi - RUNNING_WEBSERVER_PHP_FPM_POD=$(kubectl get pods --namespace=${PROJECT_NAME} --field-selector=status.phase=Running -l app=webserver-php-fpm -o=jsonpath='{.items[?(@.status.containerStatuses[0].state.running)].metadata.name}') echo -n "Disable maintenance page " From 550a54079473feee1ae5bbefceb59fe724435649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 18:58:43 +0200 Subject: [PATCH 2/7] autoscaling is enabled by default --- README.md | 8 +++----- deploy/parts/autoscaling.sh | 6 +----- tests/scenarios/basic-production/deploy-project.sh | 1 - .../scenarios/development-single-domain/deploy-project.sh | 1 - tests/scenarios/escaping-env/deploy-project.sh | 1 - .../production-with-cloudflare/deploy-project.sh | 1 - 6 files changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4279282..fe478fc 100644 --- a/README.md +++ b/README.md @@ -197,11 +197,9 @@ Add new variable to `deploy-project.sh` and specify your redis version ... ``` -### Enable Horizontal pod autoscaling +### Horizontal pod autoscaling -Add new variables to `deploy-project.sh` to enable pod autoscaling: - -- Enable this functionality: +- You can disable autoscaling by setting `ENABLE_AUTOSCALING=false` in `deploy-project.sh`: ```diff ... function deploy() { @@ -210,7 +208,7 @@ Add new variables to `deploy-project.sh` to enable pod autoscaling: ... ) - + ENABLE_AUTOSCALING=true + + ENABLE_AUTOSCALING=false ... ``` - If you need more replicas, then you can adjust those variables (default values are set to 2): diff --git a/deploy/parts/autoscaling.sh b/deploy/parts/autoscaling.sh index 54a2dfe..2e41a5e 100644 --- a/deploy/parts/autoscaling.sh +++ b/deploy/parts/autoscaling.sh @@ -5,11 +5,7 @@ echo -n "Prepare Autoscaling " assertVariable "BASE_PATH" assertVariable "CONFIGURATION_TARGET_PATH" -if [ -z ${ENABLE_AUTOSCALING} ]; then - ENABLE_AUTOSCALING=false -fi - -if [ ${ENABLE_AUTOSCALING} = true ]; then +if [[ "${ENABLE_AUTOSCALING:-true}" == "true" ]]; then if [ -z ${MIN_PHP_FPM_REPLICAS} ]; then MIN_PHP_FPM_REPLICAS=2 fi diff --git a/tests/scenarios/basic-production/deploy-project.sh b/tests/scenarios/basic-production/deploy-project.sh index 65c8654..4eb8fde 100644 --- a/tests/scenarios/basic-production/deploy-project.sh +++ b/tests/scenarios/basic-production/deploy-project.sh @@ -5,7 +5,6 @@ source "$(dirname "$0")/../../lib/scenario-base.sh" # Scenario-specific configuration DOMAINS=(DOMAIN_HOSTNAME_1 DOMAIN_HOSTNAME_2) export RUNNING_PRODUCTION=1 -ENABLE_AUTOSCALING=true declare -A CRON_INSTANCES=( ["cron"]='*/5 * * * *' diff --git a/tests/scenarios/development-single-domain/deploy-project.sh b/tests/scenarios/development-single-domain/deploy-project.sh index 4858fbe..f9bfd8b 100644 --- a/tests/scenarios/development-single-domain/deploy-project.sh +++ b/tests/scenarios/development-single-domain/deploy-project.sh @@ -6,7 +6,6 @@ source "$(dirname "$0")/../../lib/scenario-base.sh" DOMAINS=(DOMAIN_HOSTNAME_1) export RUNNING_PRODUCTION=0 export WHITELIST_IPS="10.0.0.0/8,192.168.0.0/16" -ENABLE_AUTOSCALING=true declare -A CRON_INSTANCES=( ["cron"]='*/5 * * * *' diff --git a/tests/scenarios/escaping-env/deploy-project.sh b/tests/scenarios/escaping-env/deploy-project.sh index 7911499..9d451c1 100644 --- a/tests/scenarios/escaping-env/deploy-project.sh +++ b/tests/scenarios/escaping-env/deploy-project.sh @@ -5,7 +5,6 @@ source "$(dirname "$0")/../../lib/scenario-base.sh" DOMAINS=(DOMAIN_HOSTNAME_1 DOMAIN_HOSTNAME_2) export RUNNING_PRODUCTION=1 export FIRST_DEPLOY=0 -ENABLE_AUTOSCALING=true declare -A CRON_INSTANCES=( ["cron"]='*/5 * * * *' diff --git a/tests/scenarios/production-with-cloudflare/deploy-project.sh b/tests/scenarios/production-with-cloudflare/deploy-project.sh index dbcece0..71a5250 100644 --- a/tests/scenarios/production-with-cloudflare/deploy-project.sh +++ b/tests/scenarios/production-with-cloudflare/deploy-project.sh @@ -7,7 +7,6 @@ DOMAINS=(DOMAIN_HOSTNAME_1 DOMAIN_HOSTNAME_2) export RUNNING_PRODUCTION=1 export USING_CLOUDFLARE=1 export CLOUDFLARE_IPS="103.21.244.0/22,103.22.200.0/22,104.16.0.0/13" -ENABLE_AUTOSCALING=true declare -A CRON_INSTANCES=( ["cron"]='*/5 * * * *' From a5b93ac76f5a102b115393dde514a33b90bbbdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 19:09:41 +0200 Subject: [PATCH 3/7] improve rolling strategy --- deploy/parts/autoscaling.sh | 35 +++++++++++++------ kubernetes/deployments/storefront.yaml | 5 +++ kubernetes/deployments/webserver-php-fpm.yaml | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/deploy/parts/autoscaling.sh b/deploy/parts/autoscaling.sh index 2e41a5e..2dc49f3 100644 --- a/deploy/parts/autoscaling.sh +++ b/deploy/parts/autoscaling.sh @@ -1,25 +1,35 @@ #!/bin/bash -e +patch_rollout() { + local file="$1" min_replicas="$2" + + if (( min_replicas >= 4 )); then + yq e -i '.spec.strategy.rollingUpdate.maxUnavailable = "25%"' "$file" + fi + + if (( min_replicas >= 6 )); then + yq e -i '.spec.strategy.rollingUpdate.maxSurge = "25%"' "$file" + fi +} + echo -n "Prepare Autoscaling " assertVariable "BASE_PATH" assertVariable "CONFIGURATION_TARGET_PATH" +assertVariable "RUNNING_PRODUCTION" if [[ "${ENABLE_AUTOSCALING:-true}" == "true" ]]; then - if [ -z ${MIN_PHP_FPM_REPLICAS} ]; then - MIN_PHP_FPM_REPLICAS=2 - fi - if [ -z ${MAX_PHP_FPM_REPLICAS} ]; then - MAX_PHP_FPM_REPLICAS=3 - fi + MIN_PHP_FPM_REPLICAS="${MIN_PHP_FPM_REPLICAS:-2}" + MAX_PHP_FPM_REPLICAS="${MAX_PHP_FPM_REPLICAS:-3}" + MIN_STOREFRONT_REPLICAS="${MIN_STOREFRONT_REPLICAS:-2}" + MAX_STOREFRONT_REPLICAS="${MAX_STOREFRONT_REPLICAS:-3}" - if [ -z ${MIN_STOREFRONT_REPLICAS} ]; then + if [[ "${RUNNING_PRODUCTION}" -eq 0 || "${DOWNSCALE_RESOURCE:-0}" -eq 1 ]]; then + MIN_PHP_FPM_REPLICAS=2 + MAX_PHP_FPM_REPLICAS=2 MIN_STOREFRONT_REPLICAS=2 - fi - - if [ -z ${MAX_STOREFRONT_REPLICAS} ]; then - MAX_STOREFRONT_REPLICAS=3 + MAX_STOREFRONT_REPLICAS=2 fi yq e -i ".spec.minReplicas=${MIN_PHP_FPM_REPLICAS}" "${CONFIGURATION_TARGET_PATH}/horizontalPodAutoscaler.yaml" @@ -27,6 +37,9 @@ if [[ "${ENABLE_AUTOSCALING:-true}" == "true" ]]; then yq e -i ".spec.minReplicas=${MIN_STOREFRONT_REPLICAS}" "${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" yq e -i ".spec.maxReplicas=${MAX_STOREFRONT_REPLICAS}" "${CONFIGURATION_TARGET_PATH}/horizontalStorefrontAutoscaler.yaml" + + patch_rollout "${CONFIGURATION_TARGET_PATH}/deployments/webserver-php-fpm.yaml" "${MIN_PHP_FPM_REPLICAS}" + patch_rollout "${CONFIGURATION_TARGET_PATH}/deployments/storefront.yaml" "${MIN_STOREFRONT_REPLICAS}" fi yq e -i ' diff --git a/kubernetes/deployments/storefront.yaml b/kubernetes/deployments/storefront.yaml index b096c87..7ccba69 100644 --- a/kubernetes/deployments/storefront.yaml +++ b/kubernetes/deployments/storefront.yaml @@ -4,6 +4,11 @@ metadata: name: storefront spec: replicas: 1 + strategy: + rollingUpdate: + maxSurge: 50% + maxUnavailable: 0 + type: RollingUpdate selector: matchLabels: app: storefront diff --git a/kubernetes/deployments/webserver-php-fpm.yaml b/kubernetes/deployments/webserver-php-fpm.yaml index 0d50252..7866bd3 100644 --- a/kubernetes/deployments/webserver-php-fpm.yaml +++ b/kubernetes/deployments/webserver-php-fpm.yaml @@ -9,7 +9,7 @@ spec: replicas: 1 strategy: rollingUpdate: - maxSurge: 1 + maxSurge: 50% maxUnavailable: 0 type: RollingUpdate selector: From a08e796350b9ea2f151d1e98da877941c5bc7b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 19:11:29 +0200 Subject: [PATCH 4/7] define scaling behavior for autoscalers --- kubernetes/horizontalPodAutoscaler.yaml | 21 +++++++++++++++++++ .../horizontalStorefrontAutoscaler.yaml | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/kubernetes/horizontalPodAutoscaler.yaml b/kubernetes/horizontalPodAutoscaler.yaml index 3a22f50..e698dfd 100644 --- a/kubernetes/horizontalPodAutoscaler.yaml +++ b/kubernetes/horizontalPodAutoscaler.yaml @@ -10,6 +10,27 @@ spec: name: webserver-php-fpm minReplicas: 2 maxReplicas: 2 + behavior: + scaleUp: + stabilizationWindowSeconds: 60 + selectPolicy: Max + policies: + - type: Pods + value: 2 + periodSeconds: 60 + - type: Percent + value: 50 + periodSeconds: 60 + scaleDown: + stabilizationWindowSeconds: 600 + selectPolicy: Max + policies: + - type: Pods + value: 1 + periodSeconds: 60 + - type: Percent + value: 30 + periodSeconds: 60 metrics: - type: ContainerResource containerResource: diff --git a/kubernetes/horizontalStorefrontAutoscaler.yaml b/kubernetes/horizontalStorefrontAutoscaler.yaml index 6da411e..ede46a1 100644 --- a/kubernetes/horizontalStorefrontAutoscaler.yaml +++ b/kubernetes/horizontalStorefrontAutoscaler.yaml @@ -10,6 +10,27 @@ spec: name: storefront minReplicas: 2 maxReplicas: 2 + behavior: + scaleUp: + stabilizationWindowSeconds: 60 + selectPolicy: Max + policies: + - type: Pods + value: 2 + periodSeconds: 60 + - type: Percent + value: 50 + periodSeconds: 60 + scaleDown: + stabilizationWindowSeconds: 600 + selectPolicy: Max + policies: + - type: Pods + value: 1 + periodSeconds: 60 + - type: Percent + value: 30 + periodSeconds: 60 metrics: - type: Resource resource: From 38aa391ae1913277ed4dba91dee7098267b543fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 19:14:07 +0200 Subject: [PATCH 5/7] update tests --- tests/run-tests.sh | 2 - .../expected/horizontalPodAutoscaler.yaml | 20 ----- .../horizontalStorefrontAutoscaler.yaml | 19 ---- .../basic-production/expected/webserver.yaml | 90 ++++++++++++++++++- .../expected/horizontalPodAutoscaler.yaml | 20 ----- .../horizontalStorefrontAutoscaler.yaml | 19 ---- .../expected/webserver.yaml | 90 ++++++++++++++++++- .../expected/horizontalPodAutoscaler.yaml | 20 ----- .../horizontalStorefrontAutoscaler.yaml | 19 ---- .../escaping-env/expected/webserver.yaml | 90 ++++++++++++++++++- .../expected/horizontalPodAutoscaler.yaml | 20 ----- .../horizontalStorefrontAutoscaler.yaml | 19 ---- .../expected/webserver.yaml | 90 ++++++++++++++++++- 13 files changed, 356 insertions(+), 162 deletions(-) delete mode 100644 tests/scenarios/basic-production/expected/horizontalPodAutoscaler.yaml delete mode 100644 tests/scenarios/basic-production/expected/horizontalStorefrontAutoscaler.yaml delete mode 100644 tests/scenarios/development-single-domain/expected/horizontalPodAutoscaler.yaml delete mode 100644 tests/scenarios/development-single-domain/expected/horizontalStorefrontAutoscaler.yaml delete mode 100644 tests/scenarios/escaping-env/expected/horizontalPodAutoscaler.yaml delete mode 100644 tests/scenarios/escaping-env/expected/horizontalStorefrontAutoscaler.yaml delete mode 100644 tests/scenarios/production-with-cloudflare/expected/horizontalPodAutoscaler.yaml delete mode 100644 tests/scenarios/production-with-cloudflare/expected/horizontalStorefrontAutoscaler.yaml diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 138e055..79468d0 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -178,8 +178,6 @@ build_outputs() { fi # Copy individual files that aren't built by kustomize - cp "${config_path}/horizontalPodAutoscaler.yaml" "${output_dir}/" 2>/dev/null || true - cp "${config_path}/horizontalStorefrontAutoscaler.yaml" "${output_dir}/" 2>/dev/null || true cp "${config_path}/namespace.yaml" "${output_dir}/" 2>/dev/null || true echo "$output_dir" diff --git a/tests/scenarios/basic-production/expected/horizontalPodAutoscaler.yaml b/tests/scenarios/basic-production/expected/horizontalPodAutoscaler.yaml deleted file mode 100644 index 74fbf30..0000000 --- a/tests/scenarios/basic-production/expected/horizontalPodAutoscaler.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: webserver-php-fpm - namespace: "myproject-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: webserver-php-fpm - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: php-fpm - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/basic-production/expected/horizontalStorefrontAutoscaler.yaml b/tests/scenarios/basic-production/expected/horizontalStorefrontAutoscaler.yaml deleted file mode 100644 index 212d868..0000000 --- a/tests/scenarios/basic-production/expected/horizontalStorefrontAutoscaler.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: storefront - namespace: "myproject-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: storefront - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/basic-production/expected/webserver.yaml b/tests/scenarios/basic-production/expected/webserver.yaml index 854c3d6..aba8ece 100644 --- a/tests/scenarios/basic-production/expected/webserver.yaml +++ b/tests/scenarios/basic-production/expected/webserver.yaml @@ -581,6 +581,11 @@ spec: selector: matchLabels: app: storefront + strategy: + rollingUpdate: + maxSurge: 50% + maxUnavailable: 0 + type: RollingUpdate template: metadata: annotations: @@ -674,7 +679,7 @@ spec: app: webserver-php-fpm strategy: rollingUpdate: - maxSurge: 1 + maxSurge: 50% maxUnavailable: 0 type: RollingUpdate template: @@ -924,6 +929,89 @@ spec: defaultMode: 420 secretName: fe-api-keys --- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: storefront + namespace: myproject-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - resource: + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: Resource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: storefront +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: webserver-php-fpm + namespace: myproject-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - containerResource: + container: php-fpm + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: ContainerResource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: webserver-php-fpm +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: diff --git a/tests/scenarios/development-single-domain/expected/horizontalPodAutoscaler.yaml b/tests/scenarios/development-single-domain/expected/horizontalPodAutoscaler.yaml deleted file mode 100644 index 95e34f3..0000000 --- a/tests/scenarios/development-single-domain/expected/horizontalPodAutoscaler.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: webserver-php-fpm - namespace: "myproject-dev" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: webserver-php-fpm - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: php-fpm - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/development-single-domain/expected/horizontalStorefrontAutoscaler.yaml b/tests/scenarios/development-single-domain/expected/horizontalStorefrontAutoscaler.yaml deleted file mode 100644 index 892de0a..0000000 --- a/tests/scenarios/development-single-domain/expected/horizontalStorefrontAutoscaler.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: storefront - namespace: "myproject-dev" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: storefront - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/development-single-domain/expected/webserver.yaml b/tests/scenarios/development-single-domain/expected/webserver.yaml index d5df13a..3bc9ebe 100644 --- a/tests/scenarios/development-single-domain/expected/webserver.yaml +++ b/tests/scenarios/development-single-domain/expected/webserver.yaml @@ -579,6 +579,11 @@ spec: selector: matchLabels: app: storefront + strategy: + rollingUpdate: + maxSurge: 50% + maxUnavailable: 0 + type: RollingUpdate template: metadata: annotations: @@ -668,7 +673,7 @@ spec: app: webserver-php-fpm strategy: rollingUpdate: - maxSurge: 1 + maxSurge: 50% maxUnavailable: 0 type: RollingUpdate template: @@ -918,6 +923,89 @@ spec: defaultMode: 420 secretName: fe-api-keys --- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: storefront + namespace: myproject-dev +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 2 + metrics: + - resource: + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: Resource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: storefront +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: webserver-php-fpm + namespace: myproject-dev +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 2 + metrics: + - containerResource: + container: php-fpm + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: ContainerResource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: webserver-php-fpm +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: diff --git a/tests/scenarios/escaping-env/expected/horizontalPodAutoscaler.yaml b/tests/scenarios/escaping-env/expected/horizontalPodAutoscaler.yaml deleted file mode 100644 index 74fbf30..0000000 --- a/tests/scenarios/escaping-env/expected/horizontalPodAutoscaler.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: webserver-php-fpm - namespace: "myproject-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: webserver-php-fpm - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: php-fpm - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/escaping-env/expected/horizontalStorefrontAutoscaler.yaml b/tests/scenarios/escaping-env/expected/horizontalStorefrontAutoscaler.yaml deleted file mode 100644 index 212d868..0000000 --- a/tests/scenarios/escaping-env/expected/horizontalStorefrontAutoscaler.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: storefront - namespace: "myproject-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: storefront - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/escaping-env/expected/webserver.yaml b/tests/scenarios/escaping-env/expected/webserver.yaml index 0520bbb..947d68e 100644 --- a/tests/scenarios/escaping-env/expected/webserver.yaml +++ b/tests/scenarios/escaping-env/expected/webserver.yaml @@ -584,6 +584,11 @@ spec: selector: matchLabels: app: storefront + strategy: + rollingUpdate: + maxSurge: 50% + maxUnavailable: 0 + type: RollingUpdate template: metadata: annotations: @@ -679,7 +684,7 @@ spec: app: webserver-php-fpm strategy: rollingUpdate: - maxSurge: 1 + maxSurge: 50% maxUnavailable: 0 type: RollingUpdate template: @@ -933,6 +938,89 @@ spec: defaultMode: 420 secretName: fe-api-keys --- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: storefront + namespace: myproject-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - resource: + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: Resource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: storefront +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: webserver-php-fpm + namespace: myproject-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - containerResource: + container: php-fpm + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: ContainerResource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: webserver-php-fpm +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: diff --git a/tests/scenarios/production-with-cloudflare/expected/horizontalPodAutoscaler.yaml b/tests/scenarios/production-with-cloudflare/expected/horizontalPodAutoscaler.yaml deleted file mode 100644 index 13e1051..0000000 --- a/tests/scenarios/production-with-cloudflare/expected/horizontalPodAutoscaler.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: webserver-php-fpm - namespace: "shop-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: webserver-php-fpm - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: php-fpm - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/production-with-cloudflare/expected/horizontalStorefrontAutoscaler.yaml b/tests/scenarios/production-with-cloudflare/expected/horizontalStorefrontAutoscaler.yaml deleted file mode 100644 index 2ef81ef..0000000 --- a/tests/scenarios/production-with-cloudflare/expected/horizontalStorefrontAutoscaler.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: storefront - namespace: "shop-production" -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: storefront - minReplicas: 2 - maxReplicas: 3 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 120 diff --git a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml index c318b1f..b1452dd 100644 --- a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml +++ b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml @@ -582,6 +582,11 @@ spec: selector: matchLabels: app: storefront + strategy: + rollingUpdate: + maxSurge: 50% + maxUnavailable: 0 + type: RollingUpdate template: metadata: annotations: @@ -675,7 +680,7 @@ spec: app: webserver-php-fpm strategy: rollingUpdate: - maxSurge: 1 + maxSurge: 50% maxUnavailable: 0 type: RollingUpdate template: @@ -925,6 +930,89 @@ spec: defaultMode: 420 secretName: fe-api-keys --- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: storefront + namespace: shop-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - resource: + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: Resource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: storefront +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: webserver-php-fpm + namespace: shop-production +spec: + behavior: + scaleDown: + policies: + - periodSeconds: 60 + type: Pods + value: 1 + - periodSeconds: 60 + type: Percent + value: 30 + selectPolicy: Max + stabilizationWindowSeconds: 600 + scaleUp: + policies: + - periodSeconds: 60 + type: Pods + value: 2 + - periodSeconds: 60 + type: Percent + value: 50 + selectPolicy: Max + stabilizationWindowSeconds: 60 + maxReplicas: 3 + metrics: + - containerResource: + container: php-fpm + name: cpu + target: + averageUtilization: 120 + type: Utilization + type: ContainerResource + minReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: webserver-php-fpm +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: From e390654afeeefbac6d0ef3452ddd1c60db95e6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 19:21:21 +0200 Subject: [PATCH 6/7] test changing rolling update strategy --- .../production-with-cloudflare/deploy-project.sh | 5 +++++ .../expected/webserver.yaml | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/scenarios/production-with-cloudflare/deploy-project.sh b/tests/scenarios/production-with-cloudflare/deploy-project.sh index 71a5250..6dd53bb 100644 --- a/tests/scenarios/production-with-cloudflare/deploy-project.sh +++ b/tests/scenarios/production-with-cloudflare/deploy-project.sh @@ -8,6 +8,11 @@ export RUNNING_PRODUCTION=1 export USING_CLOUDFLARE=1 export CLOUDFLARE_IPS="103.21.244.0/22,103.22.200.0/22,104.16.0.0/13" +MIN_PHP_FPM_REPLICAS=6 +MAX_PHP_FPM_REPLICAS=8 +MIN_STOREFRONT_REPLICAS=3 +MAX_STOREFRONT_REPLICAS=4 + declare -A CRON_INSTANCES=( ["cron"]='*/5 * * * *' ["feed-generator"]='0 */2 * * *' diff --git a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml index b1452dd..19269ed 100644 --- a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml +++ b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml @@ -680,8 +680,8 @@ spec: app: webserver-php-fpm strategy: rollingUpdate: - maxSurge: 50% - maxUnavailable: 0 + maxSurge: 25% + maxUnavailable: 25% type: RollingUpdate template: metadata: @@ -957,7 +957,7 @@ spec: value: 50 selectPolicy: Max stabilizationWindowSeconds: 60 - maxReplicas: 3 + maxReplicas: 4 metrics: - resource: name: cpu @@ -965,7 +965,7 @@ spec: averageUtilization: 120 type: Utilization type: Resource - minReplicas: 2 + minReplicas: 3 scaleTargetRef: apiVersion: apps/v1 kind: Deployment @@ -998,7 +998,7 @@ spec: value: 50 selectPolicy: Max stabilizationWindowSeconds: 60 - maxReplicas: 3 + maxReplicas: 8 metrics: - containerResource: container: php-fpm @@ -1007,7 +1007,7 @@ spec: averageUtilization: 120 type: Utilization type: ContainerResource - minReplicas: 2 + minReplicas: 6 scaleTargetRef: apiVersion: apps/v1 kind: Deployment From e47b87095a705af4010ee3d715444abe4028a4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3recki?= Date: Wed, 15 Apr 2026 19:24:30 +0200 Subject: [PATCH 7/7] add upgrade info --- UPGRADE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/UPGRADE.md b/UPGRADE.md index dc6a0b7..8cae4bd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,7 @@ ## Upgrade from v5.0.0 to v5.1.0 +- define autoscaling behavior with rolling update strategy ([#78](https://github.com/shopsys/deployment/pull/78)) - removed GCloud-specific docker registry secret creation ([#77](https://github.com/shopsys/deployment/pull/77)) - improved probes and graceful shutdown for storefront ([#76](https://github.com/shopsys/deployment/pull/76)) - added probes for RabbitMQ with graceful shutdown ([#75](https://github.com/shopsys/deployment/pull/75))