Git Product home page Git Product logo

kubez-autoscaler's Introduction

Kubez-autoscaler Overview

kubez-autoscaler 通过为 deployment / statefulset 添加 annotations 的方式,自动维护对应 HorizontalPodAutoscaler 的生命周期.

Prerequisites

kubernetes 集群中, 需要先完成 Metrics Server 组件的安装,请参考 Metrics Server

kubectl top node/pod 验证 Metrics Server 已成功安装

# kubectl top node
NAME          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
kubez         333m         16%    1225Mi          65%

# kubectl top pod
NAME                     CPU(cores)   MEMORY(bytes)
test1-54cd855b77-q67h6   1m           3Mi

Installing

kubez-autoscaler 控制器的安装非常简单,通过 kubectl 执行 apply 如下文件即可完成安装,真正做到猩猩都能使用.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: kubez
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: kubez
rules:
  - apiGroups:
      - "*"
    resources:
      - horizontalpodautoscalers
      - deployments
      - statefulsets
      - endpoints
      - leases
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubez
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kubez
subjects:
- kind: ServiceAccount
  name: kubez
  namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    kubez.hpa.controller: kubez-autoscaler
  name: kubez-autoscaler-controller
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      kubez.hpa.controller: kubez-autoscaler
  template:
    metadata:
      labels:
        kubez.hpa.controller: kubez-autoscaler
    spec:
      containers:
        - image: jacky06/kubez-autoscaler-controller:v0.0.1
          command:
            - kubez-autoscaler-controller
            - --leader-elect=true
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 8
            httpGet:
              host: 127.0.0.1
              path: /healthz
              port: 10256
              scheme: HTTP
            initialDelaySeconds: 15
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 15
          resources:
            requests:
              cpu: 100m
              memory: 90Mi
          name: kubez-autoscaler-controller
      serviceAccountName: kubez

然后通过 kubectl get pod -l kubez.hpa.controller=kubez-autoscaler 能看到 kubez-autoscaler 已经启动成功.

NAME                                          READY   STATUS    RESTARTS   AGE
kubez-autoscaler-controller-dbc4bc4d8-hwpqz   1/1     Running   0          20s
kubez-autoscaler-controller-dbc4bc4d8-tqxrl   1/1     Running   0          20s

Getting Started

deployment / statefulsetannotations 中添加所需注释即可自动创建对应的 HPA

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    ...
    hpa.caoyingjunz.io/minReplicas: "2"  # MINPODS
    hpa.caoyingjunz.io/maxReplicas: "6"  # MAXPODS
    cpu.hpa.caoyingjunz.io/targetAverageUtilization: "60"  # TARGETS
    ...
  name: test1
  namespace: default
  ...

kubez-autoscaler-controller 会根据注释的变化,自动同步 HPA 的生命周期.

通过 kubectl get hpa test1 命令,可以看到 deployment / statefulset 关联的 HPA 被自动创建

NAME    REFERENCE          TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
test1   Deployment/test1   6% / 60%        1         2         1          5h29m

kubez-autoscaler's People

Contributors

caoyingjunz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.