試すためのDeploymentを作成
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 |
apiVersion: apps/v1 kind: Deployment metadata: name: php-apache spec: selector: matchLabels: run: php-apache template: metadata: labels: run: php-apache spec: containers: - name: php-apache image: registry.k8s.io/hpa-example ports: - containerPort: 80 resources: limits: cpu: 500m requests: cpu: 200m --- apiVersion: v1 kind: Service metadata: name: php-apache labels: run: php-apache spec: ports: - port: 80 selector: run: php-apache |
適用
1 |
kubectl apply -f hpa.yaml |
オートスケールを設定
1 |
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10 |
1 2 3 |
kubectl get hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE php-apache Deployment/php-apache /50% 1 10 0 7s |
負荷コマンドを実行する
1 |
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done" |
Pod数を確認すると、増えていることがわかる。
1 2 3 4 5 6 7 8 9 |
kubectl get pod -A -o wide | grep php default php-apache-598b474864-8tdfd 1/1 Running 0 7m45s 10.1.128.253 microk8s <none> <none> default php-apache-598b474864-wzkt4 1/1 Running 0 5m55s 10.1.128.206 microk8s <none> <none> default php-apache-598b474864-szmf4 1/1 Running 0 5m55s 10.1.128.199 microk8s <none> <none> default php-apache-598b474864-4mq97 1/1 Running 0 5m55s 10.1.128.202 microk8s <none> <none> default php-apache-598b474864-c2pfr 1/1 Running 0 5m40s 10.1.128.200 microk8s <none> <none> default php-apache-598b474864-hg9bw 1/1 Running 0 5m10s 10.1.128.215 microk8s <none> <none> default php-apache-598b474864-qnjfz 1/1 Running 0 4m55s 10.1.128.217 microk8s <none> <none> default php-apache-598b474864-h8cvh 1/1 Running 0 4m55s 10.1.128.218 microk8s <none> <none> |