Installing Knative Serving using YAML files¶
This topic describes how to install Knative Serving by applying YAML files using the kubectl
CLI.
Prerequisites¶
Before installing Knative, you must meet the following prerequisites:
-
For prototyping purposes, Knative works on most local deployments of Kubernetes. For example, you can use a local, one-node cluster that has 3 CPUs and 4 GB of memory.
Tip
You can install a local distribution of Knative for development purposes using the Knative Quickstart plugin
-
For production purposes, it is recommended that:
- If you have only one node in your cluster, you need at least 6 CPUs, 6 GB of memory, and 30 GB of disk storage.
- If you have multiple nodes in your cluster, for each node you need at least 2 CPUs, 4 GB of memory, and 20 GB of disk storage.
- You have a cluster that uses Kubernetes v1.28 or newer.
- You have installed the
kubectl
CLI. - Your Kubernetes cluster must have access to the internet, because Kubernetes needs to be able to fetch images. To pull from a private registry, see Deploying images from a private container registry.
Caution
The system requirements provided are recommendations only. The requirements for your installation might vary, depending on whether you use optional components, such as a networking layer.
Verifying image signatures¶
Knative releases from 1.9 onwards are signed with cosign.
curl -sSL https://storage.googleapis.com/knative-nightly/serving/latest/serving-core.yaml \
| grep 'gcr.io/' | awk '{print $2}' | sort | uniq \
| xargs -n 1 \
cosign verify -o text \
--certificate-identity=signer@knative-releases.iam.gserviceaccount.com \
--certificate-oidc-issuer=https://accounts.google.com
Note
Knative images are signed in KEYLESS
mode. To learn more about keyless signing, please refer to
Keyless Signatures
Our signing identity(Subject) for our releases is signer@knative-releases.iam.gserviceaccount.com
and the Issuer is https://accounts.google.com
Install the Knative Serving component¶
To install the Knative Serving component:
-
Install the required custom resources by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/serving/latest/serving-crds.yaml
-
Install the core components of Knative Serving by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/serving/latest/serving-core.yaml
Info
For information about the YAML files in Knative Serving, see Knative Serving installation files.
Install a networking layer¶
The following tabs expand to show instructions for installing a networking layer. Follow the procedure for the networking layer of your choice:
The following commands install Kourier and enable its Knative integration.
-
Install the Knative Kourier controller by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/net-kourier/latest/kourier.yaml
-
Configure Knative Serving to use Kourier by default by running the command:
kubectl patch configmap/config-network \ --namespace knative-serving \ --type merge \ --patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'
-
Fetch the External IP address or CNAME by running the command:
kubectl --namespace kourier-system get service kourier
Tip
Save this to use in the following Configure DNS section.
The following commands install Istio and enable its Knative integration.
-
Install a properly configured Istio by following the Advanced Istio installation instructions or by running the command:
kubectl apply -l knative.dev/crd-install=true -f https://storage.googleapis.com/knative-nightly/net-istio/latest/istio.yaml kubectl apply -f https://storage.googleapis.com/knative-nightly/net-istio/latest/istio.yaml
-
Install the Knative Istio controller by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/net-istio/latest/net-istio.yaml
-
Fetch the External IP address or CNAME by running the command:
kubectl --namespace istio-system get service istio-ingressgateway
Tip
Save this to use in the following Configure DNS section.
The following commands install Contour and enable its Knative integration.
-
Install a properly configured Contour by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/net-contour/latest/contour.yaml
-
Install the Knative Contour controller by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/net-contour/latest/net-contour.yaml
-
Configure Knative Serving to use Contour by default by running the command:
kubectl patch configmap/config-network \ --namespace knative-serving \ --type merge \ --patch '{"data":{"ingress-class":"contour.ingress.networking.knative.dev"}}'
-
Fetch the External IP address or CNAME by running the command:
kubectl --namespace contour-external get service envoy
Tip
Save this to use in the following Configure DNS section.
Verify the installation¶
Success
Monitor the Knative components until all of the components show a STATUS
of Running
or Completed
.
You can do this by running the following command and inspecting the output:
kubectl get pods -n knative-serving
Example output:
NAME READY STATUS RESTARTS AGE
3scale-kourier-control-54cc54cc58-mmdgq 1/1 Running 0 81s
activator-67656dcbbb-8mftq 1/1 Running 0 97s
autoscaler-df6856b64-5h4lc 1/1 Running 0 97s
controller-788796f49d-4x6pm 1/1 Running 0 97s
domain-mapping-65f58c79dc-9cw6d 1/1 Running 0 97s
domainmapping-webhook-cc646465c-jnwbz 1/1 Running 0 97s
webhook-859796bc7-8n5g2 1/1 Running 0 96s
Configure DNS¶
You can configure DNS to prevent the need to run curl commands with a host header.
The following tabs expand to show instructions for configuring DNS. Follow the procedure for the DNS of your choice:
Knative provides a Kubernetes Job called default-domain
that configures Knative Serving to use sslip.io as the default DNS suffix.
kubectl apply -f https://storage.googleapis.com/knative-nightly/serving/latest/serving-default-domain.yaml
Warning
This will only work if the cluster LoadBalancer
Service exposes an
IPv4 address or hostname, so it will not work with IPv6 clusters or local setups
like minikube unless minikube tunnel
is running.
In these cases, see the "Real DNS" or "No DNS" tabs.
To configure DNS for Knative, take the External IP or CNAME from setting up networking, and configure it with your DNS provider as follows:
-
If the networking layer produced an External IP address, then configure a wildcard
A
record for the domain:# Here knative.example.com is the domain suffix for your cluster *.knative.example.com == A 35.233.41.212
-
If the networking layer produced a CNAME, then configure a CNAME record for the domain:
# Here knative.example.com is the domain suffix for your cluster *.knative.example.com == CNAME a317a278525d111e89f272a164fd35fb-1510370581.eu-central-1.elb.amazonaws.com
-
Once your DNS provider has been configured, direct Knative to use that domain:
# Replace knative.example.com with your domain suffix kubectl patch configmap/config-domain \ --namespace knative-serving \ --type merge \ --patch '{"data":{"knative.example.com":""}}'
If you are using curl
to access the sample applications, or your own Knative app, and are unable to use the "Magic DNS (sslip.io)" or "Real DNS" methods, there is a temporary approach. This is useful for those who wish to evaluate Knative without altering their DNS configuration, as per the "Real DNS" method, or cannot use the "Magic DNS" method due to using,
for example, minikube locally or IPv6 clusters.
To access your application using curl
using this method:
-
Configure Knative to use a domain reachable from outside the cluster:
kubectl patch configmap/config-domain \ --namespace knative-serving \ --type merge \ --patch '{"data":{"example.com":""}}'
-
After starting your application, get the URL of your application:
The output should be similar to:kubectl get ksvc
NAME URL LATESTCREATED LATESTREADY READY REASON helloworld-go http://helloworld-go.default.example.com helloworld-go-vqjlf helloworld-go-vqjlf True
-
Instruct
curl
to connect to the External IP or CNAME defined by the networking layer mentioned in section 3, and use the-H "Host:"
command-line option to specify the Knative application's host name. For example, if the networking layer defines your External IP and port to behttp://192.168.39.228:32198
and you wish to access thehelloworld-go
application mentioned earlier, use:In the case of the providedcurl -H "Host: helloworld-go.default.example.com" http://192.168.39.228:32198
helloworld-go
sample application, using the default configuration, the output is:Refer to the "Real DNS" method for a permanent solution.Hello Go Sample v1!
Install optional Serving extensions¶
The following tabs expand to show instructions for installing each Serving extension.
Knative also supports the use of the Kubernetes Horizontal Pod Autoscaler (HPA) for driving autoscaling decisions.
-
Install the components needed to support HPA-class autoscaling by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/serving/latest/serving-hpa.yaml
Knative supports encryption features through cert-manager. Follow the documentation in Serving encryption for more information.