Expose Operator metrics
When specified for a resource, the following ProxyClass definition enables client metrics at the path /metrics on a container port named "metrics":
apiVersion: tailscale.com/v1alpha1
kind: ProxyClass
metadata:
name: prod
spec:
metrics:
enable: true
The operator also creates a metrics Service for the proxy in the operator's namespace that also exposes metrics at /metrics on a port named "metrics".
Prometheus ServiceMonitor
The Kubernetes operator can also create a Prometheus ServiceMonitor for proxy resources.
To enable it:
-
Ensure that Prometheus operator including its custom resource definitions is installed.
-
Apply
ProxyClassthat enables metrics andServiceMonitorcreation:apiVersion: tailscale.com/v1alpha1 kind: ProxyClass metadata: name: prod spec: metrics: enable: true serviceMonitor: enable: true
The ingested metrics have labels that identify the proxy to which the ProxyClass was applied:
ts_proxy_type: Type of the proxy. Values can beingress_service,ingress_resource,connector,proxygroup, orpeerrelay.ts_proxy_parent_name: Name of the proxy's parent resource. That is, the name of theIngressresource, TailscaleService,Connector,ProxyGroup, orPeerRelay.ts_proxy_parent_namespace: Namespace of the proxy's parent resource. This only applies to namespaced resources.
PeerRelay metrics
In Tailscale v1.106 or later, the operator applies the metrics settings of a ProxyClass to each PeerRelay that references it. The operator doesn't apply the default ProxyClass to a PeerRelay. Set spec.proxyClass on each PeerRelay that needs one. For example, the following manifests enable metrics and ServiceMonitor creation for a PeerRelay named my-relay:
apiVersion: tailscale.com/v1alpha1
kind: ProxyClass
metadata:
name: relay-metrics
spec:
metrics:
enable: true
serviceMonitor:
enable: true
---
apiVersion: tailscale.com/v1alpha1
kind: PeerRelay
metadata:
name: my-relay
spec:
replicas: 1
proxyClass: relay-metrics
This configuration has the following effects:
- Each replica serves metrics at
<pod-ip>:9002/metrics. - The operator creates a metrics
Servicenamedpeerrelay-my-relay-metricsin the operator's namespace. It selects every replica and exposes port 9002, namedmetrics. - When
serviceMonitor.enableistrue, the operator creates aServiceMonitorwith the same name and namespace as the metricsService. The ingested metrics havets_proxy_typeset topeerrelayandts_proxy_parent_nameset tomy-relay. APeerRelayis cluster-scoped, so its metrics have nots_proxy_parent_namespacelabel.
The metrics include the peer relay server metrics, such as tailscaled_peer_relay_forwarded_bytes_total.
If you set metrics.enable to false or remove spec.proxyClass from the PeerRelay, the operator removes the metrics Service and the ServiceMonitor. Turning metrics.enable on or off, or removing spec.proxyClass, restarts the peer relay pods, which briefly interrupts relay traffic. Changing only the serviceMonitor settings doesn't restart them. If you set serviceMonitor.enable to false and keep metrics.enable set to true, the operator removes the ServiceMonitor and keeps the metrics Service.
A ProxyClass that enables serviceMonitor isn't ready until you install the Prometheus operator's ServiceMonitor custom resource definition. Until then, the operator doesn't create or update resources for the PeerRelay, which reports PeerRelayReady as False with the reason ProxyClassNotReady.
The operator doesn't apply the ProxyClass setting spec.statefulSet.pod.tailscaleContainer.debug to a PeerRelay, so peer relay pods don't serve debug endpoints.