Skip to content

Commit 3a5861c

Browse files
authored
feat(cockpit-k8s): review & test néda
1 parent cace6a6 commit 3a5861c

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

observability/cockpit/how-to/send-log-from-k8s-to-cockpit.mdx

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ tags: kubernetes cockpit logs observability monitoring cluster
99
categories:
1010
- observability
1111
dates:
12-
validation: 2025/01/03
13-
posted: 2025/01/03
12+
validation: 2025/01/20
13+
posted: 2025/01/20
1414
---
1515

16-
This page shows you how to send application logs created in a Kubernetes cluster to your Cockpit either by using a Helm chart or by deploying a Helm chart with [Terraform](https://www.terraform.io/).
16+
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/).
1717

18-
In this example, we use [k8s-monitoring](https://artifacthub.io/packages/helm/grafana/k8s-monitoring/1.6.16) which installs an Alloy Daemon set to your Kubernetes cluster to export logs to your Cockpit.
18+
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.
1919

2020
<Macro id="requirements" />
2121

2222
- A Scaleway account logged into the [console](https://console.scaleway.com)
2323
- [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/) a custom external data source
24+
- [Created](/observability/cockpit/how-to/create-external-data-sources/) a custom external data source of the [logs type](/observability/cockpit/concepts/#data-types)
2525
- [Created](/observability/cockpit/how-to/create-token/) a Cockpit token for the same region as the data source
2626
- A running Kubernetes cluster containing your application deployed
2727
- [Created](/identity-and-access-management/iam/how-to/create-api-keys/) an API key and retrieved your API secret key
@@ -32,7 +32,7 @@ In this example, we use [k8s-monitoring](https://artifacthub.io/packages/helm/gr
3232

3333
## Configure the Helm chart
3434

35-
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_DATASOURCE_HOST` with the hostname of your custom endpoint, and `$COCKPIT_TOKEN` with your Cockpit token.
35+
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_DATASOURCE_HOST` with the URL of your custom 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.
3636

3737
```yaml
3838
cluster:
@@ -45,7 +45,7 @@ destinations:
4545
protocol: "http"
4646
logs:
4747
enabled: true
48-
url: "$COCKPIT_CUSTOM_DATASOURCE_HOST/loki/api/v1/push"
48+
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
4949
tenantId: "$COCKPIT_TOKEN"
5050

5151
metrics:
@@ -77,37 +77,51 @@ alloy-singleton:
7777
```
7878
7979
<Message type="info">
80-
The template above is only an example to send logs to your Cockpit. You can also send metrics to Cockpit using this Helm chart.
81-
You can check our guide to [send metrics from your cluster to Cockpit](// ADD LINK TO METRICS TUTO)
80+
The template above is for sending logs to your Cockpit. You can also configure it to send metrics to Cockpit using this Helm chart.
81+
Refer to our dedicated doucumentation to [send metrics from your cluster to Cockpit](/observability/cockpit/how-to/send-metrics-froms-k8s-to-cockpit).
8282
</Message>
8383
84-
## Send Kubernetes logs to your Cockpit using Helm chart
84+
## Send Kubernetes logs using Helm chart
8585
86-
1. Connect your kubectl to your Kubernetes cluster
87-
2. Run the following command to apply your Helm chart with the `values.yml` file:
86+
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.
87+
88+
1. [Connect](/containers/kubernetes/how-to/connect-cluster-kubectl/) `kubectl` to your Kubernetes cluster
89+
2. Run the command below to install the `k8s-monitoring` Helm chart:
8890
```
89-
helm install -f /your-path/to/values.yml my-log-ingester k8s-monitoring --version 1.6.16
91+
helm install -f /your-path/to/values.yml your-log-ingester k8s-monitoring --version 1.6.16
9092
```
91-
Make sure to replace `-f` flag with the correct path to your `values.yml` file.
93+
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`.
94+
95+
Helm installs the `k8s-monitoring` chart, which includes the Alloy DaemonSet configured to collect logs from your Kubernetes cluster.
96+
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.
97+
98+
3. Optionally, check the status of the release to ensure it was installed:
9299

93-
## Send Kubernetes logs to your Cockpit using Helm chart with Terraform
100+
```
101+
helm list
102+
```
103+
You should see a list of all the Helm releases in your cluster, including `my-log-ingester`.
94104

95-
1. Set up the Helm Terraform provider:
105+
## Send Kubernetes logs using Helm chart with Terraform
106+
107+
You can also use Terraform to manage and deploy Helm charts, providing you with more automation and consistency to manage your Kubernetes resources.
108+
109+
1. Create a `provider.tf` file and paste the following template to set up the Helm Terraform provider:
96110
```terraform
97111
provider "helm" {
98112
kubernetes {
99-
host = your_k8s_cluster_host
100-
token = your_k8s_cluster_token
113+
host = your_k8s_cluster_host # The URL of your Kubernetes API server.
114+
token = your_k8s_cluster_token # Authentication token to access the cluster.
101115
cluster_ca_certificate = base64decode(
102-
your_k8s_cluster_ca_certificate
116+
your_k8s_cluster_ca_certificate # The cluster's CA certificate, base64 encoded.
103117
)
104118
}
105119
}
106120
```
107-
2. Create a Helm release resource with the path to your `values.yml`:
121+
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.
108122
```
109123
resource "helm_release" "log-ingester" {
110-
name = "my-log-ingester"
124+
name = "your-log-ingester"
111125
repository = "https://grafana.github.io/helm-charts"
112126
chart = "k8s-monitoring"
113127
version = "2.0.2"
@@ -117,13 +131,20 @@ You can check our guide to [send metrics from your cluster to Cockpit](// ADD LI
117131
values = [file("/your-path/to/values.yml")]
118132
}
119133
```
120-
3. Run `terraform apply` to apply the new Terraform configuration.
134+
3. Save your changes.
135+
4. Run `terraform init` to initialize your Terraform configuration and download any necessary providers.
136+
5. Run `terraform apply` to apply your configuration.
137+
5. Type `yes` when prompted to confirm the actions.
121138
122139
## Explore your logs in Cockpit
123140
124-
Now that your logs are exported to your Cockpit, you can access and query them.
125-
126-
1. Click **Cockpit** in the Observability section of the [console](https://console.scaleway.com/) side menu. The **Cockpit** overview page displays.
141+
1. Click **Cockpit** in the Observability section of the Scaleway [console](https://console.scaleway.com/) side menu. The **Cockpit** overview page displays.
127142
2. Click **Open dashboards** to open your managed dashboards in Grafana. You are redirected to the Grafana website.
128-
3. Click the **Home** icon > **Explore**. Select your custom data source in the upper left corner.
129-
4. Filter the query by only searching for the label `cluster` with the value corresponding to your cluster name and your logs should display.
143+
3. Log in to Grafana using your [Grafana credentials](/observability/cockpit/how-to/retrieve-grafana-credentials/).
144+
4. Click the **Home** icon, then click **Explore**.
145+
5. Select your custom data source in the search drop-down on the upper left corner of your screen.
146+
6. In the **Labels filter** drop-down, select the `cluster` label and in the **Value** drop-down, select your cluster.
147+
7. Optionally, click the **Clock** icon on the top right corner of your screen and filter by time range.
148+
8. Click **Run query** to see your logs. An output similar to the following should display.
149+
150+
<Lightbox src="scaleway-cpt-k8s-terraform-logs.webp" alt="" />

0 commit comments

Comments
 (0)