Expose Operator metrics

Last validated:

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:

  1. Ensure that Prometheus operator including its custom resource definitions is installed.

  2. Apply ProxyClass that enables metrics and ServiceMonitor creation:

    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 be ingress_service, ingress_resource, connector, proxygroup, or peerrelay.
  • ts_proxy_parent_name: Name of the proxy's parent resource. That is, the name of the Ingress resource, Tailscale Service, Connector, ProxyGroup, or PeerRelay.
  • 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 Service named peerrelay-my-relay-metrics in the operator's namespace. It selects every replica and exposes port 9002, named metrics.
  • When serviceMonitor.enable is true, the operator creates a ServiceMonitor with the same name and namespace as the metrics Service. The ingested metrics have ts_proxy_type set to peerrelay and ts_proxy_parent_name set to my-relay. A PeerRelay is cluster-scoped, so its metrics have no ts_proxy_parent_namespace label.

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.