Usage Scenario
After deploying your microservice-based application to Kyma, you want to monitor it continuously with Kyma's telemetry capabilities and the integration to SAP Cloud Logging.
Task Flow
In this exercise, you will perform the following tasks:
- Deploy a sample application that produces application logs.
- Provision an SAP Cloud Logging service instance and create a service binding with credential rotation.
- Configure a Kyma Telemetry LogPipeline resource that references the binding.
- Add deep linking to Kyma dashboard.
- Use SAP Cloud Logging to explore logs.
Prerequisites
Before you begin, ensure that the following prerequisites are met:
- You have created a SAP BTP, Kyma runtime instance in the SAP BTP subaccount. See Deploying a Kubernetes Cluster with Kyma on SAP BTP.
- You have configured kubectl to interact with your SAP BTP, Kyma runtime instance. See Setting and Configuring Kubectl for Kyma.
- You have added the Serverless module. See Adding Kyma Modules.
- You have an entitlement for an SAP Cloud Logging plan.
Task 1: Deploy a Sample Application that Produces Application Logs
Steps
Create a new namespace calledtelemetry-exercise:
Code Snippet1kubectl create namespace telemetry-exerciseIn the telemetry-exercise namespace, create a new Deployment called hello-kyma:
Code Snippet1kubectl apply -n telemetry-exercise -f https://raw.githubusercontent.com/SAP-samples/kyma-runtime-learning-journey/main/unit_9/hello-kyma-deployment-svc.yamlVerify if the Deployment is created:
Code Snippet1kubectl get deployments -n telemetry-exerciseIf successful, you get the following output:
Code Snippet12NAME READY UP-TO-DATE AVAILABLE AGE hello-kyma 1/1 1 1 2mPort-forward the `hello-kyma` Service to your local machine:
Code Snippet1kubectl port-forward -n telemetry-exercise svc/hello-kyma 8080:8080Leave this terminal window open, and open http://localhost:8080 in a new browser tab. You get the message Hello Kyma! (Version 1.0.0).
Stop the port-forwarding by pressing Ctrl+C in the terminal window.
Verify that logs are written for every request to stdout:
Code Snippet1kubectl logs -n telemetry-exercise -l app=hello-kymaThe logs retrieved with kubectl are stored temporarily on the Node file system. These logs are rotated frequently and are lost when the Pod or the Node is rescheduled. The following setup collects the logs from the Node file system, stores them long-term in SAP Cloud Logging, and makes them searchable across Pods and namespaces.
In this task, you will create a new hello-kyma Deployment and Service in a new namespace called telemetry-exercise. The deployment uses the image ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0, which writes application logs for incoming requests to stdout in JSON format.
Task 2: Provision an SAP Cloud Logging Instance and Create a Binding with Credential Rotation
Steps
Using the SAP BTP Operator module (which is in your Kyma cluster by default), define a new instance for SAP Cloud Logging:
Code Snippet12345678910111213cat <<EOF | kubectl -n telemetry-exercise apply -f - apiVersion: services.cloud.sap.com/v1 kind: ServiceInstance metadata: name: cloud-logging spec: serviceOfferingName: cloud-logging servicePlanName: standard externalName: Cloud Logging parameters: ingest_otlp: # must be enabled for trace and metric data ingestion enabled: true EOFFor the instance you just created, define a new Service Binding that has credential rotation enabled:
Code Snippet1234567891011121314cat <<EOF | kubectl -n telemetry-exercise apply -f - apiVersion: services.cloud.sap.com/v1 kind: ServiceBinding metadata: name: cloud-logging spec: serviceInstanceName: cloud-logging externalName: cloud-logging secretName: cloud-logging credentialsRotationPolicy: enabled: true rotationFrequency: 720h rotatedBindingTTL: 24h EOFThe credential rotation rotates the credentials in the generated Secret periodically, keeping the old credentials valid in parallel for the specified TTL. Whenever the content of the Secret changes, the LogPipeline resource defined in the following step reloads the Secret value dynamically. This assures that the credentials do not expire and are rotated frequently.
To verify the setup, check the state of the service instance and binding:
Code Snippet1kubectl -n telemetry-exercise get serviceinstanceCode Snippet1kubectl -n telemetry-exercise get servicebindingIt takes several minutes till the instance is provisioned and the binding and the related Kubernetes Secret are created. However, you can continue with the next steps already because the LogPipeline picks up the Secret value dynamically as soon as it is ready.
Task 3: Configure a Kyma Telemetry LogPipeline Referencing the Service Binding
Steps
Create a LogPipeline:
Code Snippet123456789101112131415161718192021222324252627282930cat <<EOF | kubectl apply -f - apiVersion: telemetry.kyma-project.io/v1alpha1 kind: LogPipeline metadata: name: cloud-logging spec: output: http: dedot: true host: valueFrom: secretKeyRef: name: cloud-logging namespace: telemetry-exercise key: ingest-mtls-endpoint tls: cert: valueFrom: secretKeyRef: name: cloud-logging namespace: telemetry-exercise key: ingest-mtls-cert key: valueFrom: secretKeyRef: name: cloud-logging namespace: telemetry-exercise key: ingest-mtls-key uri: /customindex/kyma EOFNote
This example uses a LogPipeline, but the Telemetry module is not limited to logs. You can integrate traces and metrics in a similar way.
Task 4: Use SAP Cloud Logging to Explore Logs
Steps
To see your credentials, inspect the Secret:
Code Snippet1kubectl -n telemetry-exercise get secret cloud-logging -o go-template='{{range $key, $value := .data}}{{$key}}={{$value|base64decode}}{{"\n"}}{{end}}'The attribute dashboards-endpoint contains the URL to the SAP Cloud Logging Dashboard. The attributes dashboards-username and dashboards-password contain the credentials for authentication.
Open the URL taken from dashboards-endpoint and authenticate yourself with the credentials.
In the Discover section, inspect the logs-json-kyma-* indexes. All logs are instantly available for query with the used log attributes.
Setting up SAP Cloud Logging also resulted in the creation of a Secret. This Secret contains details for pushing data to SAP Cloud Logging and for accessing the SAP Cloud Logging Dashboard.
Note
This example simplifies the setup by using Basic Authentication with a shared secret for the access to the SAP Cloud Logging Dashboard. However, when you're using Kyma in live environments, it's recommended to use single-sign-on (SSO), for example with a SAML configuration. If you use SSO, no credentials for the SAP Cloud Logging Dashboard access are provided with the generated Secret.
Task 5: Add Deep Linking to Kyma Dashboard
Steps
To add navigation and deep links to Kyma dashboard, follow Use SAP Cloud Logging Dashboards.
To try out the new links, go to Kyma dashboard, choose a namespace, and select Discover Logs in SAP Cloud Logging.
Result
Bravo! You have completed this exercise. You have used the Telemetry module to collect and visualize the logs of your extension with SAP Cloud Logging.