Created
January 21, 2021 17:38
-
-
Save wallyqs/dd958404f5290aa0f03a1e1fdaa1e91b to your computer and use it in GitHub Desktop.
NATS + STAN embedded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: stan-config | |
data: | |
stan.conf: | | |
port: 4222 | |
http: 8222 | |
cluster { | |
port: 6222 | |
routes: $CLUSTER_ROUTES | |
} | |
debug: true | |
streaming { | |
id: stan | |
store: file | |
dir: /data/stan/store | |
cluster { | |
node_id: $POD_NAME | |
log_path: /data/stan/log | |
# Explicit names of resulting peers | |
peers: ["stan-0", "stan-1", "stan-2"] | |
} | |
} | |
--- | |
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 | |
volumeClaimTemplates: | |
- metadata: | |
name: stan-sts-vol | |
spec: | |
accessModes: | |
- ReadWriteOnce | |
volumeMode: "Filesystem" | |
resources: | |
requests: | |
storage: 1Gi | |
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:latest | |
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 | |
- name: CLUSTER_ADVERTISE | |
value: $(POD_NAME).nats.$(POD_NAMESPACE).svc | |
- name: CLUSTER_ROUTES | |
value: "[ stan://stan-0.stan.$(POD_NAMESPACE).svc:6222, stan://stan-1.stan.$(POD_NAMESPACE).svc:6222, stan://stan-2.stan.$(POD_NAMESPACE).svc:6222 ]" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment