|
|
|
@ -0,0 +1,861 @@
|
|
|
|
|
# Kubernetes 动态自动扩容HPA&VPA
|
|
|
|
|
|
|
|
|
|
作者:行癫(盗版必究)
|
|
|
|
|
|
|
|
|
|
------
|
|
|
|
|
|
|
|
|
|
## 一、部署 metrics-server 环境
|
|
|
|
|
|
|
|
|
|
### 1、下载部署清单文件
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
[root@k8s-master metrics-server]# wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.4/components.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2、修改components.yaml文件
|
|
|
|
|
|
|
|
|
|
- 修改了镜像地址,gcr.io为阿里仓库
|
|
|
|
|
- 修改了metrics-server启动参数args,要不然会报错`unable to fully scrape metrics from source kubelet_summary...`
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- args:
|
|
|
|
|
- --cert-dir=/tmp
|
|
|
|
|
- --secure-port=4443
|
|
|
|
|
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
|
|
|
|
|
- --kubelet-use-node-status-port
|
|
|
|
|
- --metric-resolution=15s
|
|
|
|
|
- --kubelet-insecure-tls # 添加忽略证书
|
|
|
|
|
image: registry.cn-hangzhou.aliyuncs.com/rainux/metrics-server:v0.6.4 # 修改镜像地址微阿里云
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3、执行部署
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
[root@k8s-master metrics-server]# kubectl apply -f components.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 4、验证
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
[root@k8s-master metrics-server]# kubectl get po -n kube-system
|
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
|
metrics-server-7947cb98b6-xw6b8 1/1 Running 0 10m
|
|
|
|
|
|
|
|
|
|
# 能获取要top信息视为成功
|
|
|
|
|
[root@k8s-master metrics-server]# kubectl top nodes
|
|
|
|
|
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
|
|
|
|
|
k8s-node001 618m 7% 4796Mi 15%
|
|
|
|
|
k8s-node003 551m 6% 5522Mi 17%
|
|
|
|
|
k8s-node004 308m 3% 5830Mi 18%
|
|
|
|
|
k8s-node005 526m 6% 5997Mi 38%
|
|
|
|
|
k8s-node002 591m 7% 5306Mi 33%
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 二、HPA 实现Pod水平(横向)自动扩缩容
|
|
|
|
|
|
|
|
|
|
- Horizontal Pod Autoscaler(HPA)POD 横向自动扩展
|
|
|
|
|
- HPA 与 RC、Deployment 一样,也属于 Kubernetes 资源对象。
|
|
|
|
|
- 通过追踪分析 RC 或 RS 控制的所有目标 Pod 的负载变化情况,来确定是否需要针对性地调整目标 Pod 的副本数。
|
|
|
|
|
- HPA 有以下方式作为 Pod 负载的度量指标:
|
|
|
|
|
- CPU Utilization Percentage (CPU利用率百分比)
|
|
|
|
|
- 应用程序自定义的度量指标,比如服务在每秒内的相应的请求数( TPS 或 QPS )。
|
|
|
|
|
- CPU Utilization Percentage 是一个算术平均值,即目标 Pod 所有副本自带的 CPU 利用率的平均值。
|
|
|
|
|
- Pod 自身的 CPU 利用率是该 Pod 当前 CPU 的使用量除以它的Pod Request 的值,比如我们定义一个 Pod 的 Pod Request 为 0.4,而当前 Pod 的 CPU 使用量为 0.2,则它的 CPU 使用率为 50%,这样就可以算出来一个 RC 或 RS 控制的所有 Pod 副本的 CPU 利用率的算术平均值。
|
|
|
|
|
- 如果某一时刻CPU Utilization Percentage的值超过 80%,则意味着当前的 Pod 副本数很可能不足以支撑接下来更多的请求,需要进行动态扩容,而当请求高峰时段过去后,Pod 的 CPU 利用率又会降下来,此时对应的Pod副本数应该自动减少到一个合理的水平。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 支持对象:DeploymentConfig、ReplicationController、Deployment、Replica Set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- RS可以通过HPA来根据一些运行时指标实现自动伸缩,下面是一个简单的例子:(**需要安装 metrics-server**)
|
|
|
|
|
|
|
|
|
|
### 1、创建 Deployment
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
[root@k8s-master hpa]# cat <<EOF>> nginx-hpa-dep.yaml
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-hpa-dep
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 1
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app: nginx
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx
|
|
|
|
|
labels:
|
|
|
|
|
app: nginx
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: nginx
|
|
|
|
|
image: nginx
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
cpu: 20m
|
|
|
|
|
ports:
|
|
|
|
|
- containerPort: 80
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2、创建 services
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
[root@k8s-master hpa]# cat <<EOF>> nginx-hpa-svc.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-hpa-svc
|
|
|
|
|
spec:
|
|
|
|
|
type: NodePort
|
|
|
|
|
ports:
|
|
|
|
|
- port: 80
|
|
|
|
|
targetPort: 80
|
|
|
|
|
nodePort: 30008
|
|
|
|
|
selector:
|
|
|
|
|
app: nginx
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3、创建 HPA
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
[root@k8s-master hpa]# cat <<EOF>> nginx-hpa.yaml
|
|
|
|
|
apiVersion: autoscaling/v1
|
|
|
|
|
kind: HorizontalPodAutoscaler
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-hpa
|
|
|
|
|
spec:
|
|
|
|
|
scaleTargetRef: # 要给那个对象扩容
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
name: nginx-hpa
|
|
|
|
|
minReplicas: 1 # 缩容时候最少保留的pod数量
|
|
|
|
|
maxReplicas: 10 # 扩容最大能够扩的pod数量
|
|
|
|
|
targetCPUUtilizationPercentage: 50 # cpu平均使用率达到50%就开始扩容
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 4、创建资源
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master hpa]# kubectl apply -f dep.yaml
|
|
|
|
|
[root@k8s-master hpa]# kubectl apply -f svc.yaml
|
|
|
|
|
[root@k8s-master hpa]# kubectl apply -f hpa.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 5、进行压力测试
|
|
|
|
|
|
|
|
|
|
- 创建压力测试 Pod
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
[root@k8s-master hpa]# cat <<EOF>> ab-pod.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: load-generator
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: busybox
|
|
|
|
|
image: busybox
|
|
|
|
|
command: ["sleep", "3600"]
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 进入测试 Pod 中的容器中进行压力测试
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 执行压测命令
|
|
|
|
|
while true; do wget -q -O- http://nginx-hpa-svc > /dev/null; done
|
|
|
|
|
# 或node执行nodeport的端口压测
|
|
|
|
|
ab -c 1000 -n 100000000 http://127.0.0.1:30792/index.html
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 用命令的方式实现
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 增加负载
|
|
|
|
|
[root@k8s-master hpa]# kubectl run -i --tty load-generator --image=busybox:latest /bin/sh
|
|
|
|
|
# 进入容器后执行一下命令
|
|
|
|
|
while true; do wget -q -O- http://nginx-hpa-svc.default.svc.cluster.local; done
|
|
|
|
|
# 或者
|
|
|
|
|
ab -c 1000 -n 100000000 http://127.0.0.1:30792/index.html
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 6、验证效果
|
|
|
|
|
|
|
|
|
|
- 压测几分钟后查看hpa状态,如果cpu压力超过了设置的阈值,可以停止压测。
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 开始查看状态
|
|
|
|
|
[root@k8s-master hpa]# kubectl get hpa
|
|
|
|
|
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
|
|
|
|
|
php-apache Deployment/php-apache 5%/50% 1 10 10 6m5s
|
|
|
|
|
# 过1分钟左右再次检查HPA状态和部署状态
|
|
|
|
|
[root@k8s-master hpa]# kubectl get hpa
|
|
|
|
|
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
|
|
|
|
|
php-apache Deployment/php-apache 460%/50% 1 10 10 4m25s
|
|
|
|
|
# 开始 pod 数量状态
|
|
|
|
|
[root@k8s-master hpa]# kubectl get pods
|
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
|
load-generator 1/1 Running 0 41m
|
|
|
|
|
php-apache-7ddb67b575-c8vcd 1/1 Running 0 2m40s
|
|
|
|
|
# 1 分钟后pod数量状态
|
|
|
|
|
[root@k8s-master hpa]# kubectl get pods
|
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
|
load-generator 1/1 Running 0 43m
|
|
|
|
|
php-apache-7ddb67b575-b2qkz 1/1 Running 0 2m53s
|
|
|
|
|
php-apache-7ddb67b575-c8vcd 1/1 Running 0 5m23s
|
|
|
|
|
php-apache-7ddb67b575-cpjjq 1/1 Running 0 2m37s
|
|
|
|
|
php-apache-7ddb67b575-p7rw9 1/1 Running 0 2m22s
|
|
|
|
|
php-apache-7ddb67b575-pbrzf 1/1 Running 0 2m53s
|
|
|
|
|
php-apache-7ddb67b575-pvmg9 1/1 Running 0 2m22s
|
|
|
|
|
php-apache-7ddb67b575-sw82k 1/1 Running 0 2m37s
|
|
|
|
|
php-apache-7ddb67b575-tk6tn 1/1 Running 0 2m53s
|
|
|
|
|
php-apache-7ddb67b575-xxgxw 1/1 Running 0 2m37s
|
|
|
|
|
php-apache-7ddb67b575-z2mdm 1/1 Running 0 2m37s
|
|
|
|
|
|
|
|
|
|
[root@k8s-master hpa]# kubectl get deployment php-apache
|
|
|
|
|
# 停压,等1分钟查看状态
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 查看hpa状态已经超过了阈值,此时查看pod,pod的数量已经增加了。
|
|
|
|
|
|
|
|
|
|
- 当停止压力测试之后,过一段时间(冷却时间:默认5分钟),Pod数量又会恢复到1。
|
|
|
|
|
|
|
|
|
|
## 三、VPA实现Pod垂直(纵向)自动扩缩容
|
|
|
|
|
|
|
|
|
|
- **Vertical Pod Autoscaler(VPA):垂直 Pod 自动扩缩容**,用户无需为其 pods 中的容器设置最 新的资源 request。配置后,它将根据使用情况自动设置 request,从而允许在节点上进行适当的调度,以便为每个 pod 提供适当的资源量。
|
|
|
|
|
- VPA项目托管地址 :https://github.com/Kubernetes/autoscaler/tree/master/vertical-pod-autoscaler
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
- **注意!!! 使用vpa前删除hpa**
|
|
|
|
|
|
|
|
|
|
### 1、下载 vpa autoscaler
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[root@k8s-master vpa]# git clone https://github.com/Kubernetes/autoscaler.git
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2、Kubernetes 集群节点上拉取镜像
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
修改 updater-deployment.yaml 文件里的 image:
|
|
|
|
|
registry.k8s.io/autoscaling/vpa-admission-controller:1.0.0
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
|
|
|
|
|
修改 updater-deployment.yaml 文件里的 image:
|
|
|
|
|
registry.k8s.io/autoscaling/vpa-updater:1.0.0
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
|
|
|
|
|
修改 updater-deployment.yaml 文件里的 image:
|
|
|
|
|
registry.k8s.io/autoscaling/vpa-recommender:1.0.0
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3、部署 hpa autoscaler
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# cd autoscaler-master/vertical-pod-autoscaler/hack
|
|
|
|
|
[root@k8s-master hack]# ./vpa-up.sh
|
|
|
|
|
customresourcedefinition.apiextensions.Kubernetes.io/verticalpodautoscalercheckpoints.autoscaling.Kubernetes.io created
|
|
|
|
|
customresourcedefinition.apiextensions.Kubernetes.io/verticalpodautoscalers.autoscaling.Kubernetes.io created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:metrics-reader created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-actor created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-status-actor created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-checkpoint-actor created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:evictioner created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:metrics-reader created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-actor created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-status-actor created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-checkpoint-actor created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-target-reader created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-target-reader-binding created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-evictioner-binding created
|
|
|
|
|
serviceaccount/vpa-admission-controller created
|
|
|
|
|
serviceaccount/vpa-recommender created
|
|
|
|
|
serviceaccount/vpa-updater created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-admission-controller created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-admission-controller created
|
|
|
|
|
clusterrole.rbac.authorization.Kubernetes.io/system:vpa-status-reader created
|
|
|
|
|
clusterrolebinding.rbac.authorization.Kubernetes.io/system:vpa-status-reader-binding created
|
|
|
|
|
deployment.apps/vpa-updater created
|
|
|
|
|
deployment.apps/vpa-recommender created
|
|
|
|
|
Generating certs for the VPA Admission Controller in /tmp/vpa-certs.
|
|
|
|
|
Certificate request self-signature ok
|
|
|
|
|
subject=CN = vpa-webhook.kube-system.svc
|
|
|
|
|
Uploading certs to the cluster.
|
|
|
|
|
secret/vpa-tls-certs created
|
|
|
|
|
Deleting /tmp/vpa-certs.
|
|
|
|
|
deployment.apps/vpa-admission-controller created
|
|
|
|
|
service/vpa-webhook created
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 4、故障处理
|
|
|
|
|
|
|
|
|
|
#### 1. 执行 vpa-up.sh 脚本时报错
|
|
|
|
|
|
|
|
|
|
##### 1、报错信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
ERROR: Failed to create CA certificate for self-signing. If the error is "unknown option -addext", update your openssl version or deploy VPA from the vpa-release-0.8 branch.
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### 2、解决方案
|
|
|
|
|
|
|
|
|
|
1. 如果您没有通过集群中的云服务器执行命令,建议您在云服务器中下载 Autoscaler 项目,并执行完整的 部署 VPA 操作。如需为您的云服务器连接集群,详情可参见 连接集群。
|
|
|
|
|
|
|
|
|
|
2. 如出现继续报错的情况,请检查是否存在以下问题:
|
|
|
|
|
|
|
|
|
|
- 检查集群 CVM 的 `openssl` 版本是否大于 1.1.1。
|
|
|
|
|
|
|
|
|
|
- 是否使用 Autoscaler 项目的 `vpa-release-0.8` 分支。
|
|
|
|
|
|
|
|
|
|
#### 2. VPA 相关负载无法启动
|
|
|
|
|
|
|
|
|
|
##### 1、报错信息
|
|
|
|
|
|
|
|
|
|
如果您的 VPA 相关负载无法启动,并产生如下图所示信息:
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
**信息1**:表示负载中的 Pod 没有成功运行。
|
|
|
|
|
|
|
|
|
|
**信息2**:表示镜像的地址。
|
|
|
|
|
|
|
|
|
|
##### 2、解决方案
|
|
|
|
|
|
|
|
|
|
VPA 相关负载无法启动的原因是位于 GCR 的镜像无法被下载,为解决问题您可尝试以下步骤:
|
|
|
|
|
|
|
|
|
|
1. **下载镜像**。
|
|
|
|
|
|
|
|
|
|
访问 “k8s.gcr.io/” 镜像仓库,下载 vpa-admission-controller、vpa-recommender、vpa-updater 的镜像。
|
|
|
|
|
|
|
|
|
|
2. **更换标签及推送**。
|
|
|
|
|
|
|
|
|
|
将 vpa-admission-controller、vpa-recommender、vpa-updater 的镜像更换标签后推送到您的镜像仓库中。上传镜像操作详情可参见 容器镜像服务个人版快速入门。
|
|
|
|
|
|
|
|
|
|
3. **更改 YAML 镜像地址**。
|
|
|
|
|
|
|
|
|
|
在 YAML 文件中将 vpa-admission-controller、vpa-recommender、vpa-updater 的镜像地址更新为您设定的新地址。
|
|
|
|
|
|
|
|
|
|
### 5、验证安装
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master hack]# kubectl get pods -n kube-system | grep vpa
|
|
|
|
|
vpa-admission-controller-777694497b-bqpb2 1/1 Running 0 7m9s
|
|
|
|
|
vpa-recommender-64f6765bd9-twxbw 1/1 Running 0 7m9s
|
|
|
|
|
vpa-updater-c5474f4c7-h78xt 1/1 Running 0 7m9s
|
|
|
|
|
|
|
|
|
|
[root@k8s-master hack]# kubectl get svc -n kube-system
|
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
|
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 18d
|
|
|
|
|
metrics-server ClusterIP 10.109.69.92 <none> 443/TCP 18h
|
|
|
|
|
vpa-webhook ClusterIP 10.99.181.202 <none> 443/TCP 12m
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 6、测试VPA实现Pod自动扩缩容
|
|
|
|
|
|
|
|
|
|
使用VPA,您需要为要自动计算资源需求的每个控制器插入一个Vertical Pod Autoscaler资源。这将是最常见的Deployment。VPA有四种运行模式
|
|
|
|
|
|
|
|
|
|
- "Auto":VPA 在创建 pod 时分配资源请求,并使用首选更新机制在现有 pod 上更新它们。目前这相当于"Recreate"(见下文)。一旦 pod 请求的免重启(“就地”)更新可用,它可能会被该"Auto"模式用作首选的更新机制。注意:VPA 的此功能是实验性的,可能会导致您的应用程序停机,当目前运行的pod的资源达不到VPA的推荐值,就会执行pod驱逐,重新部署新的足够资源的服务
|
|
|
|
|
- "Recreate":VPA 在创建 Pod 时分配资源请求,并在现有 Pod 上更新它们,当请求的资源与新建议有很大差异时(尊重 Pod 中断预算,如果定义)。这种模式应该很少使用,只有当您需要确保在资源请求发生变化时重新启动 Pod 时。否则,更喜欢这种"Auto"模式,一旦它们可用,就可以利用重新启动免费更新。注意:VPA 的此功能是实验性的,可能会导致您的应用程序停机
|
|
|
|
|
- "Initial":VPA 仅在创建 pod 时分配资源请求,以后不会更改它们
|
|
|
|
|
- "Off":VPA 不会自动更改 Pod 的资源需求。这些建议是经过计算的,并且可以在 VPA 对象中进行检查。这种模式仅获取资源推荐值,但是不更新Pod
|
|
|
|
|
|
|
|
|
|
### 7、获取pod 规格建议值 updateMode:"Off"
|
|
|
|
|
|
|
|
|
|
> **说明**
|
|
|
|
|
>
|
|
|
|
|
> 不建议在生产环境中使用 VPA 自动更新 Request。
|
|
|
|
|
>
|
|
|
|
|
> 您可以利用 VPA 查看 Request 推荐值,在合适条件下手动触发更新。
|
|
|
|
|
|
|
|
|
|
#### 1、部署一个 nginx 服务
|
|
|
|
|
|
|
|
|
|
- 部署到 namespace: vpa 名称空间下
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# kubectl create ns vpa
|
|
|
|
|
namespace/vpa created
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# cat <<EOF>>nginx-vpa-dep.yaml
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: nginx
|
|
|
|
|
name: nginx-vpa-dep
|
|
|
|
|
namespace: vpa
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 2
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app: nginx
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: nginx
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- image: nginx
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
name: nginx
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
cpu: 20m
|
|
|
|
|
memory: 30Mi
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl apply -f nginx-vpa-dep.yaml
|
|
|
|
|
deployment.apps/nginx-vpa-dep created
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2、创建nginx的Service
|
|
|
|
|
|
|
|
|
|
- 在 nginx 管理的 pod 前端创建四层代理 Service
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# cat <<EOF>> nginx-vpa-svc.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-vpa-svc
|
|
|
|
|
namespace: vpa
|
|
|
|
|
spec:
|
|
|
|
|
type: NodePort
|
|
|
|
|
ports:
|
|
|
|
|
- port: 80
|
|
|
|
|
targetPort: 80
|
|
|
|
|
selector:
|
|
|
|
|
app: nginx
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl apply -f nginx-vpa-svc.yaml
|
|
|
|
|
service/nginx created
|
|
|
|
|
[root@k8s-master vpa]# kubectl get svc -n vpa
|
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
|
nginx-vpa-svc NodePort 10.97.228.179 <none> 80:30127/TCP 9s
|
|
|
|
|
[root@k8s-master vpa]# curl -I 192.168.10.10:30127
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3、创建VPA
|
|
|
|
|
|
|
|
|
|
- 先使用 updateMode: "Off"模式,这种模式仅获取资源推荐值,但是不更新 Pod
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# cat <<EOF>>nginx-vpa.yaml
|
|
|
|
|
apiVersion: autoscaling.Kubernetes.io/v1beta2
|
|
|
|
|
kind: VerticalPodAutoscaler
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-vpa
|
|
|
|
|
namespace: vpa
|
|
|
|
|
spec:
|
|
|
|
|
targetRef:
|
|
|
|
|
apiVersion: "apps/v1"
|
|
|
|
|
kind: Deployment
|
|
|
|
|
name: nginx-vpa-dep
|
|
|
|
|
updatePolicy:
|
|
|
|
|
updateMode: "Off"
|
|
|
|
|
resourcePolicy:
|
|
|
|
|
containerPolicies:
|
|
|
|
|
- containerName: "nginx"
|
|
|
|
|
minAllowed:
|
|
|
|
|
cpu: "50m"
|
|
|
|
|
memory: "60Mi"
|
|
|
|
|
maxAllowed:
|
|
|
|
|
cpu: "1000m"
|
|
|
|
|
memory: "500Mi"
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl apply -f vpa-nginx.yaml
|
|
|
|
|
verticalpodautoscaler.autoscaling.Kubernetes.io/nginx-vpa created
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl get vpa -n vpa
|
|
|
|
|
NAME AGE
|
|
|
|
|
nginx-vpa 31s
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 4、查看详细信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# kubectl describe vpa nginx-vpa -n vpa
|
|
|
|
|
# 使用上面命令这次没看到
|
|
|
|
|
Recommendation:
|
|
|
|
|
Container Recommendations:
|
|
|
|
|
Container Name: nginx
|
|
|
|
|
Lower Bound:
|
|
|
|
|
Cpu: 50m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Target:
|
|
|
|
|
Cpu: 50m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Uncapped Target:
|
|
|
|
|
Cpu: 25m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Upper Bound:
|
|
|
|
|
Cpu: 1349m
|
|
|
|
|
Memory: 1410936619
|
|
|
|
|
Events: <none>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 上面结果表示,推荐的 Pod 的 CPU 请求为 50m,推荐的内存请求为 262144k 字节。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 字段 | 释义 |
|
|
|
|
|
| ------------------ | ------------------------------------------------------------ |
|
|
|
|
|
| **lowerBound** | 推荐的最小值。使用小于该值的 Request 可能会对性能或可用性产生重大影响。 |
|
|
|
|
|
| **target** | 推荐值。由 VPA 计算出最合适的 Request。 |
|
|
|
|
|
| **uncappedTarget** | 最新建议值。仅基于实际资源使用情况,不考虑 `.spec.resourcePolicy.containerPolicies` 中设置的容器可以被推荐的数值范围。uncappedTarget 可能与推荐上下界限不同。该字段仅用作状态指示,不会影响实际的资源分配。 |
|
|
|
|
|
| **upperBound** | 推荐的最大值。使用高于该值的 Request 可能造成浪费。 |
|
|
|
|
|
|
|
|
|
|
#### 5、压测nginx
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# yum install -y httpd-tools ab
|
|
|
|
|
|
|
|
|
|
[root@k8s-master manifests]# kubectl get svc -n vpa
|
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
|
nginx NodePort 10.97.228.179 <none> 80:30127/TCP 55m
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# ab -c 100 -n 10000000 http://192.168.10.10:30127/
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl describe vpa nginx-vpa -n vpa
|
|
|
|
|
|
|
|
|
|
# VPA 对 Pod 给出了推荐值:Cpu: 763m,因为我们这里设置了
|
|
|
|
|
# updateMode: "Off",所以不会更新 Pod
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 8、自动更新pod规格到建议值 updateMode: "Auto"
|
|
|
|
|
|
|
|
|
|
#### 1、修改resources 为:memory: 30Mi,cpu: 50m
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# vim nginx-vpa-dep.yaml
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: Deployment
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: nginx
|
|
|
|
|
name: nginx-vpa-dep
|
|
|
|
|
namespace: vpa
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 2
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app: nginx
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: nginx
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- image: nginx
|
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
|
name: nginx
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
cpu: 50m
|
|
|
|
|
memory: 30Mi
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl apply -f nginx-vpa-dep.yaml
|
|
|
|
|
deployment.apps/nginx created
|
|
|
|
|
[root@k8s-master vpa]# kubectl get pods -n vpa
|
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
|
nginx-7d946f55c4-p52gj 1/1 Running 0 10s
|
|
|
|
|
nginx-7d946f55c4-s8ggc 1/1 Running 0 10s
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2、现在将 updateMode: "Auto"
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 再次部署vpa,这里VPA部署文件只改了updateMode: "Auto"和name: nginx-vpa-2
|
|
|
|
|
[root@k8s-master vpa]# vim nginx-nginx.yaml
|
|
|
|
|
apiVersion: autoscaling.k8s.io/v1
|
|
|
|
|
kind: VerticalPodAutoscaler
|
|
|
|
|
metadata:
|
|
|
|
|
name: nginx-vpa
|
|
|
|
|
namespace: vpa
|
|
|
|
|
spec:
|
|
|
|
|
targetRef:
|
|
|
|
|
apiVersion: "apps/v1"
|
|
|
|
|
kind: Deployment
|
|
|
|
|
name: nginx-vpa-dep
|
|
|
|
|
updatePolicy:
|
|
|
|
|
updateMode: "Auto"
|
|
|
|
|
resourcePolicy:
|
|
|
|
|
containerPolicies:
|
|
|
|
|
- containerName: "nginx"
|
|
|
|
|
minAllowed:
|
|
|
|
|
cpu: "500m"
|
|
|
|
|
memory: "100Mi"
|
|
|
|
|
maxAllowed:
|
|
|
|
|
cpu: "2000m"
|
|
|
|
|
memory: "2600Mi"
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl apply -f nginx-vpa.yaml
|
|
|
|
|
verticalpodautoscaler.autoscaling.Kubernetes.io/nginx-vpa-2 created
|
|
|
|
|
[root@k8s-master vpa]# kubectl get vpa -n vpa
|
|
|
|
|
NAME AGE
|
|
|
|
|
nginx-vpa 9s
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl describe pods nginx-7d946f55c4-p52gj -n vpa
|
|
|
|
|
# 查看Requests的cpu和memory是多少和部署的文件中作比较
|
|
|
|
|
|
|
|
|
|
# 再次压测
|
|
|
|
|
[root@k8s-master vpa]# ab -c 100 -n 1000000 http://192.168.10.10:30127/
|
|
|
|
|
# 几分钟后,使用 describe 查看 vpa 详情,只关注 Container Recommendations
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl describe vpa nginx-vpa -n vpa |tail -n 20
|
|
|
|
|
Status:
|
|
|
|
|
Conditions:
|
|
|
|
|
Last Transition Time: 2021-06-28T04:48:25Z
|
|
|
|
|
Status: True
|
|
|
|
|
Type: RecommendationProvided
|
|
|
|
|
Recommendation:
|
|
|
|
|
Container Recommendations:
|
|
|
|
|
Container Name: nginx
|
|
|
|
|
Lower Bound:
|
|
|
|
|
Cpu: 250m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Target:
|
|
|
|
|
Cpu: 476m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Uncapped Target:
|
|
|
|
|
Cpu: 476m
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Upper Bound:
|
|
|
|
|
Cpu: 2
|
|
|
|
|
Memory: 262144k
|
|
|
|
|
Events: <none>
|
|
|
|
|
|
|
|
|
|
# Target 变成了 Cpu: 476m ,Memory: 262144k
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3、 查看event事件
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master vpa]# kubectl get event -n vpa
|
|
|
|
|
# vpa 执行了 EvictedByVPA,自动停掉了 nginx,然后使用 VPA 推荐的
|
|
|
|
|
# 资源启动了新的 nginx
|
|
|
|
|
|
|
|
|
|
[root@k8s-master vpa]# kubectl describe pods nginx-7d946f55c4-p52gj -n vpa
|
|
|
|
|
# 查看Requests的cpu和memory是多少和部署的文件中作比较
|
|
|
|
|
|
|
|
|
|
# 随着服务的负载的变化,VPA 的推荐值也会不断变化。当目前运行的 pod 的资源达不到 VPA 的推荐值,就会执行 pod 驱逐,重新部署新的足够资源的服务。
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 9、VPA使用限制&优势
|
|
|
|
|
|
|
|
|
|
##### 1、VPA 使用限制
|
|
|
|
|
|
|
|
|
|
- 不能与 HPA(Horizontal Pod Autoscaler )一起使用
|
|
|
|
|
- Pod 必须使用副本控制器,例如属于 Deployment 或者 StatefulSet
|
|
|
|
|
|
|
|
|
|
##### 2、VPA优点
|
|
|
|
|
|
|
|
|
|
- Pod 资源用其所需,所以集群节点使用效率高。
|
|
|
|
|
- Pod 会被安排到具有适当可用资源的节点上。
|
|
|
|
|
- 不必运行基准测试任务来确定 CPU 和内存请求的合适值。
|
|
|
|
|
- VPA 可以随时调整 CPU 和内存请求,无需人为操作,因此可以减少维护时间。
|
|
|
|
|
- VPA 是 Kubernetes 比较新的功能,还没有在生产环境大规模实践过,小环境可以使用试试,也可以提前测试看看
|
|
|
|
|
|
|
|
|
|
## 四、Openssl 升级
|
|
|
|
|
|
|
|
|
|
### 1、Linux 系统版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# cat /etc/redhat-release
|
|
|
|
|
CentOS Linux release 7.3.1611 (Core)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2、查看Openssl安装的版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# openssl version
|
|
|
|
|
OpenSSL 1.0.2k-fips 26 Jan 2017
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3、查看Openssl路径
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# which openssl
|
|
|
|
|
/usr/bin/openssl
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 4、下载 Openssl
|
|
|
|
|
|
|
|
|
|
目前最新版本是1.1.1,可以通过修改版本号的方式下载最新版本,最新版本可以在这个网站下载:https://www.openssl.org/source
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# wget http://www.openssl.org/source/openssl-1.1.1b.tar.gz
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 5、安装依赖
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# yum install -y zlib zlib-devel
|
|
|
|
|
[root@k8s-master ~]# yum install –y gcc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 6、安装Perl
|
|
|
|
|
|
|
|
|
|
#### 1、下载Perl
|
|
|
|
|
|
|
|
|
|
官方网站下载新版本的源码包:[http://www.perl.org/get.html](https://cloud.tencent.com/developer/tools/blog-entry?target=https%3A%2F%2Flink.zhihu.com%2F%3Ftarget%3Dhttp%3A%2F%2Fwww.perl.org%2Fget.html&source=article&objectId=2060895)
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# wget https://www.cpan.org/src/5.0/perl-5.28.2.tar.gz
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2、解压Perl
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# tar -zxvf perl-5.28.2.tar.gz
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3、建立文件目录,以供安装时使用
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# mkdir /usr/local/perl
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 4、配置Perl参数
|
|
|
|
|
|
|
|
|
|
进入perl-5.28.2.tar.gz的解压目录,执行:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# cd perl-5.28.2
|
|
|
|
|
[root@k8s-master perl-5.28.2]# ./Configure -des -Dprefix=/usr/local/perl -Dusethreads –Uversiononly
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 5、编译
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master perl-5.28.2]# make
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 6、安装
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master perl-5.28.2]# make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 7、查看版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master perl-5.28.2]# perl –v
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 7、安装Openssl
|
|
|
|
|
|
|
|
|
|
#### 1、解压Openssl
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master perl-5.28.2]# cd
|
|
|
|
|
[root@k8s-master ~]# tar -zxvf openssl-1.1.1b.tar.gz
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2、调用zlib共享库
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master ~]# cd openssl-1.1.1b
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ./config shared zlib
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
#### 3、编译
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# make
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 4、安装
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 5、备份当前Openssl
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# mv /usr/bin/openssl /usr/bin/openssl.old
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# mv /usr/lib64/openssl /usr/lib64/openssl.old
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 6、使用新版Openssl
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ln -s /usr/local/bin/openssl /usr/bin/openssl
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ln -s /usr/local/include/openssl/ /usr/include/openssl
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 8、更新动态链接库数据
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# echo “/usr/local/lib/” >> /etc/ld.so.conf
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 9、重新加载动态链接库
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ldconfig -v
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 10、查看安装完成后的最新版本
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# openssl version
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# openssl version –a
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 11、可能存在的异常
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 这是由于openssl库的位置不正确造成的。
|
|
|
|
|
|
|
|
|
|
- 解决方法:
|
|
|
|
|
|
|
|
|
|
- 在root用户下执行:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
|
|
|
|
|
[root@k8s-master openssl-1.1.1b]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**如上升级openssl版本后, 导致某些服务编译安装失败的坑, 如果短时间解决不来, 最好回滚到之前的默认版本:**
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
openssl由默认的OpenSSL 1.0.1e升级到OpenSSL 1.1.1e后, 编译安装openssh 出现下面报错:
|
|
|
|
|
|
|
|
|
|
由于openssl升级后, 可能会导致一个应用编译安装失败, 遇到的有nginx, keepalived等, 不得已的办法就是将openssl回滚到之前默认的版本状态, 操作方法如下:
|
|
|
|
|
查看openssl, 然后删除升级后的openssl
|
|
|
|
|
[root@k8s-master ~]# find / -name openssl
|
|
|
|
|
[root@k8s-master ~]# rm -rf /usr/local/src/openssl-1.1.1
|
|
|
|
|
[root@k8s-master ~]# rm -rf /usr/local/bin/openssl
|
|
|
|
|
[root@k8s-master ~]# rm -rf /usr/local/share/doc/openssl
|
|
|
|
|
[root@k8s-master ~]# rm -rf /usr/local/include/openssl
|
|
|
|
|
|
|
|
|
|
然后查看下openssl版本
|
|
|
|
|
[root@k8s-master ~]# which openssl
|
|
|
|
|
/usr/bin/openssl
|
|
|
|
|
[root@k8s-master ~]# openssl version -a
|
|
|
|
|
报错说/usr/local/bin/openssl 找不到这个文件
|
|
|
|
|
|
|
|
|
|
然后重启机器
|
|
|
|
|
[root@k8s-master ~]# init 6
|
|
|
|
|
|
|
|
|
|
重启机器后, 查看openssl版本, 如果正常查出是默认版本, 则回滚正常
|
|
|
|
|
[root@k8s-master ~]# openssl version -a
|
|
|
|
|
```
|