Add static endpoints to a cluster
Static endpoints are available to proxies in ProxyGroups in the Tailscale Kubernetes Operator v1.86 or later, and to Connectors in the Tailscale Kubernetes Operator v1.106 or later.
Standalone ingress and egress proxies do not support static endpoints. A standalone proxy is the dedicated proxy that the operator creates for a single Kubernetes Ingress or Service that does not use a ProxyGroup. The operator ignores spec.staticEndpoints in the ProxyClass of a standalone proxy and does not report an error. To use static endpoints with an Ingress or Service, use high availability ingress or high availability egress, which run on a ProxyGroup.
Tailscale uses various NAT traversal techniques to securely connect to other Tailscale nodes without manual intervention. Most of the time, you do not need to open any firewall ports for Tailscale. However, in some scenarios where NAT traversal is unsuccessful, Tailscale proxies deployed by the operator rely on a relayed connection, resulting in lower throughput and performance compared to direct connections. For example, NAT traversal can fail behind AWS NAT gateways, which are hard NATs.
In these scenarios, ProxyClass provides configuration to use Kubernetes NodePort services as additional endpoints for direct connections to ProxyGroups and Connectors. A tailnet device can use a static endpoint only if it can route traffic to the ExternalIP address of the Node, and firewalls permit inbound UDP traffic to the node port. If the ExternalIP address is a public IP address, tailnet devices on the internet can reach the endpoint. If it is a private IP address, only tailnet devices on networks that can route to it can reach the endpoint.
For each replica of a ProxyGroup or Connector that uses the ProxyClass, the operator does the following:
- Creates a NodePort
Servicenamed<resource-name>-<replica-index>-nodeportin the operator's namespace, which istailscaleby default. The<resource-name>value is the name of theProxyGrouporConnector, and<replica-index>is the zero-based replica number. - Allocates the node port of the
Servicefrom the port ranges in theProxyClass. - Configures the replica to advertise up to two static endpoints. Each endpoint is the
ExternalIPaddress of a selected KubernetesNodeand the node port of the replica.
The operator deletes the NodePort Service of a replica when you reduce the number of replicas, delete the ProxyGroup or Connector, or remove spec.staticEndpoints from the ProxyClass.
A ProxyGroup and a Connector with the same name use the same NodePort Service names. If both use static endpoints, give the ProxyGroup and the Connector different names.
Prerequisites
Before you configure static endpoints, make sure that the following conditions are true:
- At least one Kubernetes
Nodethat matches theProxyClassselector has anExternalIPaddress instatus.addresses. The operator advertises onlyExternalIPaddresses. If no matchingNodehas one, theProxyGrouporConnectordoes not become ready. Clusters without a cloud provider integration, such as many bare-metal clusters, often have noExternalIPaddresses. - Tailnet devices can route traffic to those
ExternalIPaddresses. - Firewalls permit inbound UDP traffic to those addresses on the ports in the
ProxyClassport ranges. For details, refer to configure firewall rules.
Configure firewall rules
The operator advertises a maximum of two static endpoints for each replica. To choose which Node addresses the operator advertises, configure the spec.staticEndpoints.nodePort.selector field in the ProxyClass resource. The selector only filters the advertised addresses. It does not restrict the NodePort Service to those nodes. If you do not set a selector, the operator can advertise the ExternalIP address of any Node.
To use static endpoints, configure inbound firewall rules that permit UDP traffic to the ExternalIP address of each selected Node on the ports in the port ranges of the ProxyClass. Each replica of every ProxyGroup and Connector that uses the ProxyClass requires one port. If no free port is left, the ProxyGroup or Connector does not become ready. Tailscale recommends configuring enough ports in the ProxyClass and on the firewall to avoid running out of ports as you add replicas.
Configure static endpoints
To configure static endpoints, complete the following steps:
-
Create a
ProxyClass.The configuration for static endpoints is part of the
ProxyClasscustom resource, underspec.staticEndpoints:apiVersion: tailscale.com/v1alpha1 kind: ProxyClass metadata: name: prod spec: staticEndpoints: nodePort: ports: - port: 31667 endPort: 31680 selector: kubernetes.io/os: linuxThe preceding example configures the
ProxyClassto use Kubernetes NodePort services for the static endpoints. ThenodePortconfiguration has the following fields:ports(Required): A list of port ranges for the NodePortServices. Each range has aportand an optionalendPort. The range contains every port fromportthroughendPort, including both values. A range withoutendPortcontains onlyport.selector(Optional): The labels of the Kubernetes nodes whoseExternalIPaddresses the operator advertises as static endpoints.
Each port range must meet the following conditions:
- When set,
endPortis equal to or greater thanport. - The range is within the node port range of the cluster, which is
30000-32767by default. - The range does not overlap with the other ranges in the
ProxyClassor with the port ranges of anotherProxyClass.
If the operator detects a port range that does not meet these conditions, the
ProxyClassdoes not become ready.Make sure the firewall rules permit inbound UDP traffic to these ports so the endpoints are reachable from other tailnet devices.
-
Reference the
ProxyClassfrom aProxyGroupor aConnector.To configure static endpoints for all replicas of a
ProxyGroup, set thespec.proxyClassfield of theProxyGroup:apiVersion: tailscale.com/v1alpha1 kind: ProxyGroup metadata: name: ingress spec: type: ingress proxyClass: prod replicas: 3To configure static endpoints for all replicas of a
Connector, set thespec.proxyClassfield of theConnector. The operator does not apply the defaultProxyClassto aConnector, so you must set this field:apiVersion: tailscale.com/v1alpha1 kind: Connector metadata: name: ts-pod-cidrs spec: proxyClass: prod replicas: 2 hostnamePrefix: ts-pod-cidrs subnetRouter: advertiseRoutes: - "10.40.0.0/14"After you apply these examples, the operator creates one NodePort
Servicefor each of the threeProxyGroupreplicas and the twoConnectorreplicas. To list them, run:kubectl get services -n tailscaleThe output includes lines similar to the following:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-0-nodeport NodePort 172.20.123.3 <none> 22918:31669/UDP 84m ingress-1-nodeport NodePort 172.20.163.230 <none> 22918:31668/UDP 84m ingress-2-nodeport NodePort 172.20.84.83 <none> 22918:31667/UDP 84m ts-pod-cidrs-0-nodeport NodePort 172.20.97.12 <none> 40531:31670/UDP 2m ts-pod-cidrs-1-nodeport NodePort 172.20.14.201 <none> 40531:31671/UDP 2m -
Check the static endpoints.
The operator reports the static endpoints of each replica in the
staticEndpointsfield of its entry instatus.devices. To list them for theConnector, run:kubectl get connector ts-pod-cidrs -o yamlThe
statussection of the output is similar to the following:status: devices: - hostname: ts-pod-cidrs-0.tails-scales.ts.net staticEndpoints: - 203.0.113.1:31670 - 203.0.113.2:31670 . . . - hostname: ts-pod-cidrs-1.tails-scales.ts.net staticEndpoints: - 203.0.113.1:31671 - 203.0.113.2:31671 . . .For the
ProxyGroup, run the following command. Thestatus.devicesfield of theProxyGrouphas the samestaticEndpointsfield for each replica:kubectl get proxygroup ingress -o yaml -
Test the connection.
From another tailnet device, use
tailscale pingto test for a direct connection to a replica.For the
Connector, ping a replica by its hostname:tailscale ping ts-pod-cidrs-0For the
ProxyGroup, create a testPodand aServicethat exposes thePodthrough a high-availability cluster ingress:apiVersion: v1 kind: Pod metadata: name: test namespace: default labels: app: test spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: test namespace: default annotations: tailscale.com/proxy-group: ingress spec: type: LoadBalancer loadBalancerClass: tailscale selector: app: test ports: - port: 80 targetPort: 80 protocol: TCPTo find the Tailscale
ServiceIP address that exposes thePodto the tailnet, run:kubectl get service -n defaultThe output is similar to the following:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE test LoadBalancer 172.20.50.164 100.64.1.2 80:31109/TCP 2m17sTest for a direct connection to the
Podin your tailnet by using the TailscaleServiceIP address:tailscale ping <external-ip>The following examples show the output for a
ProxyGroupreplica. The output for aConnectorreplica has the same format. If a direct connection is successful, the output is similar to the following:pong from ingress-0 (100.64.1.1) via 203.0.113.1:31669 in 91msIf a direct connection is unsuccessful, the output is similar to the following:
pong from ingress-0 (100.64.1.1) via DERP(nyc) in 90msIf you observe this output, make sure that the following conditions are true:
-
Inbound firewall rules are configured appropriately for traffic to flow to the correct Kubernetes nodes and port ranges, as configured in the
ProxyClass. -
Nodes that match
spec.staticEndpoints.nodePort.selectorhaveExternalIPaddresses instatus.addresses. -
For each replica, the
staticEndpointsfield in thestatus.devicesof theProxyGrouporConnectorcontains addresses that use a validExternalIPaddress and the node port of the NodePortServiceof that replica.
-