以声明方式自动缩放 google Cloud-Endpoints 后端部署(在 yaml 中)?
Autoscaling a google Cloud-Endpoints backend deployment declaratively (in the yaml)?
我已成功按照文档 here and 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 & 运行、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
在此先感谢任何能为我阐明这一点的人。
- I've read a number of times about the HorizontalPodAutoscaler and it's not clear to me whether the deployment must make use of this in order to enjoy the benefits of autoscaling?
不是必须的,但建议这样做,而且它已经内置。您可以构建自己的可扩展和缩小的自动化,但问题是为什么,因为 HPA 已经支持它。
- If so, I have seen examples in the docs of how to define the spec for the HorizontalPodAutoscaler in yaml as shown below - but how would I combine this with my existing deployment.yaml?
应该很简单。您基本上在 HPA 定义中引用了您的部署:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: my-esp-project-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: esp-myproject <== here
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
我遇到了同样的问题,对我有用的是
如果您使用的是 GKE 并面临启用 API 的问题
autoscaling/v1
autoscaling/v2beta1
当 GKE 版本在 1.12 to 1.14
左右时,您将无法应用 autoscaling/v2beta2
的清单,但是您可以应用类似
的相同内容
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: core-deployment
namespace: default
spec:
maxReplicas: 9
minReplicas: 5
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: core-deployment
metrics:
- type: Resource
resource:
name: cpu
targetAverageValue: 500m
如果你想根据利用率
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: core-deployment
namespace: default
spec:
maxReplicas: 9
minReplicas: 5
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: core-deployment
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 80
我已成功按照文档 here and 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 & 运行、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
在此先感谢任何能为我阐明这一点的人。
- I've read a number of times about the HorizontalPodAutoscaler and it's not clear to me whether the deployment must make use of this in order to enjoy the benefits of autoscaling?
不是必须的,但建议这样做,而且它已经内置。您可以构建自己的可扩展和缩小的自动化,但问题是为什么,因为 HPA 已经支持它。
- If so, I have seen examples in the docs of how to define the spec for the HorizontalPodAutoscaler in yaml as shown below - but how would I combine this with my existing deployment.yaml?
应该很简单。您基本上在 HPA 定义中引用了您的部署:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: my-esp-project-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: esp-myproject <== here
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
我遇到了同样的问题,对我有用的是
如果您使用的是 GKE 并面临启用 API 的问题
autoscaling/v1
autoscaling/v2beta1
当 GKE 版本在 1.12 to 1.14
左右时,您将无法应用 autoscaling/v2beta2
的清单,但是您可以应用类似
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: core-deployment
namespace: default
spec:
maxReplicas: 9
minReplicas: 5
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: core-deployment
metrics:
- type: Resource
resource:
name: cpu
targetAverageValue: 500m
如果你想根据利用率
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: core-deployment
namespace: default
spec:
maxReplicas: 9
minReplicas: 5
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: core-deployment
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 80