Horizontal Pod Autoscaler
score.yaml
(view on GitHub)
:
apiVersion: score.dev/v1b1
metadata:
name: my-workload
containers:
my-container:
image: busybox
command: ["/bin/sh"]
args: ["-c", "while true; do echo Hello HPA; sleep 5; done"]
resources:
hpa:
type: horizontal-pod-autoscaler
params: # optional
minReplicas: 2
maxReplicas: 3
targetCPUUtilizationPercentage: 80
10-hpa.provisioners.yaml
(view on GitHub)
:
- uri: template://community-provisioners/empty-hpa
type: horizontal-pod-autoscaler
description: Generates an empty object because HPA is not supported in Docker Compose.
Initialize your local workspace, by importing a specific community provisioner:
score-commpose init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
by the actual provisioner file you want to use and import. More information here.
Get the provisioners definition:
score-compose provisioners list
Generate the platform specific manifests:
score-commpose generate score.yaml
See the resource outputs:
score-commpose resources list
You can run the following command on each resource listed with the previous command to get their outputs
:
score-commpose resources get-outputs
Deploy the generated manifests:
docker compose up -d
See the running containers:
docker ps
10-hpa.provisioners.yaml
(view on GitHub)
:
- uri: template://community-provisioners/default-hpa
type: horizontal-pod-autoscaler
description: Generates an HorizontalPodAutoscaler manifest.
supported_params:
- maxReplicas
- minReplicas
- targetCPUUtilizationPercentage
init: |
defaultMaxReplicas: 3
defaultMinReplicas: 2
absoluteMaxReplicas : 10
defaultTargetCPUUtilizationPercentage: 80
manifests: |
- apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ .SourceWorkload }}
{{ if ne .Namespace "" }}
namespace: {{ .Namespace }}
{{ end }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .SourceWorkload }}
minReplicas: {{ .Params.minReplicas | default .Init.defaultMinReplicas }}
maxReplicas: {{ .Params.maxReplicas | default .Init.defaultMaxReplicas | min .Init.absoluteMaxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Params.targetCPUUtilizationPercentage | default .Init.defaultTargetCPUUtilizationPercentage }}
Initialize your local workspace, by importing a specific community provisioner:
score-k8s init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
by the actual provisioner file you want to use and import. More information here.
Get the provisioners definition:
score-k8s provisioners list
Generate the platform specific manifests:
score-k8s generate score.yaml
See the resource outputs:
score-k8s resources list
You can run the following command on each resource listed with the previous command to get their outputs
:
score-k8s resources get-outputs
Deploy the generated manifests:
kubectl apply -f manifests.yaml
See the running containers:
kubectl get all