騰訊面經分享
阿新 • • 發佈:2021-07-17
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: mirrorgooglecontainers/metrics-server-amd64:v0.3.6 imagePullPolicy: IfNotPresent command: - /metrics-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname volumeMounts: - name: tmp-dir mountPath: /tmp 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@master 1.8+]# kubectl top node NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% master 289m 7% 1315Mi 48% node01 119m 2% 910Mi 33% node02 100m 2% 628Mi 23%
5、測試HPA
1)、建立部署deployment,這裡設定副本數是1
apiVersion: v1 kind: Service metadata: name: svc-hpa namespace: default spec: selector: app: nginx type: NodePort ##注意這裡是NodePort,下面壓力測試要用到。 ports: - name: http port: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: docker.io/nginx ports: - containerPort: 80 resources: limits: cpu: 50m memory: 50Mi requests: cpu: 50m memory: 50Mi
2)、設定自動擴容的條件
kubectl autoscale deployment nginx-deployment --max=3 --min=1 --cpu-percent=50
使用ab工具進行壓測
先安裝ab
yum -y install httpd-tools -y
3)、使用ab工具進行壓測
ab -c 500 -n 2000 http://192.168.111.129:31379/
發現副本成兩個了
[root@master test]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx-deployment-859b474bd-2nnlv 1/1 Running 0 60m nginx-deployment-859b474bd-pfm4l 1/1 Running 0 4m38s
過一段時間又變成了一個
[root@master test]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx-deployment-859b474bd-2nnlv 1/1 Running 0 61m nginx-deployment-859b474bd-pfm4l 0/1 Terminating 0 5m23s [root@master test]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx-deployment-859b474bd-2nnlv 1/1 Running 0 61m
看下hpa
[root@master test]# kubectl get hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx-deployment Deployment/nginx-deployment 10%/50% 1 3 1 50m
參考部落格
https://www.icode9.com/content-4-795161.html
https://www.cnblogs.com/wuchangblog/p/14163960.html