Coder Social home page Coder Social logo

Comments (1)

matthewhartstonge avatar matthewhartstonge commented on May 22, 2024

Hi @damir-manapov,

You can do this using the simple-stan example as a template. You can then update the yaml spec to include the storage class you require.
See: https://github.com/nats-io/k8s/blob/master/nats-streaming-server/simple-stan.yml#L51-L60

Clustering

For example:

  volumeClaimTemplates:
  - metadata:
      name: stan-sts-vol
    spec:
      accessModes:
      - ReadWriteOnce
      volumeMode: "Filesystem"
      resources:
        requests:
          storage: 1Gi

Would become:

  volumeClaimTemplates:
  - metadata:
      name: stan-sts-vol
    spec:
      accessModes:
      - ReadWriteOnce
      volumeMode: "Filesystem"
      storageClassName: YOUR_STORAGE_CLASS_NAME
      resources:
        requests:
          storage: 1Gi

Fault Tolerance Mode

If you are running in fault tolerance mode, (by tweaking the config) you would need to remove the volumeClaimTemplate and create a PVC that supports ReadWriteMany by itself:

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: stan-sts-vol
spec:
  storageClassName: YOUR_STORAGE_CLASS_NAME
  accessModes:
    - ReadWriteMany
  volumeMode: "Filesystem"
  resources:
    requests:
      storage: 1Gi

And then bind that in via volumes at https://github.com/nats-io/k8s/blob/master/nats-streaming-server/simple-stan.yml#L77-L122:

...
      # STAN Server
      containers:
        - name: stan
          image: nats-streaming:0.16.2
          ports:
            - containerPort: 8222
              name: monitor
            - containerPort: 7777
              name: metrics
          args:
            - "-sc"
            - "/etc/stan-config/stan.conf"

          # Required to be able to define an environment variable
          # that refers to other environment variables.  This env var
          # is later used as part of the configuration file.
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          volumeMounts:
            - name: config-volume
              mountPath: /etc/stan-config
            - name: stan-sts-vol
              mountPath: /data/stan

          # Disable CPU limits.
          resources:
            requests:
              cpu: 0

          livenessProbe:
            httpGet:
              path: /
              port: 8222
            initialDelaySeconds: 10
            timeoutSeconds: 5
      volumes:
        - name: config-volume
          configMap:
            name: stan-config
        - name: stan-data-vol
          persistentVolumeClaim:
            claimName: stan-sts-vol

Fault Tolerance Spec all together:

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: stan-sts-vol
spec:
  storageClassName: YOUR_STORAGE_CLASS_NAME
  accessModes:
    - ReadWriteMany
  volumeMode: "Filesystem"
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: stan-config
data:
  stan.conf: |
    port: 4222
    http: 8222
    streaming {
     ns: "nats://nats:4222"
     id: stan
     store: file
     dir: /data/stan/store

     # Configure cluster to run in Fault Tolerance mode (no clustering).
     ft_group: stan-ft
    }
---
apiVersion: v1
kind: Service
metadata:
  name: stan
  labels:
    app: stan
spec:
  selector:
    app: stan
  clusterIP: None
  ports:
  - name: metrics
    port: 7777
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: stan
  labels:
    app: stan
spec:
  selector:
    matchLabels:
      app: stan
  serviceName: stan
  replicas: 3
  template:
    metadata:
      labels:
        app: stan
    spec:
      # Prevent NATS Streaming pods running in same host.
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: "kubernetes.io/hostname"
            labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - stan
      # STAN Server
      containers:
      - name: stan
        image: nats-streaming:0.16.2
        ports:
        - containerPort: 8222
          name: monitor
        - containerPort: 7777
          name: metrics
        args:
         - "-sc"
         - "/etc/stan-config/stan.conf"

        # Required to be able to define an environment variable
        # that refers to other environment variables.  This env var
        # is later used as part of the configuration file.
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
          - name: config-volume
            mountPath: /etc/stan-config
          - name: stan-sts-vol
            mountPath: /data/stan

        # Disable CPU limits.
        resources:
          requests:
            cpu: 0

        livenessProbe:
          httpGet:
            path: /
            port: 8222
          initialDelaySeconds: 10
          timeoutSeconds: 5
      volumes:
      - name: config-volume
        configMap:
          name: stan-config
      - name: stan-sts-vol
        persistentVolumeClaim:
          claimName: stan-sts-vol

Hope that helps!

from k8s.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.