/
README.md
83 lines (69 loc) · 2.93 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
As use-case we will use the Mercury Demo website. Mercury is a Sitecore Commerce accelerator (https://mercury-ecommerce.com/) and there is a Dockerized demonstration environment available on request from https://github.com/avivasolutionsnl/mercury-demo.
Having a fully Dockerized Sitecore Commerce webshop allows us to quickly get up and running in Kubernetes.
Start the Mercury demo in Kubernetes using:
```
PS> kubectl apply -f ./scale
```
> Remove the `xc9` deployment before running this example
# Scale application
You can scale cluster nodes and pods.
To enable Node scaling (full details [here](https://docs.microsoft.com/en-us/azure/aks/cluster-autoscaler)), add the `--enable-cluster-autoscaler` and minimum and maximum number of nodes to your cluster create or update command, e.g:
```
--enable-cluster-autoscaler --min-count 1 --max-count 5
```
> The cluster autoscaler has many more parameters, see [here](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#what-are-the-parameters-to-ca)
Run `EnableNodeScaling.ps1` to add auto-scaling to a running cluster.
To enable Pod scaling (full details [here](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) and [tutorial](https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-scale)), specify resources *per* container in a Pod, e.g:
```
resources:
requests: # Minimum
cpu: 250m
limits: # Maximum
cpu: 250m
```
Above states that the container requests at least *and* at most 250 milli CPU (i.e. 25% CPU).
Next add a `HorizontalPodAutoscaler`, for example:
```
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: commerce
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: commerce
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50 # Target is 50% of the requested CPU accros all pods, i.e. 50% of 250 milli CPU in this case
```
Above spec requests to add a Pod when the CPU load for a single Pod, which is the minimum and initial situation, goes above 50% of the requested 250 milli CPU.
See [here](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/) for full details.
# Trigger load
To trigger some load we will use K6 Loadimpact.
In `loadtest.js` a single product is added to the cart.
To run this cart addition for 30 seconds and 100 virtual users do:
```
PS> docker run -i loadimpact/k6 run -u 100 -d 30s -< loadtest.js
```
Monitor the number of Pod replicas by:
```
PS> kubectl get pod -w
```
Inspect the Horizontal Pod Autoscaler:
```
PS> kubectl get hpa
```
and a full description of its actions:
```
PS> kubectl describe hpa
```
The autoscaler by default queries every 15 seconds for metrics. When needed it will upscale the number
of Pods. Downscaling Pods will happen after a (default) cool down period of 5 minutes.