如何将 GKE 上的 k-native 的最小比例设置为 1?

How to set a minimum scale to 1 for k-native on GKE?

我在 GKE 上的 k8s 集群上安装了 k-native。现在我正在 运行 测试 a sample HelloWorld app

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

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

  1. 运行 kubectl -n knative-serving edit cm config-autoscaler 然后将 enable-scale-to-zero 标志从 'true' 更改为 'false',因为 this link 暗示
  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 pods 为服务启动的服务都终止了,因为没有更多的电话进来。

$ 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

I think the annotation has to be addedRevision 对象,但您正在注释 Service 对象,这就是它不起作用的原因。

尝试列出所有 Revision 对象

kubectl get revision

并使用与注释 Service.

相同的命令注释您感兴趣的命令

注释必须添加到 PodAutoscaler 对象。

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

或者您可以按照 the link

中所述在您的 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"