How to override the logging configMap to restrict logging to specific namespaces.

As a cluster administrator, you may have a need to limit, or restrict, logging activities only to certain namespaces. Kommander allows you to do this by creating an override configMap that modifies the logging configuration created in the Create AppDeployment for Workspace Logging procedure.

Prerequisites

Create and use the Override Entries

To create and use the override configMap entries, follow these steps:

  1. Execute the following command to get the namespace of your workspace:

    dkp get workspaces
    CODE

    And copy the value under the NAMESPACE column for your workspace.

  2. Set the WORKSPACE_NAMESPACE variable to the namespace copied in the previous step:

    export WORKSPACE_NAMESPACE=<WORKSPACE_NAMESPACE>
    CODE
  3. Identify one or more namespaces to which you want to restrict logging.

  4. Create a file named logging-operator-logging-overrides.yaml and paste the following YAML code into it to create the overrides configMap:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: logging-operator-logging-overrides
      namespace: ${WORKSPACE_NAMESPACE}
    data:
      values.yaml: |
        ---
        clusterFlows:
        - name: cluster-containers
          spec:
            globalOutputRefs:
            - loki
            match:
            - exclude:
                namespaces:
                - <your-namespace>
                - <your-other-namespace>
    CODE
  5. Add the relevant namespace values for metadata.namespace and the clusterFlows[0].spec.match[0].exclude.namespaces values at the end of the file, and save the file.

  6. Use the following command to apply the YAML file:

    kubectl apply -f logging-operator-logging-overrides.yaml
    CODE
  7. Edit the logging-operator AppDeployment to set the value of spec.configOverrides.name to logging-operator-logging-overrides.
    (Refer to Deploy an application with a custom configuration for more information)

    dkp edit appdeployment -n ${WORKSPACE_NAMESPACE} logging-operator
    CODE

    After your editing is complete, the AppDeployment resembles this example:

    apiVersion: apps.kommander.d2iq.io/v1alpha3
    kind: AppDeployment
    metadata:
      name: logging-operator
      namespace: ${WORKSPACE_NAMESPACE}
    spec:
      appRef:
        name: logging-operator-3.17.7
        kind: ClusterApp
      configOverrides:
        name: logging-operator-logging-overrides
    CODE
  8. Perform actions that generate log data, both in the specified namespaces and the namespaces you mean to exclude.

  9. Verify that the log data contains only the data you expected to receive.