gpt4 book ai didi

kubernetes - 如何水平自动缩放Kubernetes部署

转载 作者:行者123 更新时间:2023-12-02 11:37:12 25 4
gpt4 key购买 nike

编辑:

解决方案:我忘记将target_cpu_utilization_percentage添加到autoscaler.tf文件中

我想在Kubernetes上运行Python(或其他语言)的网络服务,但要具有自动缩放功能。

我创建了一个Deployment和一个Horizontal Autoscaler,但无法正常工作。

我正在使用Terraform配置Kubernetes。

我有这个文件:

Deployments.tf

resource "kubernetes_deployment" "rui-test" {
metadata {
name = "rui-test"
labels {
app = "rui-test"
}
}
spec {
strategy = {
type = "RollingUpdate"
rolling_update = {
max_unavailable = "26%" # This is not working
}
}
selector = {
match_labels = {
app = "rui-test"
}
}
template = {
metadata = {
labels = {
app = "rui-test"
}
}
spec = {
container {
name = "python-test1"
image = "***************************"
}
}
}
}
}

Autoscaler.tf
resource "kubernetes_horizontal_pod_autoscaler" "test-rui" {    
metadata {
name = "test-rui"
}
spec {
max_replicas = 10 # THIS IS NOT WORKING
min_replicas = 3 # THIS IS NOT WORKING

scale_target_ref {
kind = "Deployment"
name = "test-rui" # Name of deployment
}
}
}

Service.tf
resource "kubernetes_service" "rui-test" {
metadata {
name = "rui-test"
labels {
app = "rui-test"
}
}
spec {
selector {
app = "rui-test"
}
type = "LoadBalancer" # Use 'cluster_ip = "None"' or 'type = "LoadBalancer"'
port {
name = "http"
port = 8080
}
}
}

当我运行 kubectl get hpa时,我看到以下内容:
NAME       REFERENCE             TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
rui-test Deployment/rui-test <unknown>/80% 1 3 1 1h

代替:
rui-test   Deployment/rui-test   <unknown>/79%   3         10        1          1h

那就是我想要的。

但是,如果我运行 kubectl autoscale deployment rui-test --min=3 --max=10 --cpu-percent=81,则会看到以下内容:
Error from server (AlreadyExists): horizontalpodautoscalers.autoscaling "rui-test" already exists

在kubernetes中出现

enter image description here

最佳答案

您缺少metrics server。 Kubernetes需要确定当前的CPU /内存使用情况,以便可以自动向上和向下扩展。

知道是否已安装指标服务器的一种方法是运行:

$ kubectl top node
$ kubectl top pod

关于kubernetes - 如何水平自动缩放Kubernetes部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55578271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com