Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8s Exclude Namespaces #3678

Open
anengineerdude opened this issue Mar 2, 2025 · 8 comments
Open

K8s Exclude Namespaces #3678

anengineerdude opened this issue Mar 2, 2025 · 8 comments
Labels
enhancement New feature or request

Comments

@anengineerdude
Copy link

Describe the feature you would like to see

When running in K8s mode allow for excluding namespaces. This would support a list of namespaces that Dozzle should ignore and not monitor.

Describe how you would like to see this feature implemented

Environment variable for a list of namespaces or a comma seperated string. Example DOZZLE_EXCLUDE_NAMESPACES

Describe any alternatives you've considered

No response

@anengineerdude anengineerdude added the enhancement New feature or request label Mar 2, 2025
@amir20
Copy link
Owner

amir20 commented Mar 3, 2025

K8s API does not support namespace exclusion. However, you can use fieldSelector, which can be set to something like metadata.namespace!=excluded-namespace. I believe it would be better to support any field selector. Currently, only label selectors are supported. Supporting field selectors will require some effort. I need to consider the best way to configure this with environment variables and flags. I will keep this open.

Thank you.

@thioovoom
Copy link

hi @amir20 please help me how can I filter for only my label containers: Example I have these labels:
Labels: app.kubernetes.io/instance=app-api
app.kubernetes.io/name=app-api
pod-template-hash=794bf8xxxx
my setting:

  • name: DOZZLE_FILTER
    value: "name=app-fe,name=app-api"
    I also tried with:
  • name: DOZZLE_FILTER
    value: "label=app-fe,label=app-api"
    But it's not working, no container showed. If I dont use DOZZLE_FILTER all my containers showed.

@amir20
Copy link
Owner

amir20 commented Mar 6, 2025

Hi @thioovoom, I just tested this. The filter option should work similar to the -l flag when using kubectl get pods. It should work this way:

  1. I created a deployment with app=echo-deployment label.
  2. Tested with kubectl get pods -l=app=echo-deployment. It did work.
  3. Started Dozzle with DOZZLE_FILTER=app=echo-deployment and confirmed that worked too.

So for you, I would expect to do DOZZLE_FILTER=app.kubernetes.io/instance=app-api.

If it doesn't work, enable debug and open a new issue so we can investigate.

@ngoisaoquay
Copy link

hi @amir20 thank you so much for your response, I able to filter my app as you mentioned above DOZZLE_FILTER=app.kubernetes.io/instance=app-api, but when I add more label in filter, it's not working, this is my config:

  • name: DOZZLE_FILTER
    value: "app.kubernetes.io/name=common-api,app.kubernetes.io/name=auth-api"
    I can filter multi label with kubectl command:
    kubectl get pods -n dev -l "app.kubernetes.io/name in (common-api, auth-api)"
    I also try add but got error:
  • name: DOZZLE_FILTER
    value: "app.kubernetes.io/name in (common-api, auth-api)"
    Usage: dozzle [--addr ADDR] [--base BASE] [--hostname HOSTNAME] [--level LEVEL] [--auth-provider AUTH-PROVIDER] [--auth-ttl AUTH-TTL] [--auth-header-user AUTH-HEADER-USER] [--auth-header-email AUTH-HEADER-EMAIL] [--auth-header-name AUTH-HEADER-NAME] [--auth-header-filter AUTH-HEADER-FILTER] [--enable-actions] [--filter FILTER] [--remote-host REMOTE-HOST] [--remote-agent REMOTE-AGENT] [--no-analytics] [--mode MODE] [--timeout TIMEOUT] [--namespace NAMESPACE] []
    error: each filter should be of the form key=value
    So please show me how can i add multi filter for multi labels name.
    And another question, I have many name spaces but I only want to show 2 name spaces, it đi not work.
  • name: DOZZLE_NAMESPACE
    value: "dev,staging"
    It only work with dev or staging.

@amir20
Copy link
Owner

amir20 commented Mar 7, 2025

@ngoisaoquay Dozzle only supports comma-separated filters, which translate to AND. In your example, it attempts to execute name=common-api AND name=auth-api, which obviously won't work.

I suggest creating a new label, such as dozzle=enabled, and filtering based on that.

The approach for namespaces is similar.

In the future, I might implement sets like name in (common, auth). However, the filters would need to change, and since Docker doesn't support sets, it would require a specific set of flags for Kubernetes.

I am tracking the usage of Dozzle with K8s. It is still very small. Hope to see more traction so that I can spend more time.

@ngoisaoquay
Copy link

Thank you so much @amir20 I can filter container with dozzle=enabled as you mentioned.

@anengineerdude
Copy link
Author

Thanks @amir20 I think you outlined some other good options here, espically if the k8s API makes this difficult.

The only other thought I had was the opposite, rather than excluding namespaces, at least allow a list of included namespaces. But I also recognize that using labels could do the same thing, so low priority or could close this issue.

@amir20
Copy link
Owner

amir20 commented Mar 12, 2025

Yes, @anengineerdude. I believe it's worth exploring how Kubernetes handles labels and filters. Docker's labels are quite limited, and currently, Dozzle supports Docker, Podman, Swarm, and Kubernetes. I need to consider carefully how to build specific features that would enable filtering exclusively for Kubernetes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants