kind: Deployment
apiVersion: apps/v1
metadata:
  name: cluster-autoscaler
  namespace: kube-system
  labels:
    app: cluster-autoscaler
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cluster-autoscaler
  template:
    metadata:
      namespace: kube-system
      labels:
        app: cluster-autoscaler
    spec:
      tolerations:
        - effect: NoSchedule
          key: node-role.kubernetes.io/control-plane
      # Node affinity is used to force cluster-autoscaler to stick
      # to the macontrol-plane node. This allows the cluster to reliably downscale
      # to zero worker nodes when needed.
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/control-plane
                operator: Exists
      serviceAccountName: cluster-autoscaler
      containers:
        - name: cluster-autoscaler
          image: registry.k8s.io/autoscaling/cluster-autoscaler:latest
          imagePullPolicy: Always
          env:
            - name: BOOTSTRAP_TOKEN_ID
              valueFrom:
                secretKeyRef:
                  name: bootstrap-token-cluster-autoscaler-cherry
                  key: token-id
            - name: BOOTSTRAP_TOKEN_SECRET
              valueFrom:
                secretKeyRef:
                  name: bootstrap-token-cluster-autoscaler-cherry
                  key: token-secret
            - name: CHERRY_AUTH_TOKEN
              valueFrom:
                secretKeyRef:
                  name: cluster-autoscaler-cherry
                  key: authtoken
          # You can take advantage of multiple nodepools by adding
          # extra arguments on the cluster-autoscaler command.
          # e.g. for pool1, pool2
          # --nodes=0:10:pool1
          # --nodes=0:10:pool2
          command:
            - ./cluster-autoscaler
            - --alsologtostderr
            - --cluster-name=cluster1
            - --cloud-config=/config/cloud-config
            - --cloud-provider=cherryservers
            - --nodes=0:10:pool1
            - --nodes=0:10:pool2
            - --scale-down-unneeded-time=1m0s
            - --scale-down-delay-after-add=1m0s
            - --scale-down-unready-time=1m0s
            - --v=2
          volumeMounts:
            - name: cloud-config
              mountPath: /config
              readOnly: true
      volumes:
        - name: cloud-config
          secret:
            secretName: cluster-autoscaler-cloud-config
