networkPolicies.restrictInternalTraffic is blocking also Metrics scrape endpoint #13732
Replies: 2 comments 1 reply
|
This is the chart working as written, not a scrape misconfiguration on your side. The
{{- if .Values.networkPolicies.restrictInternalTraffic }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: longhorn-manager
namespace: {{ include "release_namespace" . }}
spec:
podSelector:
matchLabels:
app: longhorn-manager
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: longhorn-manager
- podSelector:
matchLabels:
app: longhorn-ui
- podSelector:
matchLabels:
app: longhorn-csi-plugin
- podSelector:
matchLabels:
longhorn.io/managed-by: longhorn-manager
matchExpressions:
- { key: recurring-job.longhorn.io, operator: Exists }
- podSelector:
matchExpressions:
- { key: longhorn.io/job-task, operator: Exists }
- podSelector:
matchLabels:
app: longhorn-driver-deployer
{{- end }}Three properties of that rule make it fatal for scraping:
One precondition: these resources only bite where your CNI actually enforces NetworkPolicy. Longhorn says so explicitly — "These policies are enforced only when the cluster has a network plugin that supports and enforces Kubernetes And 9500 is unambiguously the metrics port. In r.Methods("GET").Path("/metrics").Handler(registry.Handler())That router is served at What actually changed under youThe policy body has not changed since v1.12.0 — only its gate did. At v1.12.0 line 1 reads So on a policy-enforcing CNI, a plain 1.12.1 install with You do not need to turn it offNetworkPolicies are additive — Longhorn's own docs state it: "Network policies are additive, and when both the source and destination are isolated by NetworkPolicies, a connection must be permitted by both the source's egress policy and the destination's ingress policy" ( apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: longhorn-manager-allow-metrics
namespace: longhorn-system
spec:
podSelector:
matchLabels:
app: longhorn-manager
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: cattle-monitoring-system # your Prometheus namespace
podSelector:
matchLabels:
app.kubernetes.io/name: prometheus # tighten to your actual Prometheus pod labels
ports:
- protocol: TCP
port: 9500The You can ship it with the release rather than managing it out of band, via extraObjects:
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: longhorn-manager-allow-metrics
namespace: longhorn-system
spec:
podSelector:
matchLabels:
app: longhorn-manager
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: cattle-monitoring-system
podSelector:
matchLabels:
app.kubernetes.io/name: prometheus
ports:
- protocol: TCP
port: 9500That way it survives Note this only re-opens 9500 from the one namespace; it does not weaken any of the other five internal policies, which is what One thing that looks like it should help but does not: the manager pods also carry If your Prometheus runs with Worth filingThere is a real docs gap. The networking reference's longhorn-manager ingress matrix ( #12505 hit the same wall in January ("[BUG] No network policy to allow prometheus to scap metrics on RKE2") but with |
Uh oh!
There was an error while loading. Please reload this page.
Now
networkPolicies.restrictInternalTraffic=trueis implemented.Prometheus metrics end point will not work.
Setting to false resolves this.
Is this how it have to be done?
All reactions