2025-09-27 17:42:22 +02:00
2025-10-29 11:30:25 +01:00
2025-11-28 16:59:05 +01:00
2025-12-02 09:57:04 +01:00
2026-01-23 13:12:48 +01:00
2025-12-02 09:57:46 +01:00
2025-11-18 13:34:07 +01:00
2025-11-29 13:06:21 +01:00
2025-11-28 17:00:12 +01:00
2025-06-30 12:28:15 +02:00
2025-09-06 08:01:54 +02:00
2021-09-23 14:29:27 +02:00
2025-11-10 17:51:00 +01:00

NixOps Kubernetes clusters

This repository contains a batteries included, production ready, opinionated Kubernetes cluster setup. It only requires editing two simple configuration files to deploy a fully functional cluster using NixOps.

Together, NixOS and Kubernetes is a powerful combination. NixOS enables programmatic configuration of the base Kubernetes system services at the OS level. Just enabling the basic service is still a long way from having a production ready, multi node Kubernetes cluster up and running. Setting up a cluster at the OS level gives you a functional system shell, lacking most of the services needed for actually deploying, accessing and monitoring services.

This project will do to things: It will configure the cluster at the OS level, setting up services, networking, certificates, access tokens etc. It will then bootstrap the running Kubernetes instance, fixing permissions and configuring the following services:

  • Helm for deploying services
  • Nginx-ingress for external access
  • cert-manager with issuers (Let's encrypt, cluster-ca and self-sign)
  • nfs-client-provisioner for automatic volume management
  • kubernetes-dashboard for managing the cluster and services
  • metrics-server for monitoring
  • Prometheus, node exporters and grafana for monitoring

Prerequisites

  1. Install n basic nodes (node-1, ..., node-n) running nixos.
git submodule init
git submodule update

Installation

cd clusters
cp -r template cluster-1
cd cluster-1
../../bin/initca.sh # generates the cluster wide CA certificate
for i in node-1 node-2 node-3; do
  scp $i:/etc/nixos/hardware-confifuration.nix $i.nix
done
vi default.nix # add nodes and ip:s, etc.
../../bin/deploy.sh cluster-1

etcd clustering guide

Using fish:

  1. Install standard nixos k8s
  2. Run the init-admin-kubeconfig.sh script in the k8s-charts repo.
  3. Snapshot the etcd database: etcdctl snapshot save (date --iso-8601).etcd
  4. Add the external interface to the etcd peers:
    etcdctl member list
    etcdctl member update [id] --peer-urls=https://[extenal ip]:2380
    etcdctl member list
    
  5. In the nixos cluster config, enable clustering for all nodes:
      etcdNodes = {
        kN-0 = "https://[ip1]:2380";
        kN-1 = "https://[ip2]:2380";
        kN-2 = "https://[ip3]:2380";
      };
    
      features.k8s.etcdCluster = {
        enable = true;
        existing = false; # true for master node!
        nodes = {}; # vitally important!
      };
    
  6. Add the next node kN-1 to the cluster (on the master node):
    etcdctl member add kN-1 --peer-urls=https://[ip2]:2380
    
  7. ssh into kN-1 and run the etcd-join-cluster script:
    sudo etcd-join-cluster kN-0=https://[ip0]:2380
    
  8. Add the next node kN-2 to the cluster on the master node kN-0:
    etcdctl member add kN-2 --peer-urls=https://[ip2]:2380
    
  9. ssh into kN-2 and run the etcd-join-cluster script:
    sudo etcd-join-cluster kN-0=https://[ip0]:2380,kN-1=https://[ip1]:2380
    
  10. Zap (ctrl-c) the running etcd:s on kN-1 and kN-2.
  11. Uncomment etcdNodes and set existing to true for all, and redeploy cluster
      features.k8s.etcdCluster = {
        enable = true;
        existing = true;
        nodes = etcdNodes;
      };
    
  12. Check logs, restart etcd on nodes if necessary, etc.
Description
NixOps clusters
Readme MIT 1.2 MiB
Languages
Nix 74.4%
Python 18.4%
Shell 7.2%