Migrate Trendz Kubernetes files from 1.16.1 or earlier
This guide moves a Trendz Kubernetes installation to the files that the trendz-k8s repository ships from Trendz 1.16.1.1.
Who needs this guide
Section titled “Who needs this guide”You need this guide if your cluster still has the ConfigMap trendz-app-db-config, that is, it runs on the files of
Trendz 1.16.1 or earlier:
kubectl -n trendz get configmap trendz-app-db-configIf the command prints the ConfigMap, follow this guide, even if your local folder already holds the new files. If it
prints NotFound, your installation already uses the new files: follow the
upgrade instructions instead.
Before you start
Section titled “Before you start”Follow Prepare for upgrading Trendz Analytics: connect to your cluster and back up the database. Skip its “Obtain Trendz Kubernetes scripts”: step 1 below clones the new files.
What changes
Section titled “What changes”The new files differ in these ways:
- Trendz runs as user
799, not as root. The Python Executor already ran as a non-root user. - The database connection is in the Secret
trendz-db-app-secret, not in the ConfigMaptrendz-app-db-config. - Trendz and the Python Executor share a secret, kept in the Secret
trendz-python-executor-secret. - Each service has two ConfigMaps: one for environment variables (
*-env-config) and one for mounted files (*-files-config). - Trendz is the StatefulSet
trendz-app(podstrendz-app-0,trendz-app-1, …), not the Deploymenttrendz-app-deployment. Each pod keeps its own license file,/data/license-<pod name>.data, and the stable pod names keep it on that file across restarts. /dataof all Trendz pods is the ReadWriteMany volumetrendz-app-shared-pvc, not the ReadWriteOncetrendz-app-pvc.- Valkey (
trendz-cache-deployment.yml) holds the cache shared by Trendz replicas. - A network policy lets only Trendz call the Python Executor and blocks all outbound traffic from the executor.
Your cluster needs a ReadWriteMany storage class (NFS, EFS, Azure Files, CephFS) for trendz-app-shared-pvc. All
Trendz pods share this volume, so a ReadWriteOnce class does not work. If the cluster has no such class, install a
provisioner for one first, for example the NFS or EFS CSI driver.
Migration steps
Section titled “Migration steps”-
Clone the new files next to your old folder. From the folder that contains your old
trendz-k8sfolder:Terminal window git clone https://github.com/thingsboard/trendz-k8s.git --depth 1 trendz-k8s-newcd trendz-k8s-newThe
masterbranch holds the files of the latest Trendz release. Run all later commands, here and in the upgrade instructions, intrendz-k8s-new: it is yourtrendz-k8sfolder from now on. -
Copy your values from the old files in
../trendz-k8s:Old file Values New file trendz-app-db-config.ymlSPRING_DATASOURCE_URL,SPRING_DATASOURCE_USERNAME,SPRING_DATASOURCE_PASSWORDtrendz-db-app-secret.ymltrendz-app-deployment.ymlTB_API_URL,TRENDZ_LICENSE_SECRET,JWT_TOKEN_SIGNING_KEYtrendz-app-statefulset.ymltrendz-app-config.ymlyour changes to trendz.confandlogback.xmltrendz-app-files-config.ymltrendz-python-executor-config.ymlthe Python libraries you added to requirements.txt, your changes topython-executor.confandlogback.xmltrendz-python-executor-files-config.ymltrendz-ingress.ymlyour host, TLS and annotations trendz-ingress.ymlIf you no longer have the old folder, read the values from the cluster. It keeps the old objects until step 7:
Terminal window kubectl -n trendz get configmap trendz-app-db-config trendz-app-config trendz-python-executor-config -o yamlkubectl -n trendz get deployment trendz-app-deployment trendz-python-executor-deployment -o yamlTuning values (heap, timeouts, CPU and memory) are in
trendz-app-env-config.yml,trendz-python-executor-env-config.yml,trendz-app-statefulset.ymlandtrendz-python-executor-deployment.yml. Carry over the ones you changed. The other keys of the old ConfigMaps are no longer used.Then set the values the old files did not have:
trendz-python-executor-secret.yml: replaceplaceholderwith a long random value, for example fromopenssl rand -hex 32.trendz-app-shared-pvc.yml: setstorageClassNameto your ReadWriteMany storage class.
To keep passwords out of the files, you can create the two Secrets with
kubectl create secretinstead, as the comment intrendz-db-app-secret.ymlshows, and skip applying those files in the next step.If you added Python libraries, the executor installs them only with
INSTALL_PYTHON_DEPS_ON_STARTUPset totrueand outbound access to PyPI. See Add custom Python libraries. -
Apply the new configuration. Trendz keeps running; the network policy applies to the running Python Executor at once. If you created the two Secrets from the command line, leave out the line that applies their files:
Terminal window kubectl apply -f trendz-namespace.ymlkubectl apply -f trendz-db-app-secret.yml -f trendz-python-executor-secret.ymlkubectl apply -f trendz-app-env-config.yml -f trendz-app-files-config.ymlkubectl apply -f trendz-python-executor-env-config.yml -f trendz-python-executor-files-config.ymlkubectl apply -f trendz-app-shared-pvc.ymlkubectl apply -f trendz-cache-deployment.ymlkubectl apply -f trendz-python-executor-network-policy.yml -
Stop Trendz. Delete the Deployment; the StatefulSet replaces it in step 6:
Terminal window kubectl -n trendz delete deployment trendz-app-deploymentkubectl -n trendz wait --for=delete pod -l app=trendz-app-pod-label --timeout=180s -
Move the license file to the new volume. A temporary pod copies
license.datafromtrendz-app-pvctotrendz-app-shared-pvcaslicense-trendz-app-0.data, gives it to user799and lists both volumes. It runs as root because the old volume holds files owned by root:Terminal window kubectl -n trendz run trendz-license-move --rm -i --restart=Never --image=busybox:1.37 --overrides='{"spec":{"containers":[{"name":"move","image":"busybox:1.37","command":["sh","-c","if [ -f /old/license.data ] && [ ! -f /data/license-trendz-app-0.data ]; then cp /old/license.data /data/license-trendz-app-0.data && chown 799:799 /data/license-trendz-app-0.data; fi; ls -lnA /old /data"],"volumeMounts":[{"name":"old","mountPath":"/old"},{"name":"data","mountPath":"/data"}]}],"volumes":[{"name":"old","persistentVolumeClaim":{"claimName":"trendz-app-pvc"}},{"name":"data","persistentVolumeClaim":{"claimName":"trendz-app-shared-pvc"}}]}}'Trendz keeps its data in the database. On the old volume it keeps only the license file, the
.firstlaunchmarker and heap dumps. Step 7 deletes that volume: if the list of/oldshows anything else you want to keep, copy it first.Without
license.datanothing is copied. The command never overwrites an existinglicense-trendz-app-0.data, so you can run it again. If it does not finish, checkkubectl -n trendz describe pod trendz-license-move: a Pending volume usually means a wrongstorageClassName. -
Upgrade Trendz. Open the Kubernetes upgrade instructions for 1.16.1.2 and follow the steps for your current version. Skip “Update the Kubernetes files”, and skip “Stop Trendz” if your version has it: you did both here. Come back here when the new Trendz pod is running.
-
Remove the replaced objects:
Terminal window kubectl -n trendz delete pvc trendz-app-pvckubectl -n trendz delete configmap trendz-app-config trendz-app-db-config trendz-python-executor-config
Was this helpful?