Skip to content

Deploy Seafile cluster with Kubernetes (K8S) by K8S resources files

This manual explains how to deploy and run Seafile cluster on a Linux server using Kubernetes (k8s thereafter).

Prerequisites

Cluster requirements

Please refer here for the details about the cluster requirements for all nodes in Seafile cluster. In general, we recommend that each node should have at least 2G RAM and a 2-core CPU (> 2GHz).

K8S tools

Two tools are suggested and can be installed with official installation guide on all nodes:

  • kubectl
  • k8s control plane tool (e.g., kubeadm)

After installation, you need to start the k8s control plane service on each node and refer to the k8s official manual for creating a cluster.

Tip

Although we recommend installing the k8s control plane tool on each node, it does not mean that we will use each node as a control plane node, but it is a necessary tool to create or join a K8S cluster. For details, please refer to the above link about creating or joining into a cluster.

Download K8S YAML files for Seafile cluster (without frontend node)

mkdir -p /opt/seafile-k8s-yaml

wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-backend-deployment.yaml
wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-persistentvolume.yaml
wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-persistentvolumeclaim.yaml
wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-service.yaml
wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-env.yaml
wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-secret.yaml

In here we suppose you download the YAML files in /opt/seafile-k8s-yaml, which mainly include about:

  • seafile-xx-deployment.yaml for frontend and backend services pod management and creation,
  • seafile-service.yaml for exposing Seafile services to the external network,
  • seafile-persistentVolume.yaml for defining the location of a volume used for persistent storage on the host
  • seafile-persistentvolumeclaim.yaml for declaring the use of persistent storage in the container.

For futher configuration details, you can refer the official documents.

Modify seafile-env.yaml and seafile-secret.yaml

Similar to Docker-base deployment, Seafile cluster in K8S deployment also supports use files to configure startup progress, you can modify common environment variables by

nano /opt/seafile-k8s-yaml/seafile-env.yaml

and sensitive information (e.g., password) by

nano /opt/seafile-k8s-yaml/seafile-secret.yaml

For seafile-secret.yaml

To modify sensitive information (e.g., password), you need to convert the password into base64 encoding before writing it into the seafile-secret.yaml file:

echo -n '<your-value>' | base64

Warning

For the fields marked with <...> are required, please make sure these items are filled in, otherwise Seafile server may not run properly.

Initialize Seafile cluster

You can use following command to initialize Seafile cluster now (the Seafile's K8S resources will be specified in namespace seafile for easier management):

kubectl apply -f /opt/seafile-k8s-yaml/ -n seafile

About Seafile cluster initialization

When Seafile cluster is initializing, it will run with the following conditions:

  • Only have backend service (i.e., only has the Seafile backend K8S resouce file)
  • CLUSTER_INIT_MODE=true

Success

You can get the following information through kubectl logs seafile-xxxx -n seafile to check the initialization process is done or not:

---------------------------------
This is your configuration
---------------------------------

    server name:            seafile
    server ip/domain:       seafile.example.com

    seafile data dir:       /opt/seafile/seafile-data
    fileserver port:        8082

    database:               create new
    ccnet database:         ccnet_db
    seafile database:       seafile_db
    seahub database:        seahub_db
    database user:          seafile


Generating seafile configuration ...

done
Generating seahub configuration ...


-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------


[2024-11-21 02:22:37] Updating version stamp
Start init

Init success

When the initialization is complete, the server will stop automaticlly (because no operations will be performed after the initialization is completed).

We recommend that you check whether the contents of the configuration files in /opt/seafile/shared/seafile/conf are correct when going to next step, which are automatically generated during the initialization process.

Put the license into /opt/seafile/shared

You have to locate the /opt/seafile/shared directory generated during initialization firsly, then simply put it in this path, if you have a seafile-license.txt license file.

Finally you can use the tar -zcvf and tar -zxvf commands to package the entire /opt/seafile/shared directory of the current node, copy it to other nodes, and unpack it to the same directory to take effect on all nodes.

If the license file has a different name or cannot be read, Seafile server will start with in trailer mode with most THREE users

Download frontend service's YAML and restart pods to start Seafile server

  1. Download frontend service's YAML by:

    wget -P /opt/seafile-k8s-yaml https://manual.seafile.com/12.0/repo/k8s/cluster/seafile-frontend-deployment.yaml
    
  2. Modify seafile-env.yaml, and set CLUSTER_INIT_MODE to false (i.e., disable initialization mode)

  3. Run the following command to restart pods to restart Seafile cluster:

    Tip

    If you modify some configurations in /opt/seafile/shared/seafile/conf or YAML files in /opt/seafile-k8s-yaml/, you still need to restart services to make modifications.

    kubectl delete pods -n seafile $(kubectl get pods -n seafile -o jsonpath='{.items[*].metadata.name}' | grep seafile)
    

Sucess

You can view the pod's log to check the startup progress is normal or not. You can see the following message if server is running normally:

*** Running /etc/my_init.d/01_create_data_links.sh...
*** Booting runit daemon...
*** Runit started as PID 20
*** Running /scripts/enterpoint.sh...
2024-11-21 03:02:35 Nginx ready 

2024-11-21 03:02:35 This is an idle script (infinite loop) to keep container running. 
---------------------------------

Seafile cluster frontend mode

---------------------------------


Starting seafile server, please wait ...
Seafile server started

Done.

Starting seahub at port 8000 ...

Seahub is started

Done.

Uninstall Seafile K8S

You can uninstall the Seafile K8S by the following command:

kubectl delete -f /opt/seafile-k8s-yaml/ -n seafile

Advanced operations

Please refer from here for futher advanced operations.