Stream of Consciousness

Mark Eschbach's random writings on various topics.

Forking Node Module

Categories: tech

Tags: stock nodejs algorithm-trading kubernetes

Maurice has reached the point where I am ready to deploy the initial version on my K8S cluster. In the future I would love to setup a helm chart however for now it’s a bit more heavy weight than what I really need.

The first major hurtle is how to mount the configuration file. Kubernetes allows one to mount a secrets volume. However the volume must be mounted as a directory. This is not unreasonable, however does deviate from the Docker volume design which does allow for mounting individual files.

Sometimes I over build just enough that it works out. I can easily override the location of the configuration file by passing an additional argument to the program contianing the path to execute. To help in debugging I found kubectl-tree super helpful.

Example K8S configuration

To spare anyone else who might be interested in deploying this service here is the YAML you’ll need. Remember to replace the secrets with a base64 encoding of your config.json file.

apiVersion: v1
kind: Namespace
metadata:
  name: maurice-prod
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: maurice
  namespace: maurice-prod
  labels:
    app: maurice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: maurice
  template:
    metadata:
      labels:
        app: maurice
    spec:
      containers:
        - name: watcher
          image: meschbach/maurice:0.1.0
          command: ["node","/app/maurice.js"]
          args: ["/var/maurice/config.json"]
          volumeMounts:
            - name: config
              mountPath: "/var/maurice"
              readOnly: true
      volumes:
        - name: config
          secret:
            secretName: 'asset-watcher-config'
---
apiVersion: v1
kind: Secret
metadata:
  name: asset-watcher-config
  namespace: mee-stocks
data:
  config.json: '<your-base64-encoded-config>'