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

  1. Physical Machines: Ensure you have two physical machines with virtualization support enabled in the BIOS.
  2. Virtual Machines: Create three VMs:
    • VM1: Master Node (k3s server)
    • VM2: Worker Node (k3s agent)
    • VM3: Worker Node (k3s agent)
  3. Alpine Linux: Install Alpine Linux on all three VMs.
  4. 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 -p

Step 2: Install k3s

  1. 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
  2. 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

  1. 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
  2. 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:

  1. Nextcloud:

    • Create a nextcloud-deployment.yaml file:
    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
  2. Vaultwarden:

    • Create a vaultwarden-deployment.yaml file:
    
    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

This page was last edited on 2025-03-07 18:09

Powered by Wiki|Docs

This page was last edited on 2025-03-07 18:09

Mac
To whom it may concern

Powered by Wiki|Docs