On-Premises & Bare-Metal Cluster (k3s)

Multi-master and bare-metal Kubernetes with k3s on Linux hosts via Polycrate (block ayedo/linux/k8s-1.27): setup, encrypted secrets, and Day-2 operations.

On-Premises & Bare-Metal Cluster (k3s)

With the Linux cluster block of the ayedo Kubernetes Distribution, you can install and operate highly available k3s clusters directly on your own Linux hosts — on bare-metal servers, in on-premises data centers, on cloud VMs, or in isolated air-gapped environments.

You can check current block versions, available parameters, and examples at any time via:

polycrate hub inspect ayedo/linux/k8s-1.27

When Is This Block the Right Choice?

  • On-Premises & Bare Metal: You run Kubernetes on your own hardware or virtual machines.
  • Multi-Master HA: You need a highly available control plane across 3 (or 5) independent Linux nodes with embedded etcd.
  • Air-Gap & Regulated Networks: Container images are pulled via private registry mirrors (k3s.private_registries).
  • Flexible SDP Foundation: Flannel and kube-proxy can be disabled cleanly so you can install Cilium eBPF, MetalLB, Rook/Ceph, or Longhorn as SDP blocks on top.

If you instead need a lightweight control plane running as a pod on an existing host cluster, use k3s-server (Managed Controlplane).

Feature Scope

  • Multi-master HA control plane and worker nodes managed via Ansible groups
  • OIDC integration on kube-apiserver (Keycloak, Authentik, or any OIDC provider)
  • Private registry mirrors and custom TLS SANs for API load balancers
  • Optional control plane without workload scheduling (k3s.controlplane.disable_agent) plus taints and maxpods
  • Toggleable Flannel and kube-proxy for Cilium eBPF
  • Complete lifecycle actions: install, configure-cluster, join-cluster, show-ips, restart-k3s, hosts, uninstall

Setup in Three Steps

1. Define the Inventory (inventory.yml)

Define your control plane and worker hosts in inventory.yml at the root of your Polycrate workspace:

all:
  children:
    k8s_controlplane:
      hosts:
        cp-1:
          ansible_host: 10.0.0.11
          ansible_user: ubuntu
          ansible_become: true
        cp-2:
          ansible_host: 10.0.0.12
          ansible_user: ubuntu
          ansible_become: true
        cp-3:
          ansible_host: 10.0.0.13
          ansible_user: ubuntu
          ansible_become: true
    k8s_worker:
      hosts:
        worker-1:
          ansible_host: 10.0.0.21
          ansible_user: ubuntu
          ansible_become: true
        worker-2:
          ansible_host: 10.0.0.22
          ansible_user: ubuntu
          ansible_become: true

The group names (k8s_controlplane, k8s_worker) must match config.ansible_host_groups in your block configuration.

2. Configure the Block in workspace.poly and the Token in secrets.poly

Place the non-sensitive cluster configuration in workspace.poly:

blocks:
  - name: k8s
    from: cargo.ayedo.cloud/ayedo/linux/k8s-1.27
    config:
      cluster_name: acme-production-1
      cluster_ip_detection:
        enabled: true
      init:
        restart_nodes: false
      oidc:
        enabled: true
        issuer_url: "https://id.example.com/realms/acme"
        client_id: "kubernetes"
        username_claim: "email"
        groups_claim: "groups"
      k3s:
        version: "<desired-k3s-version>" # e.g. current stable v1.3x+k3s1 release
        maxpods: "110"
        cidr: 10.42.0.0/16
        tlssans:
          - k8s-api.example.com
        private_registries:
          enabled: true
          content:
            mirrors:
              docker.io:
                endpoint:
                  - "https://registry.acme.corp"
      flannel:
        disabled: true          # When installing Cilium as CNI afterward
      kube_proxy:
        disabled: true          # When Cilium takes over kube-proxy replacement
      ansible_host_groups:
        controlplane: k8s_controlplane
        worker: k8s_worker

Sensitive values such as the cluster join token (k3s.token, at least 10 characters) must never be stored in plaintext in workspace.poly; place them in the Age-encrypted secrets.poly instead (see Workspace Encryption):

# secrets.poly (stored as secrets.poly.age via polycrate workspace encrypt)
blocks:
  - name: k8s
    config:
      k3s:
        token: "<secure-random-join-token>"

3. Install and Verify the Cluster

# Verify host IPs and inventory mapping upfront
polycrate run k8s show-ips

# Install and configure the control plane
polycrate run k8s install
polycrate run k8s configure-cluster

# Join worker nodes to the cluster
polycrate run k8s join-cluster

The generated kubeconfig is saved in the workspace under artifacts/secrets/kubeconfig.yml and protected via workspace encryption.

Key Configuration Options

Option Description
k3s.version Target k3s release (v1.27 or newer; update regularly to current supported minor releases)
k3s.token Secret join token (managed via secrets.poly, minimum 10 characters)
k3s.cidr Pod network CIDR
k3s.tlssans Additional DNS names or IPs for the API server certificate (e.g., an upstream load balancer)
oidc.* OIDC integration with Keycloak, Authentik, or a corporate IdP
flannel.disabled / kube_proxy.disabled Disables default CNI or kube-proxy for a pure Cilium eBPF setup
cluster_ip_detection.enabled Detects node IPs automatically (otherwise uses values from the inventory)

Day-2 Operations and Upgrades

Task Action / Procedure
Inspect host overview polycrate run k8s hosts or polycrate run k8s show-ips
Adjust configuration without reinstalling polycrate run k8s configure-cluster
Add new workers Add hosts to inventory.yml and run polycrate run k8s join-cluster
Controlled k3s restart polycrate run k8s restart-k3s (performs sequential cordon → drain → restart → uncordon)
Upgrade k3s version Bump k3s.version in workspace.poly (step by step across minor releases) and run polycrate run k8s install
Host hardening & host logs Additionally deploy the ayedo/linux/hardening block (SSH hardening, firewall, auditd, Vector → VictoriaLogs — see Ingesting Logs)

Next Steps After Cluster Setup

The Kubernetes Distribution stops at a working k3s cluster. Next, install the desired SDP platform building blocks:

  1. Networking & Edge: Cilium (eBPF, optionally BGP/LB), MetalLB, Envoy Gateway, or NGINX Ingress
  2. Storage: Longhorn, Rook/Ceph, or cloud CSI drivers
  3. Observability & Security: VictoriaMetrics, VictoriaLogs, Grafana, cert-manager, OpenBao

Further Reading