LoginSignup
0
0

More than 3 years have passed since last update.

KubernetesのHPAを試験する際のサンプル

Posted at

超小ネタです。メモ程度。KubernetesのHPAが正しく動作しているか確認する時のyamlのメモ書き。

前提

  • HPAの導入が済んでいる
  • HPAが正しく動いているか調査する際のコマンド

1. hpa-test.yaml を作成する

以下のファイルを作成する

hpa-test.yaml
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: hpa-deploy
  minReplicas: 1
  maxReplicas: 2
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 50
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hpa-deploy
spec:
  replicas: 1
  template:
    metadata:
      name: hpa-app
      labels:
        app: hpa-app
    spec:
      containers:
      - image: frapsoft/openssl
        name: openssl
        command: ["sh", "-c", "openssl speed -multi `grep processor /proc/cpuinfo|wc -l`"]
        resources:
          limits:
            cpu: 2700m
            memory: 4000M
          requests:
            cpu: 2700m
            memory: 4000M

以下は必要に応じてパラメータは変更ください

  • maxReplicas
  • targetAverageUtilization
  • resources.limits
  • resources.requests

2. apply する

$ kubectl apply -f hpa-test.yaml
horizontalpodautoscaler.autoscaling/hpa created
deployment.extensions/hpa-deploy created

3. hpaを確認する

直後はまだ計測できない。30秒に一回計測されるので少し待つ

$ kubectl get hpa hpa
NAME   REFERENCE               TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
hpa    Deployment/hpa-deploy   <unknown>/50%   1         2         1          42s

opensslコマンドがマルチCPUをフルで稼働させてくれるので、以下の通りに96%使用し、REPLICASが2になりスケールしている。

$ kubectl get hpa hpa
NAME   REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
hpa    Deployment/hpa-deploy   96%/50%   1         2         2          2m51s
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0