一、Metrics-server安装:

由于使用自动扩容,得安装heapster或metrics-server(由于heapster停止更新故用metrics-server):

1、安装之前需要为kubernetes增加配置项:

1、为/etc/kubernetes/controller-manager增加启动项:
***
--horizontal-pod-autoscaler-use-rest-clients=true
***
systemctl restart kube-controller-manager 2、为/usr/lib/systemd/system/kube-apiserver.service增加启动项(也可以修改/etc/kubernetes/apiserver文件增加):
***
    --requestheader-client-ca-file=/etc/kubernetes/ssl/ca.pem \
    --requestheader-allowed-names=  \
    --requestheader-extra-headers-prefix=X-Remote-Extra- \
    --requestheader-group-headers=X-Remote-Group \
    --requestheader-username-headers=X-Remote-User \
    --proxy-client-cert-file=/etc/kubernetes/ssl/kubelet-client.crt \
    --proxy-client-key-file=/etc/kubernetes/ssl/kubelet-client.key \
    --enable-aggregator-routing=true
***
systemctl daemon-reload
systemctl restart kube-apiserver

2、在kubenetes上安装Metrics-server:

1、创建:
kubectl create -f metrics-server.yml 2、删除:
kubectl delete ServiceAccount metrics-server -n kube-system
kubectl delete ClusterRoleBinding metrics-server:system:auth-delegator -n kube-system
kubectl delete RoleBinding metrics-server-auth-reader -n kube-system
kubectl delete ClusterRole system:metrics-server -n kube-system
kubectl delete ClusterRoleBinding system:metrics-server -n kube-system
kubectl delete APIService v1beta1.metrics.k8s.io -n kube-system
kubectl delete Service metrics-server -n kube-system
kubectl delete Deployment metrics-server -n kube-system 注:要修改metrics-server的镜
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: metrics-server-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- "extensions"
resources:
- deployments
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
---
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1beta1.metrics.k8s.io
spec:
service:
name: metrics-server
namespace: kube-system
group: metrics.k8s.io
version: v1beta1
insecureSkipTLSVerify: true
groupPriorityMinimum: 100
versionPriority: 100
---
apiVersion: v1
kind: Service
metadata:
name: metrics-server
namespace: kube-system
labels:
kubernetes.io/name: "Metrics-server"
spec:
selector:
k8s-app: metrics-server
ports:
- port: 443
protocol: TCP
targetPort: 443
---
apiVersion: apps/v1beta2
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
containers:
- name: metrics-server
# image: gcr.io/google_containers/metrics-server-amd64:v0.2.1
image: 144.202.127.156/google_containers/metrics-server-amd64:v0.2.1
imagePullPolicy: Always
command:
- /metrics-server
- --source=kubernetes.summary_api:''
resources:
requests:
cpu: 20m
memory: 200Mi
limits:
cpu: 100m
memory: 500Mi

metrics-server.yml

3、验证:

1、创建测试资源:
kubectl create -f nginx.yml 2、创建自动伸缩规则:
kubectl autoscale deployment nginx --cpu-percent=75 --min=2 --max=10
kubectl get hpa NAME           REFERENCE                 TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
bill-service   Deployment/bill-service   0% / 80%   5         10        5          2h
注:TARGETS出现 <unknown> / 80% 说明没有成功就得看metrics-server的日志和hpa的describe来查找原因了。 3、测试是否生效(使用脚本测):
python pressure-web.py
kubectl get hpa
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
selector:
app: nginx
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 50m
memory: 50Mi
ports:
- containerPort: 80
name: web

nginx-php.yml

import requests,time,threading

url = "https://www.baidu.com"
requests_timeout = 2 def get_response_time(url,count,ring):
start_time = time.time()
try:
req_obj = requests.get(url,timeout=requests_timeout)
except requests.exceptions.ReadTimeout as e:
status = False
else:
status = True
end_time = time.time()
requests_time = end_time-start_time
if status and (req_obj.status_code == requests.codes.ok) :
requests_status = "OK"
else:
requests_status = "NO"
print("第%s轮,第%s连接,请求用时(s):%s,返回状态:%s"%(ring,count,requests_time,requests_status)) if __name__ == "__main__":
'''在规定超时时间内,11秒内处理不了100个请求,请求就会累积,一直拖垮'''
ring = 1
while True:
for count in range(100):
t = threading.Thread(target=get_response_time,args=(url,count,ring))
time.sleep(0.01)
t.start()
time.sleep(10)
ring += 1
print("第%s轮开始"%ring)

pressure-web.py

 

kubernetes Metrics-server 安装的更多相关文章

  1. kubeadm1.14.1 安装Metrics Server

    Metrics API 介绍Metrics-Server之前,必须要提一下Metrics API的概念 Metrics API相比于之前的监控采集方式(hepaster)是一种新的思路,官方希望核心指 ...

  2. kubernetes之配置Metrics Server

    Kubernetes 1.8 关于资源使用情况的 metrics,可以通过 Metrics API 获取到, Kubernetes 1.11 已经废弃 heapster.这里我们基于 Kubernet ...

  3. k8s搭建监控:安装metrics server和dashboard

      安装metrics server 参考:https://github.com/kubernetes-sigs/metrics-server kubectl  create -f component ...

  4. 启用k8s metrics server监控

    1.创建aggregator证书 方法一:直接使用二进制源码包安装 $ wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 $ chmod +x cfs ...

  5. Kubernetes集群安装(自己搭过,已搭好)

    k8s安装目录 1. 组件版本 && 集群环境 组件版本 etcd 集群 && k8s master 机器 && k8s node 机器 集群环境变量 ...

  6. K8S原来如此简单(五)Metrics Server与HPA

    什么是HPA https://kubernetes.io/zh/docs/tasks/run-application/horizontal-pod-autoscale/ 我们前面有通过kubectl ...

  7. [经验交流] Kubernetes Nginx Ingress 安装与使用

    Ingress 介绍 Kubernetes 上部署的微服务运行在它的私有网络中, 通过Pod实例的hostPort或Service实例的NodePort可以暴露到主机端口上,便于用户访问.但这样的方法 ...

  8. kubernetes实践之一:kubernetes二进制包安装

    kubernetes二进制部署 1.环境规划 软件 版本 Linux操作系统 CentOS Linux release 7.6.1810 (Core) Kubernetes 1.9 Docker 18 ...

  9. kubernetes 1.14安装部署metrics-server插件

    简单介绍: 如果使用kubernetes的自动扩容功能的话,那首先得有一个插件,然后该插件将收集到的信息(cpu.memory..)与自动扩容的设置的值进行比对,自动调整pod数量.关于该插件,在ku ...

  10. kubernetes 源码安装部署 1.12

    一. 前期准备 参考文档 https://jimmysong.io/kubernetes-handbook/practice/create-tls-and-secret-key.html 1. 安装g ...

随机推荐

  1. int main(int argc, char *argv[])中的argc和argv

    argc 是 argument count的缩写,表示传入main函数的参数个数: argv 是 argument vector的缩写,表示传入main函数的参数序列或指针,并且第一个参数argv[0 ...

  2. a &a &a[0]之间的区别和联系

    数组中,a为数组的首地址,&a[0]为数组第一个元素的地址. 所以 a == &a[0] 但是,&a又是什么东西呢? 我们来做下面的代码测试: #include <std ...

  3. Hibernate_day03--Hibernate多对多操作

    Hibernate多对多操作 多对多映射配置 以用户和角色为例演示 第一步 创建实体类,用户和角色 第二步 让两个实体类之间互相表示 (1)一个用户里面表示所有角色,使用set集合 具体: User. ...

  4. uva 110 Meta-Loopless Sorts 用程序写程序 有点复杂的回溯水题

    题目要求写一个直接用比较排序的pascal程序,挺有趣的一题. 我看题目数据范围就到8,本来以为贪个小便宜,用switch输出. 然后发现比较次数是阶乘级别的,8的阶乘也是挺大的,恐怕会交不上去. 于 ...

  5. SSH电力项目一 搭建Hibernate框架

    Hibernate所需要的基本文件: ElectText.java ElecText.hbm.xml hibernate.cfg.xml 第一步:创建测试表Elec_Text: create tabl ...

  6. fieldmeta 基于springboot的字段元数据管理,通用代码生成,快速开发引擎

    fieldmeta: 基于springboot的字段元数据管理 version:Alpha 0.0.1 ,码云地址:https://gitee.com/klguang/fieldmeta 元数据(Me ...

  7. Spring的AOP细节理解

    什么是AOP?AOP:是面向切面编程,是对面向对象编程(oop)的一种补充,为什么需要AOP?例如在我们做一个计算器,要求我们每次运行对应的功能(也就是进行运算时)都要输出日志,以便于知道程序是怎么运 ...

  8. SVN备份及恢复

    一,SVN备份 svnadmin dump /data/svn/blzfmima/ > /tmp/full.svn.bak 其中/data/svn/blzfmima/为svn文件夹,导出成一个备 ...

  9. jsp+servlet+mvc模式图

    在我们的开发中,最常用的开发模式莫过于MVC模式,即M--MODEL.V--View.C--Controller,这样不仅可以方便开发人员分工协作,提高开发效率,增强程序的可维护性和拓展性,而且利用C ...

  10. Servlet------>jsp自定义标签3(不显示余下jsp内容)

    2.自定义标签控制,jsp页面余下标签是否继续执行 EndTag.java package tag; import javax.servlet.jsp.JspException; import jav ...