Horizontal Pod Autoscaler Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:


===With Metadata===
===With Metadata===
<syntaxhighlight lang='yaml'>
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: example
spec:
  minReplicas: 1
  maxReplicas: 5
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: httpd
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50
</syntaxhighlight>
===Playground===
===Playground===
{{External|https://github.com/ovidiuf/playground/tree/master/kubernetes/horizontal-pod-autoscaler}}
{{External|https://github.com/ovidiuf/playground/tree/master/kubernetes/horizontal-pod-autoscaler}}

Revision as of 19:35, 12 October 2020

Internal

Create an Autoscaler

CPU-Based Autoscaler

For the autoscaler to work, the pods subject to autoscaling must have their CPU requests set.

With CLI

kubectl autoscale deployment <deployment-name> --cpu-percent=50 --min=1 --max=10

With Metadata

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: example
spec:
  minReplicas: 1
  maxReplicas: 5
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: httpd
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50

Playground

https://github.com/ovidiuf/playground/tree/master/kubernetes/horizontal-pod-autoscaler