我已成功遵循文档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示例(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
在此先感谢任何可以帮助我了解一下的人。
答案 0 :(得分:1)
- 我已经阅读了很多有关HorizontalPodAutoscaler的文章,我不清楚部署是否必须利用此工具才能享受自动缩放的好处?
不是必须的,但是它是推荐的,并且已经内置。您可以构建自己的可自动伸缩的自动化系统,但问题是为什么,因为HPA已经支持它。
- 如果是这样,我在文档中看到了一些示例,这些示例说明了如何在yaml中定义HorizontalPodAutoscaler的规范,如下所示-但是如何将其与现有的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
答案 1 :(得分:0)
我面临着同样的问题,对我有用的是
如果您使用的是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