Declarative vs imperative deployments
In this guide, we show how to deploy Knative services by writing YAML manifests
kubectl apply command. These manifests can be stored in source
control, such as git repositories.
Alternatively, Knative also offers a command-line tool called
kn to create and
manage Knative resources.
kn doesn't accept manifest files to read Service configuration from,
everything is configured through command-line options, which can get lengthy.
Therefore, it's easier to use
kn for first-time deployments or while playing
with Knative. However, it's harder to use in your continuous deployment scripts.
For example, to create and update Knative Service using kn, first run:
$ kn service create hello \ --image gcr.io/google-samples/hello-app:1.0
then run this to configure additional options (specified as –flags):
$ kn service update hello \ --image gcr.io/google-samples/hello-app:2.0 \ --max-scale 10 \ --limits-memory 256Mi
Note: If you use Knative via Google Cloud Run:
gcloud run deploycommand offers an imperative experience similar to
kn, where you don't work with YAML manifest files, everything is configured with a respective command-line option.
gcloud alpha run services replaceis the alternative that works with declarative YAML manifests, just like
kubectl apply. It's designed to be used in continuous delivery environments.