1、常规手动扩容缩容
可以通过:
kubectl scale 的形式在master节点上以命令的形式进行更新
亦或者:
kubectl edit deploy/sts xxxxx 通过进入yaml的文件来改里面的replicas
然后再用apply -f更新

#主要是在yaml文件中找到spec下的replicas,变更数量即可
spec:
    replicas: 3
  • 1.
  • 2.
  • 3.

2、HPA:Pod的水平自动伸缩策略。基于kube-controll-manager。可以通过周期性的检测pod的cpu使用率。通过追踪控制器(deploy或者sts)的负载变化。来达到针对性的调整pod的副本数
yaml示例:

apiVersion: apps/v1
kind: statefulset
metadata:
  name: web #statfulset控制器元数据的对象名字
spec: 
  servername: “nginx” #通过使用哪一个service来管理dns
    replicas: 2
    selector:
      matchLabels: 
        app: nginx
    template:
      metadata:
        labels:
          app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx: 1.8.0
            ports: #容器内需要暴露的端口
            - containerPort: 80 #容器内需要暴露的端口
            - name: web
            volumemounts: #加载数据卷(此处开始往下均为对存储卷的描述)
            - name: test #指定加载哪一个数据卷
              mountPath: /usr/local/share/nginx/html #指定映射到容器内的挂载位置。
volumeClaimTemplates: #数据卷模版
metadata: #数据卷元数据描述
  name: test
  annotations: 数据卷的注解
    volume.alpha.kubernetes.io/storage-class: anything
  spec:
    accessModes: [ “ReadWriteOnce” ]   #访问模式
      resources:
        requests: 
          storage: 1Gi  #需要1g的存储空间资源


#注:上面的是用sts控制器创建一个名为web。并做好相应的pv申请和pvc绑定。
#hpa在下文。
—-
apiVersion: autoscaling/v1
kind: HorizontalPodAotoscaler
metadata:
  name: hpa-test1
spec:
  scaleTargetRef:  #指定要自动缩放的扩容对象
    apiVersion: apps/v1
    kind: statefulset
    name: web
#上面指定的东西需要和最上面的statefulset控制器一致
  minReplicas: 1
  maxReplicas: 5
#最小副本数1,最大副本数5
targetCPUUtilizationPercentage: 50
#cpu 利用率的阈值
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.