zoukankan      html  css  js  c++  java
  • K8S部署Metrics-Server服务

    1.下载并解压Metrics-Server

    https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
    tar -zxvf v0.3.6.tar.gz 

    2.修改Metrics-Server配置文件

    cd metrics-server-0.3.6/deploy/1.8+/
    vim metrics-server-deployment.yaml
    

    vim metrics-server-deployment.yaml文件

    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: metrics-server
      namespace: kube-system
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: metrics-server
      namespace: kube-system
      labels:
        k8s-app: metrics-server
    spec:
      selector:
        matchLabels:
          k8s-app: metrics-server
      template:
        metadata:
          name: metrics-server
          labels:
            k8s-app: metrics-server
        spec:
          serviceAccountName: metrics-server
          volumes:
          # mount in tmp so we can safely use from-scratch images and/or read-only containers
          - name: tmp-dir
            emptyDir: {}
          containers:
          - name: metrics-server
            # 修改image 和 imagePullPolicy
            image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6
            imagePullPolicy: IfNotPresent
            # 新增command配置
            command:
            - /metrics-server
            - --kubelet-insecure-tls
            - --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
            volumeMounts:
            - name: tmp-dir
              mountPath: /tmp
            # 新增resources配置
            resources:
              limits:
                cpu: 300m
                memory: 200Mi
              requests:
                cpu: 200m
                memory: 100Mi  

    3.安装Metrics-Server

    kubectl apply -f metrics-server-0.3.6/deploy/1.8+/

    4.查看node信息

    [root@binghe101 ~]# kubectl top node
    NAME        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
    binghe101   141m         7%     1113Mi          65%       
    binghe102   62m          3%     549Mi           32% 
    binghe103   100m         5%     832Mi           48%

     5、测试HPA

    1)、创建部署deployment

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 2
      selector:
         matchLabels:
           app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: docker.io/nginx
            ports:
            - containerPort: 80
            resources:
              limits:
                 cpu: 500m
              requests:
                 cpu: 500m 
    

    2)、设定自动扩容的条件

    kubectl autoscale deployment hpa-demo --cpu-percent=10 --min=1 --max=10
    

     --cpu-percent=10      cpu使用率超过10%

    3)、使用ab工具进行压测

    ab -c 5000 -n 2000000 http://10.244.1.10:80/
    

    10.244.1.10  ---为pod的ip

    4)、发现pod数量会增长

  • 相关阅读:
    英特尔“硬盘内存一体化”首款产品正式发布,读写速度超千倍,存储密度扩充十倍
    程序员,你为什么值这么多钱?
    不懂程序看的明白《黑客帝国》吗?
    程序员的工作、学习与绩效
    架构设计师能力模型
    .net平台的MongoDB使用
    转载-30分钟搞定后台登录界面(103个后台PSD源文件、素材网站)
    XAF-DevExpress.ExpressApp.DC.Xpo.XpoTypeInfoSource 生成实体的过程-学习笔记
    谈谈敏捷开发
    XAF-由于try catch导致的性能问题一例
  • 原文地址:https://www.cnblogs.com/wuchangblog/p/14163960.html
Copyright © 2011-2022 走看看