diff --git a/serving/samples/README.md b/serving/samples/README.md index 33a28b936..82d143221 100644 --- a/serving/samples/README.md +++ b/serving/samples/README.md @@ -19,3 +19,4 @@ to learn more about Knative Serving resources. | Source to URL | A sample that shows how to use Knative to go from source code in a git repository to a running application with a URL. | [Go](source-to-url/README.md) | | Telemetry | This sample runs a simple web server that makes calls to other in-cluster services and responds to requests with "Hello World!". The purpose of this sample is to show generating metrics, logs, and distributed traces. | [Go](telemtry-go/README.md) | | Thumbnailer | An example of deploying a "dockerized" application to Knative Serving which takes video URL as an input and generates its thumbnail image. | [Go](thumbnailer-go/README.md) | +| Traffic Splitting | This samples builds off the [Creating a RESTful Service](../rest-api-go) sample to illustrate applying a revision, then using that revision for manual traffic splitting. | [YAML](traffic-splitting/README.md) | diff --git a/serving/samples/traffic-splitting/README.md b/serving/samples/traffic-splitting/README.md new file mode 100644 index 000000000..e0f2857b0 --- /dev/null +++ b/serving/samples/traffic-splitting/README.md @@ -0,0 +1,103 @@ +# Simple Traffic Splitting Between Revisions + +This samples builds off the [Creating a RESTful Service](../rest-api-go) sample +to illustrate applying a revision, then using that revision for manual traffic splitting. + +## Prerequisites + +1. [Creating a RESTful Service](../rest-api-go). + +## Updating the Service + +This section describes how to create an revision by deploying a new configuration. + +1. Replace the image reference path with our published image path in the configuration files (`serving/samples/traffic-splitting/updated_configuration.yaml`: + * Manually replace: + `image: github.com/knative/docs/serving/samples/rest-api-go` with `image: /serving/samples/rest-api-go` + + Or + + * Use run this command: + ``` + perl -pi -e "s@github.com/knative/docs@${REPO}@g" serving/samples/rest-api-go/updated_configuration.yaml + ``` + +2. Deploy the new configuration to update the `RESOURCE` environment variable +from `stock` to `share`: +``` +kubectl apply -f serving/samples/traffic-splitting/updated_configuration.yaml +``` + +3. Once deployed, traffic will shift to the new revision automatically. Verify the deployment by checking the route status: +``` +kubectl get route -o yaml +``` + +4. When the new route is ready, you can access the new endpoints: + The hostname and IP address can be found in the same manner as the [Creating a RESTful Service](../rest-api-go) sample: + ``` + export SERVICE_HOST=`kubectl get route stock-route-example -o jsonpath="{.status.domain}"` + export SERVICE_IP=`kubectl get svc knative-ingressgateway -n istio-system \ + -o jsonpath="{.status.loadBalancer.ingress[*].ip}"` + ``` + + * Make a request to the index endpoint: + ``` + curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP} + ``` + Response body: `Welcome to the share app!` + + * Make a request to the `/share` endpoint: + ``` + curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP}/share + ``` + Response body: `share ticker not found!, require /share/{ticker}` + + * Make a request to the `/share` endpoint with a `ticker` parameter: + ``` + curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP}/share/ + ``` + Response body: `share price for ticker is ` + +## Manual Traffic Splitting + +This section describes how to manually split traffic to specific revisions. + +1. Get your revisions names via: +``` +kubectl get revisions +``` +``` +NAME AGE +stock-configuration-example-00001 11m +stock-configuration-example-00002 4m +``` + +2. Update the `traffic` list in `serving/samples/rest-api-go/sample.yaml` as: +```yaml +traffic: + - revisionName: + percent: 50 + - revisionName: + percent: 50 +``` + +3. Deploy your traffic revision: +``` +kubectl apply -f serving/samples/rest-api-go/sample.yaml +``` + +4. Verify the deployment by checking the route status: +``` +kubectl get route -o yaml +``` +Once updated, you can make `curl` requests to the API using either `stock` or `share` +endpoints. + +## Clean Up + +To clean up the sample service: + +``` +kubectl delete -f serving/samples/traffic-splitting/updated_configuration.yaml +``` diff --git a/serving/samples/rest-api-go/updated_configuration.yaml b/serving/samples/traffic-splitting/updated_configuration.yaml similarity index 100% rename from serving/samples/rest-api-go/updated_configuration.yaml rename to serving/samples/traffic-splitting/updated_configuration.yaml