k8s_cross

package module
v0.1.4-proto Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2025 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

k8s_cross

Name

k8s_cross - Kubernetes cross-cluster DNS resolution plugin.

Description

The k8s_cross plugin provides cross-cluster service discovery for Kubernetes using the Multi-Cluster Services API (KEP-1645) standard. It integrates with Headscale to enable DNS resolution for services across multiple Kubernetes clusters, allowing applications to transparently discover and connect to services running in different clusters using standard DNS queries.

The plugin follows the KEP-1645 Multi-Cluster Services API specifications, supporting the clusterset.local domain for cross-cluster service discovery. It enables ServiceExport and ServiceImport patterns by leveraging Headscale's secure network overlay capabilities.

Syntax

k8s_cross [ZONE...] {
    headscale_url URL API_KEY
    cluster CLUSTER_NAME
    clusterset CLUSTERSET_NAME
    ttl TTL_VALUE
}
  • ZONE: The zones for which the plugin is authoritative. If not specified, defaults to "." (all zones).
  • headscale_url: Specifies the URL and API key for the Headscale server. Required.
  • cluster: Specifies the local cluster name. Defaults to "default-cluster".
  • clusterset: Specifies the clusterset name. Defaults to "default-clusterset".
  • ttl: Sets the TTL value for DNS records. Defaults to 300 seconds.

Examples

Basic Configuration
clusterset.local {
    k8s_cross {
        headscale_url http://headscale:8080 your-headscale-api-key
        cluster prod-cluster
        clusterset production
        ttl 600
    }
}

This configuration enables cross-cluster DNS resolution for the clusterset.local domain, connecting to the Headscale server at http://headscale:8080 using the provided API key. DNS records will have a TTL of 600 seconds.

Multi-Zone Configuration
example.org {
    k8s_cross clusterset.local {
        headscale_url https://headscale.example.com:443 api-key-12345
        cluster primary-cluster
        clusterset staging
    }
}

KEP-1645 Compliance

The plugin implements the Multi-Cluster Services API (KEP-1645) by:

  1. Using the standard clusterset.local domain for cross-cluster service discovery
  2. Supporting service queries in the format: <service>.<namespace>.svc.clusterset.local
  3. Providing DNS records (A, AAAA, SRV, TXT) for multi-cluster services
  4. Supporting both ClusterSetIP and headless service patterns

Metrics

The plugin exports the following Prometheus metrics:

  • coredns_k8s_cross_request_count_total{server}: Counter of DNS requests processed by the k8s_cross plugin.

Ready

The plugin does not implement the Ready interface, as it's always ready to process requests after initialization.

See also

Documentation

Overview

Package k8s_cross is a CoreDNS plugin that implements KEP-1645 Multi-Cluster Services API functionality using Headscale for cross-cluster connectivity.

The plugin provides DNS resolution for services across multiple Kubernetes clusters following the ServiceExport and ServiceImport patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL    string
	APIKey     string
	HTTPClient *http.Client
}

Client represents a client for the Headscale API.

func NewClient

func NewClient(baseURL, apiKey string) *Client

NewClient creates a new Headscale API client.

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, req *CreateUserRequest) (*User, error)

CreateUser creates a new user in Headscale.

func (*Client) GetNode

func (c *Client) GetNode(ctx context.Context, nodeId string) (*Node, error)

GetNode retrieves a specific node by ID from Headscale.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (*HealthResponse, error)

Health checks the health status of the Headscale server.

func (*Client) ListNodes

func (c *Client) ListNodes(ctx context.Context, userFilter string) ([]Node, error)

ListNodes retrieves all nodes from Headscale.

type CreateUserRequest

type CreateUserRequest struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
}

CreateUserRequest represents the request for creating a new user.

type CreateUserResponse

type CreateUserResponse struct {
	User User `json:"user"`
}

CreateUserResponse represents the response from the CreateUser API endpoint.

type GetNodeResponse

type GetNodeResponse struct {
	Node Node `json:"node"`
}

GetNodeResponse represents the response from the GetNode API endpoint.

type HeadscaleClient

type HeadscaleClient interface {
	GetNode(ctx context.Context, nodeId string) (*Node, error)
	ListNodes(ctx context.Context, userFilter string) ([]Node, error)
	Health(ctx context.Context) (*HealthResponse, error)
	CreateUser(ctx context.Context, req *CreateUserRequest) (*User, error)
}

HeadscaleClient interface defines the methods that need to be implemented for interacting with Headscale.

type HealthResponse

type HealthResponse struct {
	DatabaseConnectivity bool `json:"databaseConnectivity"`
}

HealthResponse represents the response from the health API endpoint.

type K8sCross

type K8sCross struct {
	Next plugin.Handler

	// Configuration for the plugin
	HeadscaleClient HeadscaleClient
	Zones           []string
	TTL             uint32
	ClusterName     string
	ClusterSet      string
}

K8sCross is the main structure for the k8s_cross plugin, handling DNS requests for multi-cluster services.

func (K8sCross) Name

func (e K8sCross) Name() string

Name implements the Handler interface, returning the plugin name.

func (K8sCross) Ready

func (e K8sCross) Ready() bool

Ready 实现了 ready.Readiness 接口,用于报告插件是否已准备好处理查询。 当此方法返回 true 时,CoreDNS 认为插件已就绪,此后不再检查。 对于 k8s_cross 插件,由于不需要特殊初始化,始终返回 true。

func (K8sCross) ServeDNS

func (e K8sCross) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface. This is the entry point for the plugin to handle DNS requests. Parameters: - ctx: Request context containing request-related information - w: DNS response writer used to send responses to clients - r: DNS request message Returns: - int: DNS response code - error: Error during processing

type ListNodesResponse

type ListNodesResponse struct {
	Nodes []Node `json:"nodes"`
}

ListNodesResponse represents the response from the ListNodes API endpoint.

type Node

type Node struct {
	ID              string    `json:"id"`
	MachineKey      string    `json:"machineKey"`
	NodeKey         string    `json:"nodeKey"`
	DiscoKey        string    `json:"discoKey"`
	IPAddresses     []string  `json:"ipAddresses"`
	Name            string    `json:"name"`
	User            User      `json:"user"`
	LastSeen        time.Time `json:"lastSeen"`
	Expiry          time.Time `json:"expiry"`
	CreatedAt       time.Time `json:"createdAt"`
	RegisterMethod  string    `json:"registerMethod"`
	Online          bool      `json:"online"`
	ApprovedRoutes  []string  `json:"approvedRoutes"`
	AvailableRoutes []string  `json:"availableRoutes"`
}

Node represents a node in the Headscale network.

type User

type User struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"createdAt"`
	DisplayName string    `json:"displayName"`
	Email       string    `json:"email"`
}

User represents a user in the Headscale system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址