【发布时间】:2019-08-29 21:19:50
【问题描述】:
编辑:
解决方案:我忘记将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 中出现这个
【问题讨论】:
标签: kubernetes terraform autoscaling