一、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. (转)word尾注引文添加方式及相关问题

    word引文添加方式:http://www.office68.com/word/word-reference-add.html word通配符:http://www.3lian.com/edu/201 ...

  2. 全新的membership框架Asp.net Identity——绕不过的Claims

    http://www.cnblogs.com/JustRun1983/p/4708176.html?utm_source=tuicool&utm_medium=referral

  3. WPF Expander控件(扩展面板)

    这算是我比较喜欢的一个控件,以前在Winform中也常用类似的.它包装了一块内容,通过单击一个小箭头按钮可以显示或隐藏所包含的内容.在线帮助以及Web页面经常使用这种技术,因为既可以包含大量内容,而又 ...

  4. cocos2d-x 3.0 使用.plist图片集方法

    这个贴.仅仅是为了和我一样的新手,更快的索引. 我使用的是SpritePacker 软件来制作 .plist SpriteFrameCache *frameCache = SpriteFrameCac ...

  5. Spring_day02--AOP概念、原理、操作术语

    AOP概念 hibernate要手动进行事务操作,在spring中通过配置文件来配置事务 1 aop:面向切面(方面)编程,扩展功能不修改源代码实现 2  AOP采取横向抽取机制,取代了传统纵向继承体 ...

  6. 第十篇:Linux中权限的再讨论( 上 )

    前言 在Linux系统中,用户分为 个权限位.好了,很多朋友对于Linux权限的了解就仅限于此了.但,Linux目录权限和文件权限一样吗?内核对于权限的检查过程又是怎样的? 如果你不清楚,本文将为你解 ...

  7. JDBC通用DAO

    dbcBaseDao接口,内容如下: package com.sun4j.core.jdbc.dao; import java.io.Serializable; import java.util.Li ...

  8. Python闲谈(一)mgrid慢放

    不论是利用Mayavi还是matplotlib绘制三维图表,里面都用到了numpy中的一个函数叫mgrid.本次博客我简单地讲一下mgrid是干什么用的,以及一个三维曲面是如何绘制出来的. 首先说明一 ...

  9. onbeforeunload 适用DOM 0级,不适用 DOM 2级

    你可以在控制台试下: window.addEventListener("beforeunload", function () { return 'ss'; }); 我这里 chro ...

  10. typecho与wordpress

    相信玩博客的人对这两个程序会相当熟悉把. 有些人玩了很久WP之后又转向了typecho 之后又回到wp.举个例子typecho犹如一个美丽的裸体女人.wp就是一个穿着绫罗绸缎的女人. 当你看着裸体一天 ...