How to run a Webserver on Standalone Deployments
Some config options require a webserver that can server content. These are for example :
Changing Element Web apperance with custom background pictures. Or Providing a HomePage for display in Element Web. Or Providing a Guide PDF from your server in an airgapped environment.
You will need:
- a DNS entry pages.BASEDOMAIN.
- a Certificate (private key + certificate) for pages.BASEDOMAIN
- an installed standalone Element Server Suite setup
- access to the server on the command line
You will get:
- a webserver that runs in the mircok8s cluster
- a directory /var/www/apache-content to place and modify homepage, backgrounds and guides.
You can run a Webserver in Element Server Suite deployemnts. This guide is applicable to the Single Node deployment of Element Server Suite but can be used for guidance on how to host a webserver in the Kubernetes Cluster deployemnts as well.
You an use any webserver that you like, in this example we will user the Bitnami Apache chart.
We need helm version 3. One way to get his is to user the Guide. Another way is to ask microk8s to install helm3.
$ microk8s enable helm3
Infer repository core for addon helm3
Enabling Helm 3
Fetching helm version v3.8.0.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.9M 100 12.9M 0 0 17.4M 0 --:--:-- --:--:-- --:--:-- 17.4M
Helm 3 is enabled
Let's check if it is working
$ microk8s.helm3 version
version.BuildInfo{Version:"v3.8.0", GitCommit:"d14138609b01886f544b2025f5000351c9eb092e", GitTreeState:"clean", GoVersion:"go1.17.5"}
Create and Alias for helm
echo alias helm=microk8s.helm3 >> ~/.bashrc
source ~/.bashrc
Add the bitnami repository
helm repo add bitnami https://charts.bitnami.com/bitnami
Update the repo information
helm repo update
We need to add configurations to adjust the apache deployment to our needs. The K8s service should be switched to ClusterIP. The Single Node deployemnt includes an Ingress configuration through nginx that we can use to route traffic to this webserver. The name of the ingressClass is "nginx". We will need a hostname as well. This name needs to be resolvable through DNS. This could be done through the wildcard entry for *.$BASEDOMAIN that you might already have.
service:
type: ClusterIP
ingress:
enabled: true
ingressClassName: "nginx"
hostname: pages.BASEDOMAIN
htdocsConfigMap: "apache-content"
We will be using a config map to load the content that the webserver will serve.
Create a directory to supply this content :
sudo mkdir /var/www/apache-content
Put your content e.g. a homepage into the apache-content directory.
cp /tmp/background.jpg /apache-content/
cp /tmp/home.html ~element/apache-content/
There are multiple ways to provide this content to the apache pod. The bitnami helm chart user ConfigMaps, Physical Volumes or a Git Repository.
ConfigMaps are a good choice for smaller ammounts of data. There is a hard limit of 1MiB on ConfigMaps. So if all your data is not more that 1MiB, the config map is a good choice for you.
Physical Volumes are a good choice for larger amounts of data. There are several choices for backing storage available. In the context of the standalone deployments of ESS a Physical Hostpath is the most practical.
Git Repostiory is a favorit as it versions the content and you track and revert to earlier states easily. The bitnami apache helm chart is built in a way that updates in regular intervals to your latest changes.
We are selecting the Physical Volume option to serve content in this case.
$ cat <<EOF>pv-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: apache-content
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/var/www/apache-content"
EOF
Create a file called apache-values.yml in the home directory of your element user directory. Remember to replace BASEDOMAIN with the correct value for your deployment.
Now we are ready to deploy the apache helm chart
helm install myhomepage -f apache-values.yaml oci://registry-1.docker.io/bitnamicharts/apache
Tips and Tricks
You can make your life easier by using bash completing and an alias for kubectl. You will need to have the bash-completion package installed as a prerequisite.
For all users on the system:
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
Set an aias for kubectl for your user:
echo 'alias k=kubectl' >>~/.bashrc
Enable auto-completion for your alias
echo 'complete -o default -F __start_kubectl k' >>~/.bashrc
After reloading your Shell, you can now enjoy auto completion for your k ( kubectl ) commands.