apiVersion: v1
kind: ServiceAccount
metadata:
  name: dns-autoscaler
  namespace: kube-system

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: dns-autoscaler
rules:
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["list", "watch"]
- apiGroups: [""]
  resources: ["replicationcontrollers/scale"]
  verbs: ["get", "update"]
- apiGroups: ["apps"]
  resources: ["deployments/scale", "replicasets/scale"]
  verbs: ["get", "update"]
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "create", "list", "watch"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: dns-autoscaler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: dns-autoscaler
subjects:
- kind: ServiceAccount
  name: dns-autoscaler
  namespace: kube-system

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: dns-autoscaler
  namespace: kube-system
data:
  ladder: |-
    {
      "coresToReplicas":
      [
        [ 64, 1 ],
        [ 4096, 2 ]
      ],
      "nodesToReplicas":
      [
        [ 1, 1 ],
        [ 2, 2 ],
        [ 10, 3 ],
        [ 20, 4 ],
        [ 50, 5 ],
        [ 100, 7 ],
        [ 200, 10 ],
        [ 1000, 20 ],
        [ 2000, 50 ]
      ]
    }

---



apiVersion: apps/v1
kind: Deployment
metadata:
  name: dns-autoscaler
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dns-autoscaler
  template:
    metadata:
      labels:
        app: dns-autoscaler
    spec:
      serviceAccountName: dns-autoscaler
      containers:
      - name: autoscaler
        image: registry.cn-shenzhen.aliyuncs.com/shuhui/cluster-proportional-autoscaler:v1.9.0
        resources:
          requests:
            cpu: 20m
            memory: 10Mi
        command:
        - /cluster-proportional-autoscaler
        - --namespace=kube-system
        - --configmap=dns-autoscaler
        - --target=deployment/coredns
        - --default-params={"linear":{"preventSinglePointFailure":true,"nodesPerReplica":16,"coresPerReplica":256,"min":1,"max":50}}
        - --logtostderr=true
        - --v=2
