Skip to content

Commit 1a8a63d

Browse files
Dan Gerdesmeierknative-prow-robot
authored andcommitted
Update traffic splitting example to use Release mode (#964)
* Update traffic splitting example to use Release mode This change updates the traffic splitting example to use release mode introducing the concepts of the mode in three steps. This change also simplifies running the commands and removes the need to mutate files on disk to run through the example. * Use envsubst instead of perl. Simplify image path * Use long names for arguments * Update diff statement * Add envsubst install instructions
1 parent 5c55756 commit 1a8a63d

File tree

6 files changed

+245
-147
lines changed

6 files changed

+245
-147
lines changed

serving/samples/rest-api-go/README.md

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ then outputs the stock price.
1414
1. [Outbound network access](https://github.com/knative/docs/blob/master/serving/outbound-network-access.md)
1515
enabled for this Service to make external API requests.
1616
1. The code checked out locally.
17+
1. `envsubst` installed locally. This is installed by the `gettext` package. If
18+
not installed it can be installed by a Linux package manager, or by
19+
[Homebrew](https://brew.sh/) on OS X.
1720

18-
```
21+
```shell
1922
go get -d github.com/knative/docs/serving/samples/rest-api-go
2023
```
2124

@@ -35,15 +38,15 @@ To build and push to a container registry using Docker:
3538

3639
1. Move into the sample directory:
3740

38-
```
41+
```shell
3942
cd $GOPATH/src/github.com/knative/docs
4043
```
4144

4245
2. Set your preferred container registry endpoint as an environment variable.
4346
This sample uses
4447
[Google Container Registry (GCR)](https://cloud.google.com/container-registry/):
4548

46-
```
49+
```shell
4750
export REPO="gcr.io/<YOUR_PROJECT_ID>"
4851
```
4952

@@ -64,39 +67,33 @@ registry specific instructions for both setup and authorizing the image push.
6467

6568
4. Use Docker to build your application container:
6669

67-
```
70+
```shell
6871
docker build \
69-
--tag "${REPO}/serving/samples/rest-api-go" \
72+
--tag "${REPO}/rest-api-go" \
7073
--file serving/samples/rest-api-go/Dockerfile .
7174
```
7275

7376
5. Push your container to a container registry:
7477

78+
```shell
79+
docker push "${REPO}/rest-api-go"
7580
```
76-
docker push "${REPO}/serving/samples/rest-api-go"
77-
```
78-
79-
6. Replace the image reference path with our published image path in the
80-
configuration files (`serving/samples/rest-api-go/sample.yaml`:
81-
82-
- Manually replace:
83-
`image: github.com/knative/docs/serving/samples/rest-api-go` with
84-
`image: <YOUR_CONTAINER_REGISTRY>/serving/samples/rest-api-go`
8581

86-
Or
82+
6. Substitute the image reference path in the template with our published image
83+
path. The command below substitutes using the ${REPO} variable into a new
84+
file called `serving/samples/rest-api-go/sample.yaml`.
8785

88-
- Use run this command:
89-
90-
```
91-
perl -pi -e "[email protected]/knative/docs@${REPO}@g" serving/samples/rest-api-go/sample.yaml
86+
```shell
87+
envsubst < serving/samples/rest-api-go/sample-template.yaml > \
88+
serving/samples/rest-api-go/sample.yaml
9289
```
9390

9491
## Deploy the Service
9592

9693
Now that our image is available from the container registry, we can deploy the
9794
Knative Serving sample:
9895

99-
```
96+
```shell
10097
kubectl apply --filename serving/samples/rest-api-go/sample.yaml
10198
```
10299

@@ -117,42 +114,42 @@ You can inspect the created resources with the following `kubectl` commands:
117114

118115
- View the created Service resource:
119116

120-
```
117+
```shell
121118
kubectl get ksvc stock-service-example --output yaml
122119
```
123120

124121
- View the created Route resource:
125122

126-
```
127-
kubectl get route -l
123+
```shell
124+
kubectl get route -l \
128125
"serving.knative.dev/service=stock-service-example" --output yaml
129126
```
130127

131128
- View the Kubernetes Service created by the Route
132129

133-
```
134-
kubectl get service -l
130+
```shell
131+
kubectl get service -l \
135132
"serving.knative.dev/service=stock-service-example" --output yaml
136133
```
137134

138135
- View the created Configuration resource:
139136

140-
```
141-
kubectl get configuration -l
137+
```shell
138+
kubectl get configuration -l \
142139
"serving.knative.dev/service=stock-service-example" --output yaml
143140
```
144141

145142
- View the Revision that was created by our Configuration:
146143

147-
```
148-
kubectl get revision -l
144+
```shell
145+
kubectl get revision -l \
149146
"serving.knative.dev/service=stock-service-example" --output yaml
150147
```
151148

152149
- View the Deployment created by our Revision
153150

154-
```
155-
kubectl get deployment -l
151+
```shell
152+
kubectl get deployment -l \
156153
"serving.knative.dev/service=stock-service-example" --output yaml
157154
```
158155

@@ -163,9 +160,13 @@ This example assumes you are using the default Ingress Gateway setup for
163160
Knative. If you customized your gateway, you will want to adjust the enviornment
164161
variables below.
165162

163+
### Find Ingress Gateway IP
164+
165+
#### Cloud Provider
166+
166167
1. To get the IP address of your Ingress Gateway:
167168

168-
```
169+
```shell
169170
INGRESSGATEWAY=istio-ingressgateway
170171
INGRESSGATEWAY_LABEL=istio
171172

@@ -174,25 +175,31 @@ export INGRESS_IP=`kubectl get svc $INGRESSGATEWAY --namespace istio-system \
174175
echo $INGRESS_IP
175176
```
176177

177-
- If your cluster is running outside a cloud provider (for example on Minikube),
178+
#### Minikube
179+
180+
1. If your cluster is running outside a cloud provider (for example on Minikube),
178181
your services will never get an external IP address, and your INGRESS_IP will
179182
be empty. In that case, use the istio `hostIP` and `nodePort` as the ingress
180183
IP:
181184

182-
```
185+
```shell
183186
export INGRESS_IP=$(kubectl get po --selector $INGRESSGATEWAY_LABEL=ingressgateway --namespace istio-system \
184187
--output 'jsonpath={.items[0].status.hostIP}'):$(kubectl get svc $INGRESSGATEWAY --namespace istio-system \
185188
--output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
186189
echo $INGRESS_IP
187190
```
188191

192+
### Get Service Hostname
193+
189194
2. To get the hostname of the Service:
190195

191-
```
196+
```shell
192197
export SERVICE_HOSTNAME=`kubectl get ksvc stock-service-example --output jsonpath="{.status.domain}"`
193198
echo $SERVICE_HOSTNAME
194199
```
195200

201+
### Sending Requests
202+
196203
3. Now use `curl` to make a request to the Service:
197204

198205
- Make a request to the index endpoint:
@@ -202,23 +209,23 @@ Gateway uses the host header to route the request to the Service. This example
202209
passes the host header to skip DNS configuration. If your cluster has DNS
203210
configured, you can simply curl the DNS name instead of the ingress gateway IP.
204211

205-
```
212+
```shell
206213
curl --header "Host:$SERVICE_HOSTNAME" http://${INGRESS_IP}
207214
```
208215

209216
Response body: `Welcome to the stock app!`
210217

211218
- Make a request to the `/stock` endpoint:
212219

213-
```
220+
```shell
214221
curl --header "Host:$SERVICE_HOSTNAME" http://${INGRESS_IP}/stock
215222
```
216223

217224
Response body: `stock ticker not found!, require /stock/{ticker}`
218225

219226
- Make a request to the `/stock` endpoint with a `ticker` parameter:
220227

221-
```
228+
```shell
222229
curl --header "Host:$SERVICE_HOSTNAME" http://${INGRESS_IP}/stock/<ticker>
223230
```
224231

@@ -235,6 +242,6 @@ between multiple Revisions.
235242

236243
To clean up the sample Service:
237244

238-
```
245+
```shell
239246
kubectl delete --filename serving/samples/rest-api-go/sample.yaml
240247
```

serving/samples/rest-api-go/sample.yaml renamed to serving/samples/rest-api-go/sample-template.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ spec:
2020
runLatest:
2121
configuration:
2222
revisionTemplate:
23-
metadata:
24-
labels:
25-
knative.dev/type: container
2623
spec:
2724
container:
28-
# This is the Go import path for the binary to containerize
29-
# and substitute here.
30-
image: github.com/knative/docs/serving/samples/rest-api-go
25+
image: ${REPO}/rest-api-go
3126
env:
3227
- name: RESOURCE
3328
value: stock

0 commit comments

Comments
 (0)