79 lines
1.9 KiB
Nix
79 lines
1.9 KiB
Nix
|
|
{
|
||
|
|
config,
|
||
|
|
pkgs,
|
||
|
|
lib,
|
||
|
|
...
|
||
|
|
}:
|
||
|
|
|
||
|
|
{
|
||
|
|
options = {
|
||
|
|
services.kubernetes = {
|
||
|
|
enable = lib.mkOption {
|
||
|
|
type = lib.types.bool;
|
||
|
|
default = false;
|
||
|
|
description = "Whether to enable Kubernetes services";
|
||
|
|
};
|
||
|
|
|
||
|
|
version = lib.mkOption {
|
||
|
|
type = lib.types.str;
|
||
|
|
default = "1.28.0";
|
||
|
|
description = "Kubernetes version to use";
|
||
|
|
};
|
||
|
|
|
||
|
|
clusterName = lib.mkOption {
|
||
|
|
type = lib.types.str;
|
||
|
|
default = "palatine-hill-cluster";
|
||
|
|
description = "Name of the Kubernetes cluster";
|
||
|
|
};
|
||
|
|
|
||
|
|
controlPlaneEndpoint = lib.mkOption {
|
||
|
|
type = lib.types.str;
|
||
|
|
default = "localhost:6443";
|
||
|
|
description = "Control plane endpoint";
|
||
|
|
};
|
||
|
|
|
||
|
|
networking = lib.mkOption {
|
||
|
|
type = lib.types.attrs;
|
||
|
|
default = { };
|
||
|
|
description = "Kubernetes networking configuration";
|
||
|
|
};
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
config = lib.mkIf config.services.kubernetes.enable {
|
||
|
|
environment.systemPackages = with pkgs; [
|
||
|
|
kubectl
|
||
|
|
kubernetes
|
||
|
|
];
|
||
|
|
|
||
|
|
# Enable containerd for Kubernetes
|
||
|
|
virtualisation.containerd.enable = true;
|
||
|
|
|
||
|
|
# Enable kubelet
|
||
|
|
services.kubelet = {
|
||
|
|
enable = true;
|
||
|
|
extraFlags = {
|
||
|
|
"pod-infra-container-image" = "registry.k8s.io/pause:3.9";
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
# Enable kubeadm for cluster initialization
|
||
|
|
environment.etc."kubeadm.yaml".text = ''
|
||
|
|
apiVersion: kubeadm.k8s.io/v1beta3
|
||
|
|
kind: InitConfiguration
|
||
|
|
localAPIEndpoint:
|
||
|
|
advertiseAddress: 127.0.0.1
|
||
|
|
bindPort: 6443
|
||
|
|
---
|
||
|
|
apiVersion: kubeadm.k8s.io/v1beta3
|
||
|
|
kind: ClusterConfiguration
|
||
|
|
clusterName: ${config.services.kubernetes.clusterName}
|
||
|
|
controlPlaneEndpoint: ${config.services.kubernetes.controlPlaneEndpoint}
|
||
|
|
networking:
|
||
|
|
serviceSubnet: 10.96.0.0/12
|
||
|
|
podSubnet: 10.244.0.0/16
|
||
|
|
dnsDomain: cluster.local
|
||
|
|
'';
|
||
|
|
};
|
||
|
|
}
|