我在 GKE 上的 k8s 集群上安装了 k-native。现在我正在使用示例 HelloWorld 应用程序运行测试。
由于我在 GKE 上运行并 24/7 为集群付费,因此将部署扩展到零并始终对第一个请求进行冷启动是没有意义的。
到目前为止我尝试过的列表
- Ran
kubectl -n knative-serving edit cm config-autoscaler
,然后将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 pod 都终止了,因为没有更多的电话进来。
$ 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