0

我在 GKE 上的 k8s 集群上安装了 k-native。现在我正在使用示例 HelloWorld 应用程序运行测试。

由于我在 GKE 上运行并 24/7 为集群付费,因此将部署扩展到零并始终对第一个请求进行冷启动是没有意义的。

到目前为止我尝试过的列表

  1. Ran kubectl -n knative-serving edit cm config-autoscaler,然后将enable-scale-to-zero标志从“true”更改为“false”,正如此链接所暗示的那样
  2. 按照此链接kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/minScale="1"中的说明运行
  3. 作为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
4

2 回答 2

2

必须将注释添加到PodAutoscaler对象中。

kubectl annotate --overwrite PodAutoscaler helloworld-go-5jm9r autoscaling.knative.dev/minScale="2"

或者您可以按照链接中的说明在 yaml 配置文件中设置 minScale

apiVersion: 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"
于 2019-06-16T23:19:15.517 回答
0

我认为必须将注释添加Revision对象中,但是您正在注释Service对象,这就是它不起作用的原因。

尝试列出所有Revision对象

kubectl get revision

并使用与注释Service.

于 2019-06-13T08:30:46.527 回答