---
# System prepended metadata

title: Auto-Scaling
tags: [DevOps, Infra, III]

---

Auto-Scaling
===

###### tags: `III` `DevOps` `Infra`

## Terminology
- 水平擴展 scale out: 增加服務的 pod、增加服務的機器
- 垂直擴展 scale up: 同一台服務的機器增加 cpu、memory

## Add worker node
在 master node
```
kubeadm token list
```
```
kubeadm token create --print-join-command
```
在 worker node
```
kubeadm join 192.168.2.16:6443 \
  --token s8o9wi.dylbvs735sy53mmq \
  --discovery-token-ca-cert-hash sha256:0c16a05978533ca8f44af6e779162a1c99516fa2a4acd81915f0379755a856bc
```
會用到的 [kubeadm join 的參數](
https://blog.scottlowe.org/2019/08/15/reconstructing-the-join-command-for-kubeadm/)

---

## Useful Commands
- [K8s 安裝筆記 - kubeadm 手動 (ubuntu 16.04 / ubuntu 18.04)](https://rickhw.github.io/2019/03/17/Container/Install-K8s-with-Kubeadm/)
- [kubeadm reset](https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-reset/)
- [reset 參考命令](http://gitvepc/abby/tools/-/blob/master/k8s_init_setup_bash.sh)

---

## Metrics Server
HPA 會用到 metrics server 提供的 metrics
* Only for CPU & memory
```
helm install -f metric-server-values.yml --namespace kube-system gitlab-runner stable/metrics-server
```
```
# metric-server-values.yml
args: ["--kubelet-insecure-tls", "--kubelet-preferred-address-types=InternalIP"]
```
等一下，測試
```
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"
kubectl top nodes
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods"
kubectl top pod -n <NAMESPACE>
```
* [Setting up a Custom Metrics Server](https://github.com/stefanprodan/k8s-prom-hpa#setting-up-a-custom-metrics-server)
  * Prometheus
http://10.22.100.231:31190/
http://10.22.100.233:31190/
  * Custom Metrics Server
  ```
  kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/5gc/pods/*/gitlab_runner_version_info" | jq
  ```