# Read control-plane logs

Choose which control-plane logs are collected, and read the Kubernetes audit log and the API server, authenticator, controller manager and scheduler logs.

Replace _my-cluster_ with your cluster's name or id. Logs are kept 7 days.

| Type                | What                                                                                                                                                             | Default |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `audit`             | The Kubernetes audit log: every write, every refusal and every request by a person or a workload. Successful reads by the cluster's own components are left out. | on      |
| `api`               | kube-apiserver                                                                                                                                                   | off     |
| `authenticator`     | kube-apiserver's authentication                                                                                                                                  | off     |
| `controllerManager` | kube-controller-manager                                                                                                                                          | off     |
| `scheduler`         | kube-scheduler                                                                                                                                                   | off     |

## Prerequisites

- Permission for `eks:GetClusterLogs` on the cluster to read them (without it the **Logs** tab shows
  a refusal); `eks:UpdateClusterConfig` to choose the types.
- In the console, also `eks:DescribeCluster` to open the cluster.

## Choose the log types

**Console**
1. Open **Kubernetes**, open the cluster, then choose **Logs**.
2. Under **Collected log types**, turn each type on or off. Each switch is saved at once.

**CLI**
```sh
dcloud eks clusters update my-cluster --logging '{"types":["audit","api"]}'
```

**API**
```http
PATCH /eks/api/clusters/my-cluster
{ "logging": { "types": ["audit", "api"] } }
```

**Terraform**
```hcl
resource "dcloud_eks_cluster" "main" {
  name    = "my-cluster"
  logging = jsonencode({ types = ["audit", "api"] })
}
```

The list replaces the types as a whole; `[]` collects none. Only types turned on are collected.

## Read the logs

**Console**
1. On the **Logs** tab, under **Log lines**, choose the type (or **All types**) and the time window.
2. (Optional) Enter text the lines must contain.

The window is **Last hour** at first; the console shows up to 500 lines, newest first, and refreshes
every 15 seconds. Choose a line to see it in full; an audit line is summarized as who did what to
which object.

**CLI**
```sh
dcloud eks clusters logs my-cluster --type audit --contains delete
```

**API**
```http
GET /eks/api/clusters/my-cluster/logs?type=audit&contains=delete
```

**Terraform:** not available. Reading logs is not a resource.

In the CLI and the API, without `since` the hour before `until` (default: now) is returned; lines
come newest first, 200 by default (`limit`, at most 1000). `contains` ignores case. Without
`eks:GetClusterLogs` the answer is `403`.

## Related

- [Monitoring a cluster](monitoring.md)
- `eks.clusters.logs` · `dcloud eks clusters logs`
