|
| 1 | +--- |
| 2 | +title: "Installing Knative with Kourier" |
| 3 | +linkTitle: "Kourier Ingress and Knative" |
| 4 | +weight: 15 |
| 5 | +type: "docs" |
| 6 | +--- |
| 7 | + |
| 8 | +[Kourier](https://github.com/3scale/kourier) is an open-source lightweight Knative Ingress based on Envoy. It's been designed for Knative, without requiring any additional custom resource definitions (CRDs). |
| 9 | + |
| 10 | +This guide walks you through the installation of the latest version of Knative |
| 11 | +with Kourier as the ingress. |
| 12 | + |
| 13 | +## Before you Begin |
| 14 | + |
| 15 | +Knative requires a Kubernetes cluster v1.14 or newer, as well as a compatible `kubectl`. This guide assumes that you have already [created a Kubernetes cluster](https://kubernetes.io/docs/setup/) and are using |
| 16 | +bash in a Mac or Linux environment. |
| 17 | + |
| 18 | +## Install Knative |
| 19 | + |
| 20 | +Let's do a core install of Knative Serving with the released yaml templates: |
| 21 | + |
| 22 | +1. To install Knative, first install the CRDs by running the following `kubectl apply` |
| 23 | + command. This prevents race conditions during the install, which cause intermittent errors: |
| 24 | + |
| 25 | + kubectl apply --filename https://github.com/knative/serving/releases/download/{{< version >}}/serving-crds.yaml |
| 26 | + |
| 27 | +1. To complete the install of Knative and its dependencies, next run the |
| 28 | + following `kubectl apply` command: |
| 29 | + |
| 30 | + kubectl apply --filename https://github.com/knative/serving/releases/download/{{< version >}}/serving-core.yaml |
| 31 | + |
| 32 | +1. Monitor the Knative Serving namespace and wait until all of the pods come up with a |
| 33 | + `STATUS` of `Running`: |
| 34 | + |
| 35 | + ``` |
| 36 | + kubectl get pods -w -n knative-serving |
| 37 | + ``` |
| 38 | +
|
| 39 | +
|
| 40 | +## Install Kourier |
| 41 | +
|
| 42 | +Knative default installation uses Istio to handle internal and external traffic. If you are just interested in exposing Knative applications to the external network, a service mesh adds overhead and increases the system complexity. Kourier provides a way to expose your Knative application in a more simple and lightweight way. |
| 43 | +
|
| 44 | +You can install Kourier with `kubectl`: |
| 45 | +
|
| 46 | +``` |
| 47 | +kubectl apply \ |
| 48 | + --filename https://raw.githubusercontent.com/knative/serving/{{< version >}}/third_party/kourier-latest/kourier.yaml |
| 49 | +``` |
| 50 | +
|
| 51 | +## Configuring the Knative ingress class |
| 52 | +
|
| 53 | +Kourier only exposes ingresses that have the "kourier" ingress class. By default Knative annotates all the ingresses for Istio but you can change that by patching the "config-network" configmap as follows: |
| 54 | +
|
| 55 | +``` |
| 56 | +kubectl patch configmap/config-network \ |
| 57 | + -n knative-serving \ |
| 58 | + --type merge \ |
| 59 | + -p '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}' |
| 60 | +``` |
| 61 | +
|
| 62 | +## Configuring DNS |
| 63 | +
|
| 64 | +Installing Kourier will create a Kubernetes Service with type `LoadBalancer`. |
| 65 | +This may take some time to get an IP address assigned, during this process, it |
| 66 | +will appear as `<pending>`. You must wait for this IP address to be assigned |
| 67 | +before DNS may be set up. |
| 68 | +
|
| 69 | +To get the external IP address, use the following command: |
| 70 | +
|
| 71 | +``` |
| 72 | +kubectl get svc kourier -n kourier-system |
| 73 | + |
| 74 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 75 | +kourier LoadBalancer 10.43.242.100 172.22.0.2 80:31828/TCP 19m |
| 76 | + |
| 77 | +``` |
| 78 | +
|
| 79 | +This external IP can be used with your DNS provider with a wildcard `A` record; |
| 80 | +however, for a basic functioning DNS setup (not suitable for production!) this |
| 81 | +external IP address can be added to the `config-domain` ConfigMap in |
| 82 | +`knative-serving`. You can edit this with the following command: |
| 83 | +
|
| 84 | +``` |
| 85 | +kubectl edit cm config-domain --namespace knative-serving |
| 86 | +``` |
| 87 | +
|
| 88 | +Given the external IP above, change the content to: |
| 89 | +
|
| 90 | +``` |
| 91 | +apiVersion: v1 |
| 92 | +kind: ConfigMap |
| 93 | +metadata: |
| 94 | + name: config-domain |
| 95 | + namespace: knative-serving |
| 96 | +data: |
| 97 | + # xip.io is a "magic" DNS provider, which resolves all DNS lookups for: |
| 98 | + # *.{ip}.xip.io to {ip}. |
| 99 | + 172.22.0.2.xip.io: "" |
| 100 | +``` |
| 101 | +
|
| 102 | +## Deploying an Application |
| 103 | +
|
| 104 | +Now that Kourier is running and Knative is configured properly, you can go ahead and create your first Knative application: |
| 105 | +
|
| 106 | +1. Create a `Knative Service` |
| 107 | +
|
| 108 | + For this demo, a simple helloworld application written in go will be used. |
| 109 | + Copy the YAML below to a file called `helloworld-go.yaml` and apply it with |
| 110 | + `kubectl` |
| 111 | +
|
| 112 | + ```yaml |
| 113 | + apiVersion: serving.knative.dev/v1 |
| 114 | + kind: Service |
| 115 | + metadata: |
| 116 | + name: helloworld-go |
| 117 | + namespace: default |
| 118 | + spec: |
| 119 | + template: |
| 120 | + spec: |
| 121 | + containers: |
| 122 | + - image: gcr.io/knative-samples/helloworld-go |
| 123 | + env: |
| 124 | + - name: TARGET |
| 125 | + value: Go Sample v1 |
| 126 | + ``` |
| 127 | + |
| 128 | + ``` |
| 129 | + kubectl apply -f helloworld-go.yaml |
| 130 | + ``` |
| 131 | + |
| 132 | +1. Send a request |
| 133 | + |
| 134 | + `Knative Service`s are exposed via a `Host` header assigned by Knative. By |
| 135 | + default, Knative will assign the `Host`: |
| 136 | + `{service-name}.{namespace}.{the domain we have setup above}`. You can see this |
| 137 | + with: |
| 138 | + |
| 139 | + ``` |
| 140 | + $ kubectl get ksvc helloworld-go |
| 141 | + NAME URL LATESTCREATED LATESTREADY READY REASON |
| 142 | + helloworld-go http://helloworld-go.default.172.22.0.2.xip.io helloworld-go-ps7lp helloworld-go-ps7lp True |
| 143 | + ``` |
| 144 | + |
| 145 | + You can send a request to the `helloworld-go` service with curl |
| 146 | + using the `URL` given above: |
| 147 | + |
| 148 | + ``` |
| 149 | + $ curl http://helloworld-go.default.172.22.0.2.xip.io |
| 150 | +
|
| 151 | + Hello Go Sample v1! |
| 152 | + ``` |
| 153 | + |
| 154 | +Congratulations! You have successfully installed Knative with Kourier to manage and route your serverless applications! |
| 155 | + |
| 156 | +## What's next |
| 157 | + |
| 158 | +- Try the |
| 159 | + [Getting Started with App Deployment guide](../serving/getting-started-knative-app.md) |
| 160 | + for Knative serving. |
| 161 | +- Get started with Knative Eventing by walking through one of the |
| 162 | + [Eventing Samples](../eventing/samples/). |
0 commit comments