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

6/13/2019

I installed k-native on my k8s cluster on GKE. Now I am running a test with a sample HelloWorld app.

Since I'm running on GKE and paying for the cluster 24/7 it makes no sense to scale a deployment to zero and always have a cold start for the first request.

The list of What I have tried so far

  1. Ran kubectl -n knative-serving edit cm config-autoscaler and then changed enable-scale-to-zero flag to 'false' from 'true' as this link implies
  2. Ran kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/minScale="1" as stated in this link
  3. Ran kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/class- as one of my own experiment

No matter what modifications I made HelloWorld pods that launched for serving terminated away as no more calls came in.

$ 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

Setting the minScale factor to 1 correctly should've kept the pod alive forever, am I wrong?

People say the setting-a-custom-minScale option is available here and there but I can't get it on. What am I missing? Concrete commands to run, for example, are welcomed.


2nd try:

$ 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

Annotating the revision didn't keep the launched pod alive... Any idea?


Answer:

It was PodAutoscaler, not Service nor Revision.

$ 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
-- jin c
google-kubernetes-engine
knative
knative-serving
kubernetes

2 Answers

6/13/2019

I think the annotation has to be added to the Revision object, but you are annotating the Service object, and that's why it won't work.

Try listing all your Revision objects

kubectl get revision

and annotating the one you are interested in, using the same command that you were using for annotating the Service.

-- Jose Armesto
Source: StackOverflow

6/16/2019

The annotation had to be added to the PodAutoscaler object.

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

Or you could set the minScale on your yaml configuration file as described in the link

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"
-- jin c
Source: StackOverflow