Compiling C++ with gcc in Kubernetes container
I recently purchased a Terramaster F4-424 Pro NAS, and quickly discovered that its temperature management was not so great. My hard disks would often hit 40°C and above and, while still well within the recommended maximum operating temperature, I like them cooler.
I found some code that was written for the F4-220. It reads the disk temperatures and adjusts the fan speed by interfacing with the IT8772E chipset. The problem is that the F4-424 has a different chipset, the IT8613E, so the code didn’t work. Because the code didn’t seem to be actively maintained, I decided to fork it and implement the changes.
As NAS operating system I chose Truenas Scale. In order to compile the C++ code, I needed gcc. The problem is that Truenas Scale does not allow you to install gcc with apt:
Truenas Scale however can run Kubernetes containers. I found a way to compile my code using a gcc container:
- In the same folder as the code you want to compile, create
kubernetes-compile.yaml
and adapt it for your use case.
apiVersion: batch/v1
kind: Job
metadata:
name: compile-job
spec:
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: gcc-container
image: gcc
command: ["sh", "-c", "gcc -o fancontrol fancontrol.cpp"]
volumeMounts:
- name: myapp-volume
mountPath: /usr/src/myapp
workingDir: /usr/src/myapp
restartPolicy: Never
volumes:
- name: myapp-volume
hostPath:
path: "/home/admin/terramaster-fancontrol"
backoffLimit: 0
- Create the compile job:
sudo k3s kubectl create -f kubernetes-compile.yaml
- Monitor the job:
sudo k3s kubectl describe job $JOB
- When it’s finished, the job will be deleted after 100 seconds, or delete it manually:
sudo k3s kubectl delete job compile-job
Now you should have your compiled program in the same folder as the code.