-
Notifications
You must be signed in to change notification settings - Fork 258
docs(cockpit): added documentation on how to add custom metrics from k8s cluster to cockpit int-add-observability #4176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
045bab6
docs(cockpit): added documentation on how to add custom logs from k8s…
8867ccd
docs(observability): add comment to explain annotation
a25aa6a
docs(cockpit): neda review
nerda-codes 09a844e
fix(docs): typo in closing tag of a <Message> block
79f24f6
add(docs): link to metrics tutorial in note
98244d3
add(docs): docs to send metrics from k8s cluster to cockpit
adf9f87
Update documentation to follow upgrade of k8s-monitoring from 1.6.16 …
cace6a6
wording: change Grafana to Cockpit
3a5861c
feat(cockpit-k8s): review & test néda
nerda-codes fac49cf
feat(cockpit-k8s): néda review & test doc metrics
nerda-codes 60b5973
feat(cockpit-k8s): neda review fix typos & inconsistencies logs doc
nerda-codes 7ceabd7
docs(review): neda suggestions
nerda-codes e26ec9c
Apply suggestions from code review
nerda-codes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
observability/cockpit/how-to/send-log-from-k8s-to-cockpit.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| --- | ||
| meta: | ||
| title: How to send logs from your Kubernetes cluster to your Cockpit | ||
| description: Learn how to send your pod logs to your Cockpit using Scaleway's comprehensive guide. This tutorial covers sending Kubernetes pods logs to Scaleway's Cockpit for centralized monitoring and analysis using Grafana, ensuring efficient monitoring and log analysis in your infrastructure. | ||
| content: | ||
| h1: How to send logs from your Kubernetes cluster to your Cockpit | ||
| paragraph: Learn how to send your pod logs to your Cockpit using Scaleway's comprehensive guide. This tutorial covers sending Kubernetes pods logs to Scaleway's Cockpit for centralized monitoring and analysis using Grafana, ensuring efficient monitoring and log analysis in your infrastructure. | ||
| tags: kubernetes cockpit logs observability monitoring cluster | ||
| categories: | ||
| - observability | ||
| dates: | ||
| validation: 2025/01/20 | ||
| posted: 2025/01/20 | ||
| --- | ||
|
|
||
| In this page we will show you how to send application logs from your Kubernetes cluster to your Cockpit using either a Helm chart or deploying a Helm chart with [Terraform](https://www.terraform.io/). | ||
|
|
||
| We will use the [k8s-monitoring](https://artifacthub.io/packages/helm/grafana/k8s-monitoring/1.6.16) Helm Chart, which installs an Alloy Daemon set to export your Kubernetes cluster's logs to your Cockpit. | ||
|
|
||
| <Macro id="requirements" /> | ||
|
|
||
| - A Scaleway account logged into the [console](https://console.scaleway.com) | ||
| - [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization | ||
| - [Created](/observability/cockpit/how-to/create-external-data-sources/) a custom external data source of the [logs type](/observability/cockpit/concepts/#data-types) | ||
| - [Created](/observability/cockpit/how-to/create-token/) a Cockpit token in the same region as the logs data source | ||
| - A running Kubernetes cluster containing your application deployed | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [Created](/identity-and-access-management/iam/how-to/create-api-keys/) an API key and retrieved your API secret key | ||
|
|
||
| <Message type="important"> | ||
| - Sending logs for Scaleway resources or personal data using an external path is a billable feature. In addition, any data that you push yourself is billed, even if you send data from Scaleway products. Refer to the [product pricing](https://www.scaleway.com/en/pricing/?tags=available,managedservices-observability-cockpit) page for more information. | ||
| </Message> | ||
|
|
||
| ## Configure the Helm chart | ||
|
|
||
| Create a `values.yml` file to configure your Helm chart, using the example below. Make sure that you replace `$SCW_CLUSTER_NAME` with the name of your Scaleway Kubernetes cluster, `COCKPIT_CUSTOM_LOGS_DATASOURCE_URL` with the URL of your custom logs data source (you can find it under the "API URL" section in the [Data sources tab](https://console.scaleway.com/cockpit/dataSource) of the Scaleway console), and `$COCKPIT_TOKEN` with your Cockpit token. | ||
|
|
||
| ```yaml | ||
| cluster: | ||
| name: "$SCW_CLUSTER_NAME" | ||
| global: | ||
| scrape_interval: 60s | ||
| destinations: | ||
| - name: "my-cockpit-logs" | ||
| type: "loki" | ||
| protocol: "http" | ||
| logs: | ||
| enabled: true | ||
| url: "$COCKPIT_CUSTOM_LOGS_DATASOURCE_URL/loki/api/v1/push" ##You can find your logs URL in the **Data sources** tab of the Scaleway conseole under the "API URL" section of the relevant data source | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tenantId: "$COCKPIT_TOKEN" | ||
|
|
||
| metrics: | ||
| enabled: false | ||
| traces: | ||
| enabled: false | ||
| clusterEvents: | ||
| enabled: true | ||
| destinations: ["my-cockpit-logs"] | ||
| # -- Node logs. | ||
| nodeLogs: | ||
| enabled: true | ||
| destinations: ["my-cockpit-logs"] | ||
| # -- Pod logs. | ||
| podLogs: | ||
| enabled: true | ||
| destinations: ["my-cockpit-logs"] | ||
| volumeGatherSettings: | ||
| onlyGatherNewLogLines: true | ||
|
|
||
| # An Alloy instance for collecting log data. | ||
| alloy-logs: | ||
| enabled: true | ||
| logging: | ||
| level: info | ||
| format: logfmt | ||
| alloy-singleton: | ||
| enabled: true | ||
| ``` | ||
|
|
||
| <Message type="info"> | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The template above is for sending logs to your Cockpit. You can also configure it to send metrics to Cockpit using this Helm chart. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Refer to our dedicated doucumentation to [send metrics from your cluster to Cockpit](/observability/cockpit/how-to/send-metrics-froms-k8s-to-cockpit). | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Message> | ||
|
|
||
| ## Send Kubernetes logs using Helm chart | ||
|
|
||
| Once you have configured your `values.yml` file, you can use Helm to deploy the log-forwarding configuration to your Kubernetes cluster. Before you can install the Helm chart, ensure that your `kubectl` tool is properly connected to your Kubernetes cluster. `kubectl` is the command-line tool for interacting with Kubernetes clusters. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. [Connect](/containers/kubernetes/how-to/connect-cluster-kubectl/) `kubectl` to your Kubernetes cluster | ||
| 2. Run the command below to install the `k8s-monitoring` Helm chart: | ||
| ``` | ||
| helm install -f /your-path/to/values.yml your-log-ingester k8s-monitoring --version 1.6.16 | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| The `-f` flag specifies the path to your `values.yml` file, which contains the configuration for the Helm chart. Make sure that you replace `/your-path/to/values.yml` with the correct path where your `values.yml` file is stored. Make sure that you also replace `your-log-ingester` with the log ingester of your choice. In our configuration we are using `alloy-lm-ingester`. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Helm installs the `k8s-monitoring` chart, which includes the Alloy DaemonSet configured to collect logs from your Kubernetes cluster. | ||
| The DaemonSet ensures that a pod is running on each node in your cluster, which collects logs and forwards them to the specified Loki endpoint in your Cockpit. | ||
|
|
||
| 3. Optionally, check the status of the release to ensure it was installed: | ||
|
|
||
| ``` | ||
| helm list | ||
| ``` | ||
|
|
||
| ## Send Kubernetes logs using Helm chart with Terraform | ||
|
|
||
| You can also use Terraform to manage and deploy Helm charts, providing you with more automation and consistency to manage your Kubernetes resources. | ||
|
|
||
| 1. Create a `provider.tf` file and paste the following template to set up the Helm Terraform provider: | ||
| ```terraform | ||
| provider "helm" { | ||
| kubernetes { | ||
| host = your_k8s_cluster_host # The URL of your Kubernetes API server. | ||
| token = your_k8s_cluster_token # Authentication token to access the cluster. | ||
| cluster_ca_certificate = base64decode( | ||
| your_k8s_cluster_ca_certificate # The cluster's CA certificate. | ||
| ) | ||
| } | ||
| } | ||
| ``` | ||
| 2. Create a `maint.tf` file and paste the following template to create a Helm release resource. Make sure that you replace `/your-path/to/values.yml` with the actual path to your values file. | ||
| ``` | ||
| resource "helm_release" "log-ingester" { | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name = "your-log-ingester" | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| repository = "https://grafana.github.io/helm-charts" | ||
| chart = "k8s-monitoring" | ||
| version = "2.0.2" | ||
|
|
||
| namespace = "log-ingester" | ||
| create_namespace = true | ||
| values = [file("/your-path/to/values.yml")] | ||
| } | ||
| ``` | ||
| 3. Save your changes. | ||
| 4. Run `terraform init` to initialize your Terraform configuration and download any necessary providers. | ||
| 5. Run `terraform apply` to apply your configuration. | ||
| 5. Type `yes` when prompted to confirm the actions. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Explore your logs in Cockpit | ||
|
|
||
| 1. Click **Cockpit** in the Observability section of the Scaleway [console](https://console.scaleway.com/) side menu. The **Cockpit** overview page displays. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. Click **Open dashboards** to open your managed dashboards in Grafana. You are redirected to the Grafana website. | ||
| 3. Log in to Grafana using your [Grafana credentials](/observability/cockpit/how-to/retrieve-grafana-credentials/). | ||
| 4. Click the **Home** icon, then click **Explore**. | ||
| 5. Select your custom data source in the search drop-down on the upper left corner of your screen. | ||
| 6. In the **Labels filter** drop-down, select the `cluster` label and in the **Value** drop-down, select your cluster. | ||
| 7. Optionally, click the **Clock** icon on the top right corner of your screen and filter by time range. | ||
| 8. Click **Run query** to see your logs. An output similar to the following should display. | ||
|
|
||
| <Lightbox src="scaleway-cpt-k8s-terraform-logs.webp" alt="" /> | ||
177 changes: 177 additions & 0 deletions
177
observability/cockpit/how-to/send-metrics-from-k8s-to-cockpit.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| --- | ||
| meta: | ||
| title: How to send metrics from your Kubernetes cluster to your Cockpit | ||
| description: Learn how to send your pod metrics to your Cockpit using Scaleway's comprehensive guide. This tutorial covers sending Kubernetes pods metrics to Scaleway's Cockpit for centralized monitoring and analysis using Grafana, ensuring efficient monitoring and metrics analysis in your infrastructure. | ||
| content: | ||
| h1: How to send metrics from your Kubernetes cluster to your Cockpit | ||
| paragraph: Learn how to send your pod metrics to your Cockpit using Scaleway's comprehensive guide. This tutorial covers sending Kubernetes pods metrics to Scaleway's Cockpit for centralized monitoring and analysis using Grafana, ensuring efficient monitoring and metrics analysis in your infrastructure. | ||
| tags: kubernetes cockpit metrics observability monitoring cluster | ||
| categories: | ||
| - observability | ||
| dates: | ||
| validation: 2025/01/20 | ||
| posted: 2025/01/20 | ||
| --- | ||
|
|
||
|
|
||
| In this page we will show you how to send application metrics from your Kubernetes cluster to your Cockpit using either a Helm chart or deploying a Helm chart with [Terraform](https://www.terraform.io/). | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| We will use the [k8s-monitoring](https://artifacthub.io/packages/helm/grafana/k8s-monitoring/1.6.16) Helm Chart, which installs an Alloy Daemon set to export your Kubernetes cluster's metrics to your Cockpit. | ||
|
|
||
| <Macro id="requirements" /> | ||
|
|
||
| - A Scaleway account metricsged into the [console](https://console.scaleway.com) | ||
| - [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization | ||
| - [Created](/observability/cockpit/how-to/create-external-data-sources/) a custom external data source of the [metrics type](/observability/cockpit/concepts/#data-types) | ||
| - [Created](/observability/cockpit/how-to/create-token/) a Cockpit token in the same region as the metrics data source | ||
| - A running Kubernetes cluster containing your application deployed | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [Created](/identity-and-access-management/iam/how-to/create-api-keys/) an API key and retrieved your API secret key | ||
|
|
||
| <Message type="important"> | ||
| - Sending metrics for Scaleway resources or personal data using an external path is a billable feature. In addition, any data that you push yourself is billed, even if you send data from Scaleway products. Refer to the [product pricing](https://www.scaleway.com/en/pricing/?tags=available,managedservices-observability-cockpit) page for more information. | ||
| </Message> | ||
|
|
||
|
|
||
| ## Configure the Helm chart | ||
|
|
||
| Create a `values.yml` file to configure your Helm chart, using the example below. Make sure that you replace `$SCW_CLUSTER_NAME` with the name of your Scaleway Kubernetes cluster, `$COCKPIT_CUSTOM_METRICS_DATASOURCE_URL` with the URL of your custom metrics data source (you can find it under the "API URL" section in the [Data sources tab](https://console.scaleway.com/cockpit/dataSource) of the Scaleway console), and `$COCKPIT_TOKEN` with your Cockpit token. | ||
|
|
||
| ```yaml | ||
| cluster: | ||
| name: "$SCW_CLUSTER_NAME" | ||
| global: | ||
| scrape_interval: 60s | ||
| destinations: | ||
| - name: "my-cockpit-metrics" | ||
| type: "prometheus" | ||
| protocol: "http" | ||
| metrics: | ||
| enabled: true | ||
| url: "$COCKPIT_CUSTOM_METRICS_DATASOURCE_URL/api/v1/push" | ||
| tenantId: "$COCKPIT_TOKEN" | ||
|
|
||
| logs: | ||
| enabled: false | ||
| traces: | ||
| enabled: false | ||
|
|
||
| annotationAutodiscovery: | ||
| enabled: true | ||
| destinations: ["my-cockpit-metrics"] | ||
|
|
||
| alloy-metrics: | ||
| enabled: true | ||
| alloy-singleton: | ||
| enabled: true | ||
| ``` | ||
|
|
||
| <Message type="info"> | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The template above is for sending metrics to your Cockpit. You can also configure it to send logs to Cockpit using this Helm chart. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Refer to our dedicated doucumentation to [send logs from your cluster to Cockpit](/observability/cockpit/how-to/send-logs-from-k8s-to-cockpit) | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Message> | ||
|
|
||
| ## Add annotations for auto-discovery | ||
|
|
||
| Annotations in Kubernetes provide a way to attach metadata to your resources. For `k8s-monitoring`, these annotations signal which pods should be scraped for metrics, and what port to use. For the sake of this documentation, we are adding annotations to specify we want `k8s-monitoring` to scrape the pods from your deployment. Make sure that you replace $METRICS_PORT with the port where your application exposes Prometheus metrics. | ||
|
|
||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ### Kubernetes deployment template | ||
|
|
||
| ```yaml | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| ... | ||
| annotations: | ||
| "k8s.grafana.com/metrics.portNumber" = "$METRICS_PORT" | ||
| "k8s.grafana.com/scrape" = "true" | ||
| spec: | ||
| ... | ||
| ``` | ||
|
|
||
| ### Terraform deployment template | ||
|
|
||
| ```terraform | ||
| resource "kubernetes_deployment_v1" "your_application_deployment" { | ||
| ... | ||
| spec { | ||
| ... | ||
| template { | ||
| metadata { | ||
| ... | ||
| annotations = { | ||
| "k8s.grafana.com/metrics.portNumber" = "$METRICS_PORT" | ||
| "k8s.grafana.com/scrape" = "true" | ||
| } | ||
| } | ||
| ... | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Send Kubernetes metrics using Helm chart with Terraform | ||
|
|
||
| 1. Create a `provider.tf` file and paste the following template to set up the Helm Terraform provider: | ||
| ```terraform | ||
| provider "helm" { | ||
| kubernetes { | ||
| host = your_k8s_cluster_host # The URL of your Kubernetes API server. | ||
| token = your_k8s_cluster_token # Authentication token to access the cluster. | ||
| cluster_ca_certificate = base64decode( | ||
| your_k8s_cluster_ca_certificate # The cluster's CA certificate. | ||
| ) | ||
| } | ||
| } | ||
| ``` | ||
| 2. Create a `maint.tf` file and paste the following template to create a Helm release resource. Make sure that you replace `/your-path/to/values.yml` with the actual path to your values file. | ||
| ``` | ||
| resource "helm_release" "metrics-ingester" { | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name = "my-metrics-ingester" | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| repository = "https://grafana.github.io/helm-charts" | ||
| chart = "k8s-monitoring" | ||
| version = "2.0.2" | ||
|
|
||
| namespace = "metrics-ingester" | ||
| create_namespace = true | ||
| values = [file("/your-path/to/values.yml")] | ||
| } | ||
| ``` | ||
| 3. Save your changes. | ||
| 4. Run `terraform init` to initialize your Terraform configuration and download any necessary providers. | ||
| 5. Run `terraform apply` to apply your configuration. | ||
| 5. Type `yes` when prompted to confirm the actions. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Send Kubernetes metrics using Helm chart | ||
|
|
||
| Once you have configured your `values.yml` file, you can use Helm to deploy the metric-forwarding configuration to your Kubernetes cluster. Before you can install the Helm chart, ensure that your `kubectl` tool is properly connected to your Kubernetes cluster. `kubectl` is the command-line tool for interacting with Kubernetes clusters. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. [Connect](/containers/kubernetes/how-to/connect-cluster-kubectl/) `kubectl` to your Kubernetes cluster | ||
| 2. Run the command below to install the `k8s-monitoring` Helm chart: | ||
| ``` | ||
| helm install -f /your-path/to/values.yml your-metrics-ingester k8s-monitoring --version 1.6.16 | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| The `-f` flag specifies the path to your `values.yml` file, which contains the configuration for the Helm chart. Make sure that you replace `/your-path/to/values.yml` with the correct path where your `values.yml` file is stored. Make sure that you also replace `your-metrics-ingester` with the metric ingester of your choice. In our configuration we are using `alloy-lm-ingester`. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Helm installs the `k8s-monitoring` chart, which includes the Alloy DaemonSet configured to collect metrics from your Kubernetes cluster. | ||
| The DaemonSet ensures that a pod is running on each node in your cluster, which collects metrics and forwards them to the specified Prometheus endpoint in your Cockpit. | ||
|
|
||
| 3. Optionally, check the status of the release to ensure it was installed: | ||
|
|
||
| ``` | ||
| helm list | ||
| ``` | ||
|
|
||
|
|
||
| ## Explore your metrics in Cockpit | ||
|
|
||
| Now that your metrics are exported to your Cockpit, you can access and query them. | ||
|
|
||
| 1. Click **Cockpit** in the Observability section of the Scaleway [console](https://console.scaleway.com/) side menu. The **Cockpit** overview page displays. | ||
nerda-codes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. Click **Open dashboards** to open your managed dashboards in Grafana. You are redirected to the Grafana website. | ||
| 3. Log in to Grafana using your [Grafana credentials](/observability/cockpit/how-to/retrieve-grafana-credentials/). | ||
| 4. Click the **Home** icon, then click **Explore**. | ||
| 5. Select your custom data source in the search drop-down on the upper left corner of your screen. | ||
| 6. In the **Labels filter** drop-down, select the `cluster` label and in the **Value** drop-down, select your cluster. | ||
| 7. Optionally, click the **Clock** icon on the top right corner of your screen and filter by time range. | ||
| 8. Click **Run query** to see your metrics. An output similar to the following should display. | ||
| <Lightbox src="scaleway-cpt-k8s-terraform-metrics.webp" alt="" /> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.