Last active
June 14, 2022 14:52
-
-
Save wallyqs/c566c856b7119645fd7e11056374c584 to your computer and use it in GitHub Desktop.
nats-statefulset.yaml
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: Service | |
metadata: | |
name: nats | |
labels: | |
app: nats | |
spec: | |
selector: | |
app: nats | |
clusterIP: None | |
ports: | |
- name: client | |
port: 4222 | |
- name: cluster | |
port: 6222 | |
- name: monitor | |
port: 8222 | |
- name: metrics | |
port: 7777 | |
- name: leafnodes | |
port: 7422 | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: nats-config | |
data: | |
nats.conf: | | |
pid_file: "/var/run/nats/nats.pid" | |
http: 8222 | |
cluster { | |
port: 6222 | |
routes [ | |
nats://nats-0.nats:6222 | |
nats://nats-1.nats:6222 | |
nats://nats-2.nats:6222 | |
] | |
cluster_advertise: $CLUSTER_ADVERTISE | |
connect_retries: 30 | |
} | |
--- | |
apiVersion: apps/v1 | |
kind: StatefulSet | |
metadata: | |
name: nats | |
labels: | |
app: nats | |
spec: | |
selector: | |
matchLabels: | |
app: nats | |
replicas: 3 | |
serviceName: "nats" | |
template: | |
metadata: | |
labels: | |
app: nats | |
spec: | |
# Required to be able to HUP signal and apply config reload | |
# to the server without restarting the pod. | |
shareProcessNamespace: true | |
################# | |
# # | |
# NATS Server # | |
# # | |
################# | |
terminationGracePeriodSeconds: 60 | |
containers: | |
- name: nats | |
image: nats:2.1.0 | |
ports: | |
- containerPort: 4222 | |
name: client | |
- containerPort: 7422 | |
name: leafnodes | |
# Addresable within the DC cluster network only. | |
- containerPort: 6222 | |
name: cluster | |
- containerPort: 8222 | |
name: monitor | |
- containerPort: 7777 | |
name: metrics | |
args: | |
- "--config" | |
- "/etc/nats-config/nats.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 | |
volumeMounts: | |
- name: config-volume | |
mountPath: /etc/nats-config | |
- name: pid | |
mountPath: /var/run/nats | |
# Disable all cpu limits for the server. | |
# | |
resources: | |
requests: | |
cpu: 0 | |
# Liveness/Readiness probes against the monitoring | |
# | |
livenessProbe: | |
httpGet: | |
path: / | |
port: 8222 | |
initialDelaySeconds: 10 | |
timeoutSeconds: 5 | |
readinessProbe: | |
httpGet: | |
path: / | |
port: 8222 | |
initialDelaySeconds: 10 | |
timeoutSeconds: 5 | |
# Gracefully stop NATS Server on pod deletion or image upgrade. | |
# | |
lifecycle: | |
preStop: | |
exec: | |
# Using the alpine based NATS image, we add an extra sleep that is | |
# the same amount as the terminationGracePeriodSeconds to allow | |
# the NATS Server to gracefully terminate the client connections. | |
# | |
command: ["/nats-server", "-sl=ldm=/var/run/nats/nats.pid"] | |
################################# | |
# # | |
# NATS Configuration Reloader # | |
# # | |
################################# | |
- name: reloader | |
image: connecteverything/nats-server-config-reloader:0.6.0 | |
command: | |
- "nats-server-config-reloader" | |
- "-pid" | |
- "/var/run/nats/nats.pid" | |
- "-config" | |
- "/etc/nats-config/nats.conf" | |
volumeMounts: | |
- name: config-volume | |
mountPath: /etc/nats-config | |
- name: pid | |
mountPath: /var/run/nats | |
############################## | |
# # | |
# NATS Prometheus Exporter # | |
# # | |
############################## | |
- name: metrics | |
image: synadia/prometheus-nats-exporter:0.5.0 | |
args: | |
- -connz | |
- -routez | |
- -subz | |
- -varz | |
- -prefix=nats | |
- -use_internal_server_id | |
- -DV | |
- http://localhost:8222/ | |
ports: | |
- containerPort: 7777 | |
name: metrics | |
volumes: | |
- name: config-volume | |
configMap: | |
name: nats-config | |
- name: pid | |
emptyDir: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment