Skip to content

Instantly share code, notes, and snippets.

@kamiazya
Created June 13, 2018 03:51
Show Gist options
  • Select an option

  • Save kamiazya/9a5101250e217a79040a637301b41a66 to your computer and use it in GitHub Desktop.

Select an option

Save kamiazya/9a5101250e217a79040a637301b41a66 to your computer and use it in GitHub Desktop.
k8sでnatsdのStatefulSetを作成する
.PHONY: all create-config-map
all:
create-config-map:
# 設定ファイルConfigMapを作成
kubectl create configmap nats-config --from-file=nats.conf
listen: 0.0.0.0:4222
http: 0.0.0.0:8222
# Cluster definition
cluster {
listen: 0.0.0.0:6222
# Routes are actively solicited and connected to from this server.
# Other servers can connect to us if they supply the correct credentials
# in their routes definitions from above.
routes = [
nats://nats:6222
]
}
# logging options
debug: false
trace: true
logtime: true
# Some system overides
# max_connections
max_connections: 100
# maximum protocol control line
max_control_line: 512
# maximum payload
max_payload: 65536
# Duration the server can block on a socket write to a client. Exceeding the
# deadline will designate a client as a slow consumer.
write_deadline: "2s"
apiVersion: v1
# ヘッドレスサービスを作成
kind: Service
metadata:
name: nats
labels:
name: nats
spec:
selector:
app: nats
ports:
- name: client
port: 4222
- name: cluster
port: 6222
- name: monitor
port: 8222
clusterIP: None
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: nats
labels:
app: nats
spec:
serviceName: nats
replicas: 1
template:
metadata:
labels:
app: nats
spec:
# affinity:
# # Podの物理的配置ルールを指定
# podAntiAffinity:
# # nats 同士が別のnode に配置されるのが優先されるように
# requiredDuringSchedulingIgnoredDuringExecution:
# - labelSelector:
# matchExpressions:
# - key: app
# operator: In
# values:
# - nats
# topologyKey: kubernetes.io/hostname
containers:
- name: nats
image: nats:1.1.0-linux
args: [ "--config", "/etc/nats/config/nats.conf"]
volumeMounts:
- name: config-volume
mountPath: /etc/nats/config
ports:
- containerPort: 4222
name: client
- containerPort: 6222
name: cluster
- containerPort: 8222
name: monitor
livenessProbe:
httpGet:
path: /
port: 8222
initialDelaySeconds: 10
timeoutSeconds: 5
volumes:
- name: config-volume
configMap:
name: nats-config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment