Kilo Documentation

repository·main·Indexed 25 days ago

https://github.com/squat/kilo

Kilo is a multi-cloud network overlay built on WireGuard for Kubernetes, providing an encrypted Layer 3 mesh network for secure communication between nodes across different data centers, clouds, or Kubernetes clusters. It can operate as an independent networking provider or as an add-on to existing CNIs like Flannel or Cilium. The project includes the kg agent for node management and the kgctl CLI for network management, topology visualization, and peer connection.

Tokens
16.3K
Snippets
45
Records
85
Agent score
78%

What's inside Kilo

  1. Overview of Kilo

    main

    Kilo is a multi-cloud network overlay built on WireGuard for Kubernetes. It provides an encrypted Layer 3 network that can span across different data centers and public clouds.

    Key capabilities include:

    • Fully connected Pod networks: Enables communication even between nodes in different networks or behind NAT.
    • Multi-cloud clusters: Allows pools of nodes in different locations to communicate securely.
    • VPN access: Enables external clients to VPN into a cluster to access services or debug resources.
    • Multi-cluster services: Enables services to span across different Kubernetes clusters.
  2. What is the kg agent?

    main

    The kg agent is the core component of a Kilo mesh that runs on every Kubernetes node. Its primary responsibilities include:

    • Mesh Membership: Adding the node to the Kilo mesh.
    • CNI Management: Installing and managing CNI (Container Network Interface) configurations on the node.
    • WireGuard Setup: Configuring the WireGuard network interface.
    • Network Maintenance: Maintaining routing table entries and iptables rules to ensure connectivity between locations.
  3. Connect multiple Kubernetes clusters using Kilo

    main

    Kilo can connect independent Kubernetes clusters over a secure WireGuard connection, allowing clusters to provide private services to one another. This enables workloads in one cluster (e.g., an on-prem cluster) to consume services in another (e.g., an AWS cluster with GPUs) without exposing them via Ingress or NodePort.

    Critical Requirement: To ensure full routability, the declared IP ranges must be non-overlapping. This includes the Kilo, pod, and service CIDRs for all connected clusters.

  4. How Kilo works

    main

    Kilo uses WireGuard to create a mesh between nodes in a cluster. The Kilo agent, kg, runs on every node to manage public/private keys and routing rules.

    Kilo can be used in two modes:

    1. Independent networking provider: Acts as the primary CNI.
    2. Add-on mode: Complements an existing CNI (like Flannel) by handling the network between different locations/clouds, while the existing CNI handles local networking within those locations.
  5. How Peer Validation works in Kilo

    main

    Kilo uses a Kubernetes ValidatingAdmissionWebhook to prevent faulty Peer configurations from being applied to the cluster.

    When a ValidatingWebhookConfiguration is active, the Kubernetes API server sends an AdmissionReviewRequest to the Kilo Peer Validation service whenever a CREATE or UPDATE operation is attempted on a Peer resource.

    • If the webhook returns "allowed": true, the operation proceeds.
    • If the webhook returns "allowed": false, the operation is denied.
    • The default failurePolicy is set to Fail, meaning if the webhook service is unavailable, the API server will deny the changes to ensure safety.
  6. Configure logical groups for topology

    main

    Kilo determines how to group nodes into logical locations using the following priority:

    1. The topology.kubernetes.io/region node label.
    2. A custom label specified via the --topology-label=<label> command line flag.
    3. The kilo.squat.ai/location node annotation.

    If no custom label or annotation is provided, Kilo uses the Kubernetes region label. To manually group nodes into a specific location (e.g., gcp), use the kilo.squat.ai/location annotation.

  7. Customize Kilo network topology

    main
    Kilo allows administrators to customize the encrypted network topology. You can choose between a full mesh (where every node is in its own group and all inter-node traffic is encrypted) or a logical mesh (where nodes are grouped into distinct pools, such as by data-center or cloud provider, and only links between these pools are established). This is useful for securing traffic on untrusted networks while maintaining high performance on trusted ones.
  8. Prerequisites for building Kilo

    main

    Before building or testing Kilo, ensure you have the following utilities installed on your system:

    • go (used for code formatting and running unit tests)
    • make
    • jq
    • git
    • curl
    • docker (required for binary compilation and container builds)
  9. Run Kilo tests and linting

    main

    Use make commands to execute different levels of testing and code quality checks:

    • make unit: Runs unit tests.
    • make lint: Lints the repository code.
    • make e2e: Runs basic end-to-end tests (note: these may be flaky).
    • make test: Runs all tests with a single command.
    make unit
    make lint
    make e2e
    make test
  10. Use userspace WireGuard in heterogeneous clusters

    main

    In a heterogeneous cluster where only some nodes lack the WireGuard kernel module, you can provide userspace WireGuard specifically to those nodes while allowing others to use the kernel module.

    This setup uses nkml as a DaemonSet to label nodes based on whether they have the WireGuard kernel module. It then deploys two distinct Kilo DaemonSets:

    1. kilo: For nodes with the kernel module.
    2. kilo-userspace: For nodes without the kernel module, using wireguard-go as a sidecar.

    Important Requirements:

    • nkml must be run on the host network before the CNI is available.
    • nkml requires a kubeconfig to access the Kubernetes API.

    To apply an example configuration for a K3s cluster, run:

    kubectl apply -f https://raw.githubusercontent.com/squat/kilo/main/manifests/crds.yaml
    kubectl apply -f https://raw.githubusercontent.com/squat/kilo/main/manifests/kilo-k3s-userspace-heterogeneous.yaml
  11. Monitor the Kilo DaemonSet

    main

    To monitor the Kilo DaemonSet using the kube-prometheus stack, apply the provided PodMonitor manifest to your cluster.

    kubectl apply -f https://raw.githubusercontent.com/squat/kilo/main/manifests/podmonitor.yaml
  12. Build the website for production

    main

    Generate the static production content by running yarn build. The resulting static files will be located in the build directory and can be hosted on any static content hosting service.

    $ yarn build