How to configure audit collection for imported standard Kubernetes clusters?
Scenario Description
After a standard Kubernetes cluster is imported into the platform, you must enable Kubernetes API server audit logging on the cluster before the platform can collect audit data from that cluster.
This document applies to standard Kubernetes clusters whose control plane nodes are managed by you, such as kubeadm-based clusters. It does not apply to managed cloud Kubernetes clusters where you cannot log in to or modify control plane nodes.
Prerequisites
- The standard Kubernetes cluster has already been imported into the platform.
- You can log in to every control plane node in the cluster.
- The cluster uses the standard kubeadm-style API server static Pod manifest path:
/etc/kubernetes/manifests/kube-apiserver.yaml.
Procedure
-
Create a local
policy.yamlfile for the audit policy.Set
apiVersionaccording to the Kubernetes version:- Kubernetes earlier than 1.24:
audit.k8s.io/v1beta1 - Kubernetes 1.24 and later:
audit.k8s.io/v1
Use the following content:
TIPIf the cluster version is earlier than 1.24, change only the
apiVersionfield toaudit.k8s.io/v1beta1. The rest of the policy content stays the same. - Kubernetes earlier than 1.24:
-
Upload
policy.yamlto/etc/kubernetes/audit/on every control plane node.WARNING- If the cluster has multiple control plane nodes, upload the file to every node.
- Create the directory manually if it does not exist:
/etc/kubernetes/audit/
-
Update
/etc/kubernetes/manifests/kube-apiserver.yamlon every control plane node.Add or update the following audit-related flags in
spec.containers[].command:Example:
-
Add the audit directory mount configuration to the same
kube-apiserver.yamlfile.Add the following item under
spec.containers[].volumeMounts:Add the following item under
spec.volumes:WARNING- Update the manifest on every control plane node when the cluster has multiple control plane nodes.
- The
volumeMounts[].namevalue must match the correspondingvolumes[].namevalue. - Do not change the mount path
/etc/kubernetes/audit.
-
Save the file and verify that the configuration takes effect.
Check whether
/etc/kubernetes/audit/audit.logis generated on each control plane node. If the file exists and contains audit records, the configuration is effective.