In this solution, WordPress is dynamically scaled using an Horizontal Pod Autoscaler. This solution allows tracking the CPU/RAM usage of the WordPress pods and dynamicall scale the solution based on that information.
You can find information about how the algorithm used for scaling up/down the solution works in this link.
The Horizontal Pod Autoscaler controller can retrieve metrics about the CPU/Memory consumption from several APIs, being the most important the ones that are provided by Metrics Server (this solution is available by default on GKE clusters). Find more information in the link below:
Find below the specification of the "HorizontalPodAutoscaler" resource created with this solution:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: wordpress
minReplicas: 1
maxReplicas: 11
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 50