Skip to content

Latest commit

 

History

History
131 lines (107 loc) · 4.13 KB

File metadata and controls

131 lines (107 loc) · 4.13 KB

documentation

example

steps

  • check cpu load (find min and max usage )
  • add request / limit
  • create HPA
  • check result
watch -n 1  'kubectl top po  -n prod-jobs ; kubectl get po -n prod-jobs '

# max usage (usage time)

NAME                   CPU(cores)   MEMORY(bytes)
app-6f6846bc44-8hfm6   267m         1Mi
NAME                   READY   STATUS    RESTARTS   AGE
app-6f6846bc44-8hfm6   1/1     Running   0          20m


# min usage  (idle  time)

NAME                   CPU(cores)   MEMORY(bytes)
app-6f6846bc44-8hfm6   15m          1Mi
NAME                   READY   STATUS    RESTARTS   AGE
app-6f6846bc44-8hfm6   1/1     Running   0          21m

276/15 *100 = 1840 % (increase )

# update deployment (add resources.limits.cpu     resources.requests.cpu
#  k edit  deployment app  -n prod-jobs

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"app":"app"},"name":"app","namespace":"prod-jobs"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"app"}},"strategy":{},"template":{"metadata":{"creationTimestamp":null,"labels":{"app":"app"}},"spec":{"containers":[{"env":[{"name":"ENABLE_LOAD_CPU","value":"true"},{"name":"CPU_MAXPROC","value":"1"},{"name":"CPU_USAGE_PROFILE","value":"1=800=1=60 1=30=1=60"}],"image":"viktoruj/ping_pong","name":"ping-pong-cp6bg","resources":{}}]}}},"status":{}}
  creationTimestamp: "2024-02-02T04:38:24Z"
  generation: 2
  labels:
    app: app
  name: app
  namespace: prod-jobs
  resourceVersion: "3100"
  uid: c4f19a91-8549-4424-83fd-814d79291d3e
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: app
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: app
    spec:
      containers:
      - env:
        - name: ENABLE_LOAD_CPU
          value: "true"
        - name: CPU_MAXPROC
          value: "1"
        - name: CPU_USAGE_PROFILE
          value: 1=800=1=120 1=30=1=30
        image: viktoruj/ping_pong
        imagePullPolicy: Always
        name: ping-pong-cp6bg
        resources:                                        # add
          limits:                                         # add
            cpu: 400m                                     # add
          requests:                                       # add
            cpu: 20m                                      # add
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30



k  autoscale deployment app --cpu-percent=500 --min=2 --max=6 -n   prod-jobs
watch -n 1  'kubectl top po  -n prod-jobs ; kubectl get po -n prod-jobs ; kubectl get hpa -n  prod-jobs '
Every 1.0s: kubectl top po  -n prod-jobs ; kubectl get po -n prod-jobs ; kubectl get hpa -n  prod-jobs                                 worker: Fri Feb  2 06:00:06 2024

NAME                   CPU(cores)   MEMORY(bytes)
app-569b78dcb4-4cs6z   262m         1Mi
app-569b78dcb4-6zktc   210m         1Mi
app-569b78dcb4-zsf9z   14m          1Mi
NAME                   READY   STATUS    RESTARTS   AGE
app-569b78dcb4-4cs6z   1/1     Running   0          40m
app-569b78dcb4-6zktc   1/1     Running   0          2m40s
app-569b78dcb4-cnmcj   1/1     Running   0          10s
app-569b78dcb4-f5rjq   1/1     Running   0          10s
app-569b78dcb4-rvlrn   1/1     Running   0          10s
app-569b78dcb4-zsf9z   1/1     Running   0          6m32s
NAME   REFERENCE        TARGETS     MINPODS   MAXPODS   REPLICAS   AGE
app    Deployment/app   873%/500%   2         6         3          3m25s