|
| 1 | +--- |
| 2 | +meta: |
| 3 | + title: How to send logs from your Kubernetes cluster to your Cockpit |
| 4 | + 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. |
| 5 | +content: |
| 6 | + h1: How to send logs from your Kubernetes cluster to your Cockpit |
| 7 | + 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. |
| 8 | +tags: kubernetes cockpit logs observability monitoring cluster |
| 9 | +categories: |
| 10 | + - observability |
| 11 | +dates: |
| 12 | + validation: TBD |
| 13 | + posted: TBD |
| 14 | +--- |
| 15 | + |
| 16 | +This page shows you how to send your application logs created in a Kubernetes cluster to your Cockpit either by using a Helm Chart or by deploying this Helm chart with Terraform. |
| 17 | + |
| 18 | +In this example, we use [k8s-monitoring](https://artifacthub.io/packages/helm/grafana/k8s-monitoring/1.6.16) which install an Alloy Daemon set to your Kubernetes Cluster to export logs to your Cockpit. |
| 19 | + |
| 20 | +<Macro id="requirements" /> |
| 21 | + |
| 22 | + - A Scaleway account logged into the [console](https://console.scaleway.com) |
| 23 | + - [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 |
| 24 | + - [Created](/observability/cockpit/how-to/create-external-data-sources/) an custom external data source |
| 25 | + - [Created](/observability/cockpit/how-to/create-token/) a Cockpit Token for the same region as the data source |
| 26 | + - A running Kubernetes Cluster containing your application deployed |
| 27 | + - For Terraform : [Created](/identity-and-access-management/iam/how-to/create-api-keys/) an API key and retrieved your API secret key |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +<Message type="important"> |
| 32 | + - 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) for more information. |
| 33 | +<Message/> |
| 34 | + |
| 35 | +## Configure the Helm chart |
| 36 | + |
| 37 | +Create a `values.yml` file to configure your Helm chart, here is an example: |
| 38 | + |
| 39 | +<Message type="Note"> |
| 40 | + Do not forget to replace: |
| 41 | + - `$SCW_CLUSTER_NAME` by the name of your Scaleway Cluster |
| 42 | + - `$COCKPIT_CUSTOM_DATASOURCE_HOST` by the hostname of your custom endpoint (do not include the `/loki/api/v1/push` ) |
| 43 | + - `$COCKPIT_TOKEN` by your Cockpit Token |
| 44 | +<Message/> |
| 45 | + |
| 46 | +```yaml |
| 47 | +cluster: |
| 48 | + name: "$SCW_CLUSTER_NAME" |
| 49 | +externalServices: |
| 50 | + loki: |
| 51 | + host: "$COCKPIT_CUSTOM_DATASOURCE_HOST" |
| 52 | + tenantId: "$COCKPIT_TOKEN" |
| 53 | + authMode: none |
| 54 | + externalLabels: { |
| 55 | + cluster: "$SCW_CLUSTER_NAME" |
| 56 | + } |
| 57 | + |
| 58 | +logs: |
| 59 | + enabled: true |
| 60 | + pod_logs: |
| 61 | + enabled: true |
| 62 | + discovery: "all" |
| 63 | + annotation: "cockpit.scw.cloud/logs.autogather" |
| 64 | + # -- Only capture logs from pods in these namespaces (`[]` means all namespaces). |
| 65 | + namespaces: [] |
| 66 | + # -- Do not capture logs from any pods in these namespaces. |
| 67 | + excludeNamespaces: [] |
| 68 | + |
| 69 | +metrics: |
| 70 | + enabled: false |
| 71 | +kube-state-metrics: |
| 72 | + enabled: false |
| 73 | +prometheus-node-exporter: |
| 74 | + enabled: false |
| 75 | +prometheus-operator-crds: |
| 76 | + enabled: false |
| 77 | +opencost: |
| 78 | + enabled: false |
| 79 | + |
| 80 | +alloy: |
| 81 | + logging: |
| 82 | + level: info |
| 83 | + format: logfmt |
| 84 | +alloy-events: |
| 85 | + logging: |
| 86 | + level: info |
| 87 | + format: logfmt |
| 88 | +alloy-logs: |
| 89 | + logging: |
| 90 | + # -- Level at which Alloy log lines should be written. |
| 91 | + level: info |
| 92 | + # -- Format to use for writing Alloy log lines. |
| 93 | + format: logfmt |
| 94 | +``` |
| 95 | +
|
| 96 | +<Message type="info"> |
| 97 | +- Note that this is only an example to send logs to your cockpit, you can also send metrics to cockpit using this Helm chart |
| 98 | +</Message> |
| 99 | +
|
| 100 | +## Send Kubernetes logs to your Cockpit using Helm chart |
| 101 | +
|
| 102 | +1. Connect your kubectl to your Scaleway Cluster |
| 103 | +2. Apply your Helm chart with the `values.yml` file by running |
| 104 | + ``` |
| 105 | + helm install -f /your-path/to/values.yml my-log-ingester k8s-monitoring --version 1.6.16 |
| 106 | + ``` |
| 107 | + Do not forget to change the -f flag with the correct path to your `values.yml` file |
| 108 | +
|
| 109 | +## Send Kubernetes logs to your Cockpit using Helm chart with Terraform |
| 110 | +
|
| 111 | +1. Set up the Helm Terraform provider |
| 112 | + ```terraform |
| 113 | + provider "helm" { |
| 114 | + kubernetes { |
| 115 | + host = your_k8s_cluster_host |
| 116 | + token = your_k8s_cluster_token |
| 117 | + cluster_ca_certificate = base64decode( |
| 118 | + your_k8s_cluster_ca_certificate |
| 119 | + ) |
| 120 | + } |
| 121 | + } |
| 122 | + ``` |
| 123 | +2. Create a Helm release ressource with the path to your `values.yml` |
| 124 | + ``` |
| 125 | + resource "helm_release" "log-ingester" { |
| 126 | + name = "my-log-ingester" |
| 127 | + repository = "https://grafana.github.io/helm-charts" |
| 128 | + chart = "k8s-monitoring" |
| 129 | + version = "1.6.16" |
| 130 | +
|
| 131 | + namespace = "log-ingester" |
| 132 | + create_namespace = true |
| 133 | + values = [file("/your-path/to/values.yml")] |
| 134 | + } |
| 135 | + ``` |
| 136 | +3. Apply the new terraform configuration with `terraform apply` |
| 137 | + |
| 138 | +## Explore your logs |
| 139 | + |
| 140 | +Now that your logs are exported to your Cockpit, you can access and query them. |
| 141 | + |
| 142 | +1. Open your Cockpit Dashboard |
| 143 | +2. Click the **Home** icon > **Explore**. Select your custom data source in the upper left corner. |
| 144 | +3. Filter the query by only searching for the label `cluster` with the value corresponding to your cluster name and your log should display |
0 commit comments