我在GKE的k8s集群上安装了k-native。现在,我正在使用a sample HelloWorld app进行测试。
由于我在GKE上运行并为24/7集群付费,因此将部署规模扩展到零并始终对第一个请求始终保持冷启动是没有意义的。
到目前为止我已经尝试过的列表
kubectl -n knative-serving edit cm config-autoscaler
,然后根据this link的含义,将enable-scale-to-zero
标志从“ true”更改为“ false” kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/minScale="1"
kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/class-
作为我自己的实验之一无论我进行了什么修改,启动投放服务的HelloWorld吊舱都终止了,因为没有更多的电话打进来。
$ kubectl get po --watch
NAME READY STATUS RESTARTS AGE
helloworld-go-5jm9r-deployment-847d6fdb49-njktv 2/2 Running 0 13s
helloworld-go-5jm9r-deployment-847d6fdb49-njktv 2/2 Terminating 0 96s
helloworld-go-5jm9r-deployment-847d6fdb49-njktv 1/2 Terminating 0 99s
helloworld-go-5jm9r-deployment-847d6fdb49-njktv 0/2 Terminating 0 118s
将minScale因子正确设置为1应该可以使Pod永远活着,对吗?
人们说setting-a-custom-minScale选项在这里和那里都可用,但是我无法打开它。我想念什么?例如,欢迎运行具体命令。
第二次尝试:
$ kubectl annotate --overwrite revision helloworld-go-5jm9r autoscaling.knative.dev/minScale="1"
revision.serving.knative.dev/helloworld-go-5jm9r annotated
$ kubectl describe revision
Name: helloworld-go-5jm9r
Namespace: default
Labels: serving.knative.dev/configuration=helloworld-go
serving.knative.dev/configurationGeneration=1
serving.knative.dev/service=helloworld-go
Annotations: autoscaling.knative.dev/minScale: 1
serving.knative.dev/lastPinned: 1560488757
(..omit..)
$ kubectl get po --watch
NAME READY STATUS RESTARTS AGE
helloworld-go-5jm9r-deployment-65dd4cc9d4-4hhrw 2/2 Running 0 19s
helloworld-go-5jm9r-deployment-65dd4cc9d4-4hhrw 2/2 Terminating 0 98s
helloworld-go-5jm9r-deployment-65dd4cc9d4-4hhrw 1/2 Terminating 0 101s
helloworld-go-5jm9r-deployment-65dd4cc9d4-4hhrw 0/2 Terminating 0 2m
注释修订并不能使启动的pod保持活动状态...知道吗?
答案:
它是PodAutoscaler
,不是服务或修订版本。
$ kubectl annotate --overwrite PodAutoscaler helloworld-go-5jm9r autoscaling.knative.dev/minScale="2"
podautoscaler.autoscaling.internal.knative.dev/helloworld-go-5jm9r annotated
$ kubectl describe PodAutoscaler
Name: helloworld-go-5jm9r
Namespace: default
Labels: app=helloworld-go-5jm9r
serving.knative.dev/configuration=helloworld-go
serving.knative.dev/configurationGeneration=1
serving.knative.dev/revision=helloworld-go-5jm9r
serving.knative.dev/revisionUID=706b4f42-8be6-11e9-a475-42010a920158
serving.knative.dev/service=helloworld-go
Annotations: autoscaling.knative.dev/class: kpa.autoscaling.knative.dev
autoscaling.knative.dev/metric: concurrency
autoscaling.knative.dev/minScale: 2
(..omit..)
$ kubectl get po --watch
NAME READY STATUS RESTARTS AGE
helloworld-go-5jm9r-deployment-65dd4cc9d4-6rtr9 0/2 ContainerCreating 0 2s
helloworld-go-5jm9r-deployment-65dd4cc9d4-pqvcz 2/2 Running 0 116s
helloworld-go-5jm9r-deployment-65dd4cc9d4-6rtr9 1/2 Running 0 4s
helloworld-go-5jm9r-deployment-65dd4cc9d4-6rtr9 2/2 Running 0 4s
答案 0 :(得分:1)
注释必须添加到PodAutoscaler
对象中。
kubectl annotate --overwrite PodAutoscaler helloworld-go-5jm9r autoscaling.knative.dev/minScale="2"
或者您可以按照the link
中的说明在yaml配置文件上设置minScaleapiVersion: serving.knative.dev/v1alpha1 # Current version of Knative
kind: Service
metadata:
name: helloworld-min2 # The name of the app
namespace: default # The namespace the app will use
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go # The URL to the image of the app
env:
- name: TARGET # The environment variable printed out by the sample app
value: "Go Jin v1"
metadata:
annotations:
autoscaling.knative.dev/minScale: "2"
答案 1 :(得分:0)
I think the annotation has to be added到Revision
对象,但是您正在注释Service
对象,这就是为什么它不起作用的原因。
尝试列出所有Revision
个对象
kubectl get revision
并使用与注释Service
相同的命令来注释您感兴趣的那个。