akn*_*ds1 10 autoscaling kubernetes
我创建了一个Kubernetes自动缩放器,但我需要更改其参数.我该如何更新?
我尝试了以下,但它失败了:
? kubectl autoscale -f docker/production/web-controller.yaml --min=2 --max=6
Error from server: horizontalpodautoscalers.extensions "web" already exists
Run Code Online (Sandbox Code Playgroud)
小智 23
您始终可以以交互方式编辑群集中的资源.对于您调用的自动缩放控制器web,您可以通过以下方式进行编辑:
kubectl edit hpa web
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找更加程序化的方式来更新水平pod自动缩放器,那么您也可以更好地在yaml文件中描述自动缩放器实体.例如,这是一个简单的复制控制器,与Horizontal Pod Autoscale实体配对:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 2
template:
metadata:
labels:
run: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx
namespace: default
spec:
maxReplicas: 3
minReplicas: 2
scaleTargetRef:
apiVersion: v1
kind: ReplicationController
name: nginx
Run Code Online (Sandbox Code Playgroud)
将这些内容放在调用的文件中nginx.yaml,可以通过更新自动缩放器来完成kubectl apply -f nginx.yaml.
首先删除自动缩放器,然后重新创建它:
? kubectl delete hpa web
? kubectl autoscale -f docker/production/web-controller.yaml --min=2 --max=6
Run Code Online (Sandbox Code Playgroud)
小智 7
您也可以使用kubectl patch命令查看其当前状态
kubectl get hpa <autoscaler-name-here> -o json
示例输出:
{
"apiVersion": "autoscaling/v1",
"kind": "HorizontalPodAutoscaler",
"metadata": {
...
"name": "your-auto-scaler",
"namespace": "your-namespace",
...
},
"spec": {
"maxReplicas": 50,
"minReplicas": 2,
"scaleTargetRef": {
"apiVersion": "extensions/v1beta1",
"kind": "Deployment",
"name": "your-deployment"
},
"targetCPUUtilizationPercentage": 40
},
"status": {
"currentReplicas": 1,
"desiredReplicas": 2,
"lastScaleTime": "2017-12-13T16:23:41Z"
}
}
Run Code Online (Sandbox Code Playgroud)
如果要更新最小副本数:
kubectl -n your-namespace patch hpa your-auto-scaler --patch '{"spec":{"minReplicas":1}}'
Run Code Online (Sandbox Code Playgroud)
相同的逻辑适用于自动缩放器配置中的其他参数,如果要更新允许的最大副本数,请将minReplicas更改为maxReplicas.
| 归档时间: |
|
| 查看次数: |
8681 次 |
| 最近记录: |