<p>I installed k-native on my k8s cluster on GKE. Now I am running a test with <a href="https://github.com/knative/docs/blob/master/docs/install/getting-started-knative-app.md" rel="nofollow noreferrer">a sample HelloWorld app</a>.</p>

<p>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.</p>

<p>The list of What I have tried so far</p>

<ol>
<li>Ran <code>kubectl -n knative-serving edit cm config-autoscaler</code> and then changed <code>enable-scale-to-zero</code> flag to 'false' from 'true' as <a href="https://knative.dev/docs/serving/configuring-the-autoscaler/" rel="nofollow noreferrer">this link</a> implies</li>
<li>Ran <code>kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/minScale="1"</code> as stated in <a href="https://stackoverflow.com/questions/55866728/how-to-set-a-minimum-scale-for-cloud-run-on-gke-services">this link</a></li>
<li>Ran <code>kubectl annotate --overwrite svc helloworld-go-5jm9r autoscaling.knative.dev/class-</code> as one of my own experiment</li>
</ol>

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

<p><code>$ 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</code></p>

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

<p>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.</p>

<hr>

<p>2nd try:</p>

<pre><code>$ 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
</code></pre>

<p>Annotating the revision didn't keep the launched pod alive... Any idea?</p>

<hr>

<p>Answer:</p>

<p>It was <code>PodAutoscaler</code>, not Service nor Revision.</p>

<pre><code>$ 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
</code></pre>

jin c
<p>The annotation had to be added to the <code>PodAutoscaler</code> object.</p>

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

<p>Or you could set the minScale on your yaml configuration file as described in <a href="https://github.com/knative/serving/tree/master/docs/scaling" rel="nofollow noreferrer">the link</a></p>

<pre><code>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"
</code></pre>
