【发布时间】:2023-04-02 08:25:01
【问题描述】:
我已成功按照文档 here 和 here 将 API 规范和 GKE 后端部署到 Cloud Endpoints。
这给我留下了一个如下所示的 deployment.yaml:
apiVersion: v1
kind: Service
metadata:
name: esp-myproject
spec:
ports:
- port: 80
targetPort: 8081
protocol: TCP
name: http
selector:
app: esp-myproject
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: esp-myproject
spec:
replicas: 1
template:
metadata:
labels:
app: esp-myproject
spec:
containers:
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:1
args: [
"--http_port=8081",
"--backend=127.0.0.1:8080",
"--service=myproject1-0-0.endpoints.myproject.cloud.goog",
"--rollout_strategy=managed",
]
ports:
- containerPort: 8081
- name: myproject
image: gcr.io/myproject/my-image:v0.0.1
ports:
- containerPort: 8080
这会在后端创建应用的单个副本。到目前为止,一切都很好......
我现在想更新 yaml 文件以以声明方式指定自动缩放参数,以便在到端点的流量证明不止一个时,使应用的多个副本能够彼此并排运行。
我已经阅读过(O'Reilly 的书:Kubernetes Up & Running、GCP 文档、K8s 文档),但有两件事让我很困惑:
- 我已多次阅读有关 HorizontalPodAutoscaler 的信息,但我不清楚部署是否必须使用它才能享受自动缩放的好处?
- 如果是这样,我在文档中看到了如何在 yaml 中定义 HorizontalPodAutoscaler 规范的示例,如下所示 - 但我如何将其与现有的 deployment.yaml 结合起来?
HorizontalPodAutoscaler 示例 (from the docs):
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
提前感谢任何可以为我阐明这一点的人。
【问题讨论】:
标签: kubernetes google-cloud-platform google-cloud-endpoints autoscaling