我正在構建一個在 Kubernetes 上創建按需節點紅色實體的服務。此服務需要自定義身份驗證,以及 JSON 檔案中的一些其他服務特定資料。
node red 的每個實體都有一個與之關聯的 Persistent Volume,所以我想到的一種方法是將 PVC 與 pod 連接并將檔案復制到 PV,然后在修改后的 PVC 上啟動 node red 部署。
我使用以下腳本來完成此操作
def paste_file_into_pod(self, src_path, dest_path):
dir_name= path.dirname(src_path)
bname = path.basename(src_path)
exec_command = ['/bin/sh', '-c', 'cd {src}; tar cf - {base}'.format(src=dir_name, base=bname)]
with tempfile.TemporaryFile() as tar_buffer:
resp = stream(self.k8_client.connect_get_namespaced_pod_exec, self.kube_methods.component_name, self.kube_methods.namespace,
command=exec_command,
stderr=True, stdin=True,
stdout=True, tty=False,
_preload_content=False)
print(resp)
while resp.is_open():
resp.update(timeout=1)
if resp.peek_stdout():
out = resp.read_stdout()
tar_buffer.write(out.encode('utf-8'))
if resp.peek_stderr():
print('STDERR: {0}'.format(resp.read_stderr()))
resp.close()
tar_buffer.flush()
tar_buffer.seek(0)
with tarfile.open(fileobj=tar_buffer, mode='r:') as tar:
subdir_and_files = [tarinfo for tarinfo in tar.getmembers()]
tar.extractall(path=dest_path, members=subdir_and_files)
這似乎是一種非常混亂的方法。有人可以建議一種快速簡便的方法來使用自定義 settings.js 和一些額外的組態檔在 Kubernetes 中啟動節點紅色嗎?
uj5u.com熱心網友回復:
更好的方法不是使用 PV 進行流存盤,而是使用Storage Plugin將流保存在中央資料庫中。已經有幾個使用像 MongoDB 這樣的資料庫
您可以擴展現有的 Node-RED 容器以包含一個修改過的settings.jsin /data,其中包含存盤和身份驗證插件的詳細資訊,并使用環境變數在啟動時設定特定于實體的實體。
這里的例子:https : //www.hardill.me.uk/wordpress/tag/multi-tenant/
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/402991.html
標籤:
