Kubernetes.deployment.name missing after metricbeat upgrade

Hi,
we recently updated our Kubernetes version to 1.30.10 (running in AKS) and noticed that metricbeat was starting to get authentication issues after 1 hour.

I found this issue metricbeat runs happily for a while and then starts getting 401 errors when fetching metrics · Issue #42307 · elastic/beats · GitHub and after upgrading metricbeat to 8.15.4 the issue went away.

After this update, however, we noticed that the field kubernetes.deployment.name was no longer being populated in most of our metrics.

I found this issue Fix Metricbeat k8s metadata sometimes not being present at startup by swiatekm · Pull Request #41216 · elastic/beats · GitHub which was included in the release notes for 8.15.4, so I naturally thought this was the issue.

But this did not help - further digging showed that kubernetes.deployment.name was indeed being set for the state_* metrics (like state_deployment), but not in e.g. container or pod metrics.

I have read up on the add_kubernetes_metadata processor, but even with this enabled the field does not get set. And the more I read about this metadata, the less I understand how this could work in the 8.5.1 version we were using before, since we did not use that processor at all.

I have compared the fields in the metricset for 8.5.1 Kubernetes pod metricset | Metricbeat Reference [8.5] | Elastic with the version we upgraded to and kubernetes.deployment.name is not a part of that set. So I'm also really curious were this field get set?

Are there any permission changes that could have caused this? Seems a bit unlikely since we do get the field on all the state_* metrics.

Any input/suggestions would be most welcome.

So after some more digging I discovered that the kubernetes.deployment.name had been intentionally removed in Beats version 8.11.0 to fix this issue: [8.11] Updating elastic-autodiscovery version to 0.6.4 by gizas · Pull Request #36879 · elastic/beats · GitHub

But I cannot for the life of me understand how to configure metricbeat to get these fields back. Like I wrote above, I've tried using the add_kubernetes_metadata processor, but using debug logging in metricbeat I can see that it doesn't seem to be taken into account:
Skipping add_kubernetes_metadata processor as kubernetes metadata already exist

How should metricbeat be configured to get these fields back?