上記からの、https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/ を実施してみる。
kind でクラスタ準備
HPA なのでスケールアップさせるための worker ノードは増やしておく。
kind のための config yaml は以下のように。
$ more config-cluster.yaml
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
- role: worker
クラスタ作る
$ kind create cluster --config config-cluster.yaml
・・・略・・・
$ kind get clusters
kind
$ kind get nodes
kind-worker
kind-control-plane
kind-worker2
$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:45537
KubeDNS is running at https://127.0.0.1:45537/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
metrics-server 入れる
HPA するのに必要なのでセットアップしないといけない。
がしかし、上記を元に、以下のようにやるとうまくいかない。
kubectl apply -f deploy/1.8+/
Pod は Running になるが、できあがったログみると、ノードや Pod の metrics フェッチできないよというエラー。
unable to fetch node metrics for node "kind-control-plane": no metrics known for node
ISSUE 確認すると 2019/9/4 現在で OPEN 中。
https://github.com/kubernetes-sigs/kind/issues/398
minikube とか microk8s みたく専用の addon にしたらいいんじゃないのとか、
途中に kind 用の metrics-server デプロイするための YAML 提示しているのがあり、
それを apply させていただいたら、いけた。
$ kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
kind-control-plane 107m 5% 438Mi 5%
kind-worker 431m 21% 297Mi 3%
kind-worker2 208m 10% 277Mi 3%
Henning Jacobs さんご提供
https://gist.github.com/hjacobs/69b6844ba8442fcbc2007da316499eb4
HPA リソース作る
$ kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
Workthrough の php-apache が作った HPA リソースにももとづき、負荷あげるとスケールアップ、なくなるとスケールダウンする。