Installing Knative Serving using YAML files

This topic describes how to install Knative Serving by applying YAML files using the kubectl CLI.

Prerequisites

Before installation, you must meet the prerequisites. See Knative Prerequisites.

Install the Serving component

To install the serving component:

  1. Install the required custom resources:

    1. kubectl apply -f https://github.com/knative/serving/releases/download/v0.23.0/serving-crds.yaml
  2. Install the core components of Knative Serving:

    1. kubectl apply -f https://github.com/knative/serving/releases/download/v0.23.0/serving-core.yaml

For information about the YAML files in the Knative Serving and Eventing releases, see Installation files.

Install a networking layer

The networking layer in Knative Serving is responsible for incoming requests and the associated responses for your Knative installation. Knative enables you to choose a networking layer and then translates Knative’s resources into the specific configuration for your chosen networking solution.

You can choose a networking layer based on what you are familiar with, what is already installed on your cluster, or what is suitable for your use case. For prototyping purposes, if you have no preference for a networking layer, choose Kourier. For production use cases, Istio is a common choice.

The tabs below expand to show instructions for installing a networking layer. Follow the procedure for the networking layer of your choice:

The following commands install Ambassador and enable its Knative integration.

  1. Create a namespace to install Ambassador in:

    1. kubectl create namespace ambassador
  2. Install Ambassador:

    1. kubectl apply --namespace ambassador \
    2. -f https://getambassador.io/yaml/ambassador/ambassador-crds.yaml \
    3. -f https://getambassador.io/yaml/ambassador/ambassador-rbac.yaml \
    4. -f https://getambassador.io/yaml/ambassador/ambassador-service.yaml
  3. Give Ambassador the required permissions:

    1. kubectl patch clusterrolebinding ambassador -p '{"subjects":[{"kind": "ServiceAccount", "name": "ambassador", "namespace": "ambassador"}]}'
  4. Enable Knative support in Ambassador:

    1. kubectl set env --namespace ambassador deployments/ambassador AMBASSADOR_KNATIVE_SUPPORT=true
  5. To configure Knative Serving to use Ambassador by default:

    1. kubectl patch configmap/config-network \
    2. --namespace knative-serving \
    3. --type merge \
    4. --patch '{"data":{"ingress.class":"ambassador.ingress.networking.knative.dev"}}'
  6. Fetch the External IP or CNAME:

    1. kubectl --namespace ambassador get service ambassador

    Save this for configuring DNS below.

The following commands install Contour and enable its Knative integration.

  1. Install a properly configured Contour:

    1. kubectl apply -f https://github.com/knative/net-contour/releases/download/v0.23.0/contour.yaml
  2. Install the Knative Contour controller:

    1. kubectl apply -f https://github.com/knative/net-contour/releases/download/v0.23.0/net-contour.yaml
  3. To configure Knative Serving to use Contour by default:

    1. kubectl patch configmap/config-network \
    2. --namespace knative-serving \
    3. --type merge \
    4. --patch '{"data":{"ingress.class":"contour.ingress.networking.knative.dev"}}'
  4. Fetch the External IP or CNAME:

    1. kubectl --namespace contour-external get service envoy

    Save this for configuring DNS below.

For a detailed guide on Gloo integration, see Installing Gloo for Knative in the Gloo documentation.

The following commands install Gloo and enable its Knative integration.

  1. Make sure glooctl is installed (version 1.3.x and higher recommended):

    1. glooctl version

    If it is not installed, you can install the latest version using:

    1. curl -sL https://run.solo.io/gloo/install | sh
    2. export PATH=$HOME/.gloo/bin:$PATH

    Or following the Gloo CLI install instructions.

  2. Install Gloo and the Knative integration:

    1. glooctl install knative --install-knative=false
  3. Fetch the External IP or CNAME:

    1. glooctl proxy url --name knative-external-proxy

    Save this for configuring DNS below.

The following commands install Istio and enable its Knative integration.

  1. Install a properly configured Istio (Advanced installation)

    1. kubectl apply -f https://github.com/knative/net-istio/releases/download/v0.23.0/istio.yaml
  2. Install the Knative Istio controller:

    1. kubectl apply -f https://github.com/knative/net-istio/releases/download/v0.23.0/net-istio.yaml
  3. Fetch the External IP or CNAME:

    1. kubectl --namespace istio-system get service istio-ingressgateway

    Save this for configuring DNS below.

The following commands install Kong and enable its Knative integration.

  1. Install Kong Ingress Controller:

    1. kubectl apply -f https://raw.githubusercontent.com/Kong/kubernetes-ingress-controller/0.9.x/deploy/single/all-in-one-dbless.yaml
  2. To configure Knative Serving to use Kong by default:

    1. kubectl patch configmap/config-network \
    2. --namespace knative-serving \
    3. --type merge \
    4. --patch '{"data":{"ingress.class":"kong"}}'
  3. Fetch the External IP or CNAME:

    1. kubectl --namespace kong get service kong-proxy

    Save this for configuring DNS below.

The following commands install Kourier and enable its Knative integration.

  1. Install the Knative Kourier controller:

    1. kubectl apply -f https://github.com/knative/net-kourier/releases/download/v0.23.0/kourier.yaml
  2. To configure Knative Serving to use Kourier by default:

    1. kubectl patch configmap/config-network \
    2. --namespace knative-serving \
    3. --type merge \
    4. --patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'
  3. Fetch the External IP or CNAME:

    1. kubectl --namespace kourier-system get service kourier

    Save this for configuring DNS below.

Verify the installation

Monitor the Knative components until all of the components show a STATUS of Running or Completed:

  1. kubectl get pods --namespace knative-serving

Configure DNS

You can configure DNS to prevent the need to run curl commands with a host header.

The tabs below expand to show instructions for configuring DNS. Follow the procedure for the DNS of your choice:

We ship a simple Kubernetes Job called “default domain” that will (see caveats) configure Knative Serving to use sslip.io as the default DNS suffix.

  1. kubectl apply -f https://github.com/knative/serving/releases/download/v0.23.0/serving-default-domain.yaml

Caveat: 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. For these, see “Real DNS” or “Temporary DNS”.

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:

    1. # Here knative.example.com is the domain suffix for your cluster
    2. *.knative.example.com == A 35.233.41.212
  • If the networking layer produced a CNAME, then configure a CNAME record for the domain:

    1. # Here knative.example.com is the domain suffix for your cluster
    2. *.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:

  1. # Replace knative.example.com with your domain suffix
  2. kubectl patch configmap/config-domain \
  3. --namespace knative-serving \
  4. --type merge \
  5. --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:

  1. After starting your application, get the URL of your application:

    1. kubectl get ksvc

    The output should be similar to:

    1. NAME URL LATESTCREATED LATESTREADY READY REASON
    2. helloworld-go http://helloworld-go.default.example.com helloworld-go-vqjlf helloworld-go-vqjlf True
  2. Instruct curl to connect to the External IP or CNAME defined by the networking layer in section 3 above, 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 be http://192.168.39.228:32198 and you wish to access the above helloworld-go application, use:

    1. curl -H "Host: helloworld-go.default.example.com" http://192.168.39.228:32198

    In the case of the provided helloworld-go sample application, the output should, using the default configuration, be:

    1. Hello Go Sample v1!

Refer to the “Real DNS” method for a permanent solution.

Next steps

After installing Knative Serving: