forked from nats-io/k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nats-io#20 from nats-io/simple-examples
Add simple examples
- Loading branch information
Showing
2 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
--- | ||
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.default.svc:6222 | ||
nats://nats-1.nats.default.svc:6222 | ||
nats://nats-2.nats.default.svc:6222 | ||
] | ||
cluster_advertise: $CLUSTER_ADVERTISE | ||
connect_retries: 30 | ||
} | ||
--- | ||
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 | ||
- name: gateways | ||
port: 7522 | ||
--- | ||
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: | ||
# Common volumes for the containers | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: nats-config | ||
- name: pid | ||
emptyDir: {} | ||
|
||
# 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-alpine3.10 | ||
ports: | ||
- containerPort: 4222 | ||
name: client | ||
hostPort: 4222 | ||
- containerPort: 7422 | ||
name: leafnodes | ||
hostPort: 7422 | ||
- containerPort: 6222 | ||
name: cluster | ||
- containerPort: 8222 | ||
name: monitor | ||
- containerPort: 7777 | ||
name: metrics | ||
command: | ||
- "nats-server" | ||
- "--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 | ||
|
||
# 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: ["/bin/sh", "-c", "/nats-server -sl=ldm=/var/run/nats/nats.pid && /bin/sleep 60"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
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 | ||
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: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 |