Search code examples
javascriptkubernetesnats.io

Configure NATS max_payload on Kubernetes


my problem is that I need to increase NATS max_payload in production environment but it uses Kubernetes and I have no idea how to do that, I tried to use ConfigMap but I had not success.

In local/dev environment it uses a NATS config file with docker so it works fine.

Way to make it works local: NATS with moleculer. How can I change NATS max_payload value?

Code inside k8s/deployment.develop.yaml

(...)
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nats
  namespace: develop
  labels:
    account: nats
---
apiVersion: v1
kind: Service
metadata:
  name: nats
  namespace: develop
  labels:
    app: nats
    service: nats
spec:
  ports:
    - port: 4222
      targetPort: 4222
  selector:
    app: nats
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nats-v1
  namespace: develop
  labels:
    app: nats
    version: v1
spec:
  replicas: 1
  strategy: {}
  selector:
    matchLabels:
      app: nats
      version: v1
  template:
    metadata:
      labels:
        app: nats
        version: v1
    spec:
      serviceAccountName: nats
      containers:
        - image: 'nats:alpine'
          name: nats
          ports:
            - containerPort: 4222
      restartPolicy: Always
      tolerations: []
      affinity: {}

Thanks!


Solution

  • The payload value is hardcoded into the docker image (in the nats-server.conf file), so you cannot change it via a configmap. The only solution I found is to build my own nats image with a modified nats-server.conf file.

    Here is how to do it.

    1. First, select an image flavor from the official repo and download the content (for example Dockerfile and nats-server.conf from here).
    2. Modify the nats-server.conf file to change the max_payload value : just add the following line (this file is NOT in JSON format)
    max_payload: 4Mb
    
    1. Then build the image : docker image build .
    2. Tag it, upload it to your own repo and use it instead of the official nats image