# Deploy a Knative application

See the Knative Service (opens new window) documentation to get an overview about deploying your applications with Knative.

# Deploy via kn CLI

The easiest way to deploy a Knative application (called service in Knative) is to directly deploy it with the kn CLI:

$ kn --namespace demo \
  service create hello-world \
  --image gcr.io/knative-samples/helloworld-go \
  --port 8080 \
  --env TARGET=World

# Deploy via YAML

Instead of using kn you can of course also just as well use YAML files and deploy them with kubectl:

# knative-hello-world.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-world
  namespace: demo
spec:
  template:
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        ports:
        - containerPort: 8080
        env:
        - name: TARGET
          value: "World"
$ kubectl -n demo apply -f knative-hello-world.yaml

The result would be the same as with kn.

# List applications

$ kn -n demo service list

NAME          URL                                                  LATEST              AGE   CONDITIONS   READY   REASON
hello-world   https://hello-world.demo.kube-plus.cloud   hello-world-00001   44m   3 OK / 3     True

# Inspect an application

$ kn -n demo service describe hello-world

Name:       hello-world
Namespace:  demo
Age:        2h
URL:        https://hello-world.demo.kube-plus.cloud

Revisions:
  100%  @latest (hello-world-00001) [1] (2h)
        Image:     gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)
        Replicas:  0/0

Conditions:
  OK TYPE                   AGE REASON
  ++ Ready                   2h
  ++ ConfigurationsReady     2h
  ++ RoutesReady             2h

# Update an application

$ kn -n demo service hello-world \
  --scale-min 5 --scale-max 10 \
  --request cpu=500m \
  --limit memory=1024Mi --limit cpu=1000m

Be sure to check out the full documentation (opens new window) on kn service update.

# Autoscaling

Check out this documentation on how Knative Autoscaling (opens new window) for applications works.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-autoscaling-app
  namespace: demo
spec:
  template:
    metadata:
      annotations:
        # Initial target scale immediately after app is created
        autoscaling.knative.dev/initialScale: "3"
        # Disable scale to zero with a minScale of 1+
        autoscaling.knative.dev/minScale: "2"
        # Limit scaling maximum to 10 pods
        autoscaling.knative.dev/maxScale: "10"
        # Time window which must pass before a scale-down decision is applied
        autoscaling.knative.dev/scaleDownDelay: "5m"
        # Target 10 requests in-flight per pod
        autoscaling.knative.dev/target: "10"
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        env:
        - name: TARGET
          value: "World!"
Last Updated: 9/12/2022, 7:31:38 PM