nats-io / nats-streaming-operator

NATS Streaming Operator
Apache License 2.0
174 stars 44 forks source link

Support SQL store and custom Pod Spec #20

Closed wallyqs closed 5 years ago

wallyqs commented 5 years ago

This makes it possible to set store type to be SQL and ensure that the operator creates only a single instance at a time for the specified cluster. In order to pass the credentials to the database, a secret has to be used and be mounted as part of the NATS Streaming container that will be connecting to the DB:

---
apiVersion: "streaming.nats.io/v1alpha1"
kind: "NatsStreamingCluster"
metadata:
  name: "example-stan-db"
spec:
  natsSvc: "example-nats"

  # Explicitly set that the managed NATS Streaming instance
  # will be using an SQL storage, to ensure that only a single
  # instance is available.
  store: SQL

  # In order to use DB store support, it is needed to include
  # the credentials as a secret on a mounted file.
  configFile: "/etc/stan/config/secret.conf"

  # Define Pod Spec
  template:
    spec:
      volumes:
      - name: stan-secret
        secret:
          secretName: stan-secret
      containers:
        - name: nats-streaming
          volumeMounts:
          - mountPath: /etc/stan/config
            name: stan-secret
            readOnly: true

The secret configuration file should be in regular NATS Streaming config format:

echo '
streaming: {
  sql: {
    driver: "postgres"
    source: "postgres://exampleuser:notasecret@stan.asdfkljh.us-west-2.rds.amazonaws.com/stan?sslmode=disable"
  }
}
' > secret.conf

$ kubectl create secret generic stan-secret --from-file secret.conf

Fixes #10