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. This sample also shows how to create a dedicated Prometheus instance rather than using the default installation.
- A Kubernetes cluster with Knative Serving installed.
- Check if Knative monitoring components are installed:
kubectl get pods --namespace knative-monitoring
- If pods aren't found, install Knative monitoring component.
- Install Docker.
- Check out the code:
go get -d github.com/knative/docs/serving/samples/telemetry-go
Build the application container and publish it to a container registry:
- Move into the sample directory:
cd $GOPATH/src/github.com/knative/docs
- Set your preferred container registry:
export REPO="gcr.io/<YOUR_PROJECT_ID>"
This example shows how to use Google Container Registry (GCR). You will need a Google Cloud Project and to enable the Google Container Registry API.
- Use Docker to build your application container:
docker build \
--tag "${REPO}/serving/samples/telemetry-go" \
--file=serving/samples/telemetry-go/Dockerfile .
- Push your container to a container registry:
docker push "${REPO}/serving/samples/telemetry-go"
-
Replace the image reference path with our published image path in the configuration file (
serving/samples/telemetry-go/sample.yaml
):-
Manually replace:
image: github.com/knative/docs/serving/samples/telemetry-go
withimage: <YOUR_CONTAINER_REGISTRY>/serving/samples/telemetry-go
Or
-
Use run this command:
perl -pi -e "s@github.com/knative/docs@${REPO}@g" serving/samples/telemetry-go/sample.yaml
-
Deploy this application to Knative Serving:
kubectl apply --filename serving/samples/telemetry-go/
Inspect the created resources with the kubectl
commands:
- View the created Route resource:
kubectl get route --output yaml
- View the created Configuration resource:
kubectl get configurations --output yaml
- View the Revision that was created by the Configuration:
kubectl get revisions --output yaml
To access this service via curl
, you need to determine its ingress address.
- To determine if your service is ready:
Check the status of your Knative gateway:
kubectl get svc knative-ingressgateway --namespace istio-system --watch
When the service is ready, you'll see an IP address in the EXTERNAL-IP
field:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
CTRL+C to end watch.
Check the status of your route:
kubectl get route --output yaml
When the route is ready, you'll see the following fields reported as:
status:
conditions:
...
status: "True"
type: Ready
domain: telemetrysample-route.default.example.com
- Export the ingress hostname and IP as environment variables:
export SERVICE_HOST=`kubectl get route telemetrysample-route --output jsonpath="{.status.domain}"`
export SERVICE_IP=`kubectl get svc knative-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"`
- Make a request to the service to see the
Hello World!
message:
curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP}
- Make a request to the
/log
endpoint to generate logs to thestdout
file and generate files under/var/log
in bothJSON
and plain text formats:
curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP}/log
You can access to the logs from Kibana UI - see Logs for more information.
You can access to per request traces from Zipkin UI - see Traces for more information.
You can see published metrics using Prometheus UI. To access to the UI, forward the Prometheus server to your machine:
kubectl port-forward $(kubectl get pods --selector=app=prometheus,prometheus=test --output=jsonpath="{.items[0].metadata.name}") 9090
Then browse to http://localhost:9090.
To clean up the sample service:
kubectl delete --filename serving/samples/telemetry-go/