Duck GPT-4o
Setting up a home lab with k3s using Alpine Linux and the specified configuration is a great way to learn about Kubernetes and container orchestration. Below is a recommended setup for your Kubernetes cluster, including steps for installation, configuration, and deployment of your applications.
Prerequisites
- Physical Machines: Ensure you have two physical machines with virtualization support enabled in the BIOS.
- Virtual Machines: Create three VMs:
- VM1: Master Node (k3s server)
- VM2: Worker Node (k3s agent)
- VM3: Worker Node (k3s agent)
- Alpine Linux: Install Alpine Linux on all three VMs.
- Networking: Ensure that all VMs can communicate with each other over the network.
Step 1: Disable IPv6
To disable IPv6 on Alpine Linux, you can modify the /etc/sysctl.conf file:
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf
sysctl -pStep 2: Install k3s
-
On VM1 (Master Node):
- Install k3s using the following command:
curl -sfL https://get.k3s.io | sh -- After installation, retrieve the k3s token for worker nodes:
cat /var/lib/rancher/k3s/server/node-token -
On VM2 and VM3 (Worker Nodes):
- Install k3s as a worker node using the token from VM1:
curl -sfL https://get.k3s.io | K3S_URL=https://<VM1_IP>:6443 K3S_TOKEN=<TOKEN> sh -Replace
<VM1_IP>with the IP address of VM1 and<TOKEN>with the token you retrieved earlier.
Step 3: Configure NFS for Persistent Storage
-
On Physical Machine 1:
- Ensure that NFS is installed and configured. Export the desired directory in
/etc/exports:
/path/to/nfs/share *(rw,sync,no_subtree_check)- Restart the NFS service:
exportfs -a systemctl restart nfs-server - Ensure that NFS is installed and configured. Export the desired directory in
-
On VMs:
- Install NFS client:
apk add nfs-utils- Create a mount point and mount the NFS share:
mkdir -p /mnt/nfs mount -o nolock <Physical_Machine_1_IP>:/path/to/nfs/share /mnt/nfs- To make the mount persistent, add the following line to
/etc/fstab:
<Physical_Machine_1_IP>:/path/to/nfs/share /mnt/nfs nfs defaults 0 0
Step 4: Deploy Applications
You can deploy your applications using Helm or Kubernetes manifests. Below are example manifests for each application:
-
Nextcloud:
- Create a
nextcloud-deployment.yamlfile:
apiVersion: apps/v1 kind: Deployment metadata: name: nextcloud spec: replicas: 1 selector: matchLabels: app: nextcloud template: metadata: labels: app: nextcloud spec: containers: - name: nextcloud image: nextcloud ports: - containerPort: 80 volumeMounts: - name: nextcloud-storage mountPath: /var/www/html volumes: - name: nextcloud-storage nfs: server: <Physical_Machine_1_IP> path: /path/to/nfs/share/nextcloud - Create a
-
Vaultwarden:
- Create a
vaultwarden-deployment.yamlfile:
apiVersion: apps/v1 kind: Deployment metadata: name: vaultwarden spec: replicas: 1 selector: matchLabels: app: vaultwarden template: metadata: labels: app: vaultwarden spec: containers: - name: vaultwarden image: vaultwarden/server ports: - containerPort: 80 volumeMounts: - name: vaultwarden-storage mountPath: /data volumes: - name: vaultwarden-storage - Create a