@@ -14,8 +14,11 @@ then outputs the stock price.
14141 . [ 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.
16161 . 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
1922go 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
36391 . Move into the sample directory:
3740
38- ```
41+ ``` shell
3942cd $GOPATH /src/github.com/knative/docs
4043```
4144
42452 . 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
4750export REPO=" gcr.io/<YOUR_PROJECT_ID>"
4851```
4952
@@ -64,39 +67,33 @@ registry specific instructions for both setup and authorizing the image push.
6467
65684 . Use Docker to build your application container:
6669
67- ```
70+ ``` shell
6871docker 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
73765 . 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
9693Now that our image is available from the container registry, we can deploy the
9794Knative Serving sample:
9895
99- ```
96+ ``` shell
10097kubectl 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
121118kubectl 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
163160Knative. If you customized your gateway, you will want to adjust the enviornment
164161variables below.
165162
163+ ### Find Ingress Gateway IP
164+
165+ #### Cloud Provider
166+
1661671 . To get the IP address of your Ingress Gateway:
167168
168- ```
169+ ``` shell
169170INGRESSGATEWAY=istio-ingressgateway
170171INGRESSGATEWAY_LABEL=istio
171172
@@ -174,25 +175,31 @@ export INGRESS_IP=`kubectl get svc $INGRESSGATEWAY --namespace istio-system \
174175echo $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
183186export 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}' )
186189echo $INGRESS_IP
187190```
188191
192+ ### Get Service Hostname
193+
1891942 . To get the hostname of the Service:
190195
191- ```
196+ ``` shell
192197export SERVICE_HOSTNAME=` kubectl get ksvc stock-service-example --output jsonpath=" {.status.domain}" `
193198echo $SERVICE_HOSTNAME
194199```
195200
201+ ### Sending Requests
202+
1962033 . 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
202209passes the host header to skip DNS configuration. If your cluster has DNS
203210configured, you can simply curl the DNS name instead of the ingress gateway IP.
204211
205- ```
212+ ``` shell
206213curl --header " Host:$SERVICE_HOSTNAME " http://${INGRESS_IP}
207214```
208215
209216Response body: ` Welcome to the stock app! `
210217
211218- Make a request to the ` /stock ` endpoint:
212219
213- ```
220+ ``` shell
214221curl --header " Host:$SERVICE_HOSTNAME " http://${INGRESS_IP} /stock
215222```
216223
217224Response 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
222229curl --header " Host:$SERVICE_HOSTNAME " http://${INGRESS_IP} /stock/< ticker>
223230```
224231
@@ -235,6 +242,6 @@ between multiple Revisions.
235242
236243To clean up the sample Service:
237244
238- ```
245+ ``` shell
239246kubectl delete --filename serving/samples/rest-api-go/sample.yaml
240247```
0 commit comments