Guest User

dgraph.yaml

a guest
Jul 8th, 2021
12
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This highly available config creates 3 Dgraph Zeros and 3 Dgraph Alphas with 3
  2. # replicas. The Dgraph cluster will still be available to service requests even
  3. # when one Zero and/or one Alpha are down.
  4. #
  5. # There are 3 services can can be used to expose outside the cluster as needed:
  6. # dgraph-zero-public - To load data using Live & Bulk Loaders
  7. # dgraph-alpha-public - To connect clients and for HTTP APIs
  8.  
  9. apiVersion: v1
  10. kind: Service
  11. metadata:
  12. name: dgraph-zero-public
  13. labels:
  14. app: dgraph-zero
  15. monitor: zero-dgraph-io
  16. spec:
  17. type: LoadBalancer
  18. ports:
  19. - port: 5080
  20. targetPort: 5080
  21. name: grpc-zero
  22. - port: 6080
  23. targetPort: 6080
  24. name: http-zero
  25. selector:
  26. app: dgraph-zero
  27. ---
  28. apiVersion: v1
  29. kind: Service
  30. metadata:
  31. name: dgraph-alpha-public
  32. labels:
  33. app: dgraph-alpha
  34. monitor: alpha-dgraph-io
  35. spec:
  36. type: LoadBalancer
  37. ports:
  38. - port: 8080
  39. targetPort: 8080
  40. name: http-alpha
  41. - port: 9080
  42. targetPort: 9080
  43. name: grpc-alpha
  44. selector:
  45. app: dgraph-alpha
  46. ---
  47. # This is a headless service which is necessary for discovery for a dgraph-zero StatefulSet.
  48. # https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset
  49. apiVersion: v1
  50. kind: Service
  51. metadata:
  52. name: dgraph-zero
  53. labels:
  54. app: dgraph-zero
  55. spec:
  56. ports:
  57. - port: 5080
  58. targetPort: 5080
  59. name: grpc-zero
  60. clusterIP: None
  61. # We want all pods in the StatefulSet to have their addresses published for
  62. # the sake of the other Dgraph Zero pods even before they're ready, since they
  63. # have to be able to talk to each other in order to become ready.
  64. publishNotReadyAddresses: true
  65. selector:
  66. app: dgraph-zero
  67. ---
  68. # This is a headless service which is necessary for discovery for a dgraph-alpha StatefulSet.
  69. # https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset
  70. apiVersion: v1
  71. kind: Service
  72. metadata:
  73. name: dgraph-alpha
  74. labels:
  75. app: dgraph-alpha
  76. spec:
  77. ports:
  78. - port: 7080
  79. targetPort: 7080
  80. name: grpc-alpha-int
  81. clusterIP: None
  82. # We want all pods in the StatefulSet to have their addresses published for
  83. # the sake of the other Dgraph alpha pods even before they're ready, since they
  84. # have to be able to talk to each other in order to become ready.
  85. publishNotReadyAddresses: true
  86. selector:
  87. app: dgraph-alpha
  88. ---
  89. # This StatefulSet runs 3 Dgraph Zero.
  90. apiVersion: apps/v1
  91. kind: StatefulSet
  92. metadata:
  93. name: dgraph-zero
  94. spec:
  95. serviceName: "dgraph-zero"
  96. replicas: 3
  97. selector:
  98. matchLabels:
  99. app: dgraph-zero
  100. template:
  101. metadata:
  102. labels:
  103. app: dgraph-zero
  104. spec:
  105. affinity:
  106. podAntiAffinity:
  107. preferredDuringSchedulingIgnoredDuringExecution:
  108. - weight: 100
  109. podAffinityTerm:
  110. labelSelector:
  111. matchExpressions:
  112. - key: app
  113. operator: In
  114. values:
  115. - dgraph-zero
  116. topologyKey: kubernetes.io/hostname
  117. containers:
  118. - name: zero
  119. image: dgraph/dgraph:latest
  120. imagePullPolicy: IfNotPresent
  121. ports:
  122. - containerPort: 5080
  123. name: grpc-zero
  124. - containerPort: 6080
  125. name: http-zero
  126. volumeMounts:
  127. - name: datadir
  128. mountPath: /dgraph
  129. env:
  130. - name: POD_NAMESPACE
  131. valueFrom:
  132. fieldRef:
  133. fieldPath: metadata.namespace
  134. command:
  135. - bash
  136. - "-c"
  137. - |
  138. set -ex
  139. [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
  140. ordinal=${BASH_REMATCH[1]}
  141. idx=$(($ordinal + 1))
  142. if [[ $ordinal -eq 0 ]]; then
  143. exec dgraph zero --my=$(hostname -f):5080 --raft="idx=$idx" --replicas 3
  144. else
  145. exec dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080 --raft="idx=$idx" --replicas 3
  146. fi
  147. livenessProbe:
  148. httpGet:
  149. path: /health
  150. port: 6080
  151. initialDelaySeconds: 15
  152. periodSeconds: 10
  153. timeoutSeconds: 5
  154. failureThreshold: 6
  155. successThreshold: 1
  156. readinessProbe:
  157. httpGet:
  158. path: /health
  159. port: 6080
  160. initialDelaySeconds: 15
  161. periodSeconds: 10
  162. timeoutSeconds: 5
  163. failureThreshold: 6
  164. successThreshold: 1
  165. terminationGracePeriodSeconds: 60
  166. volumes:
  167. - name: datadir
  168. persistentVolumeClaim:
  169. claimName: datadir
  170. updateStrategy:
  171. type: RollingUpdate
  172. volumeClaimTemplates:
  173. - metadata:
  174. name: datadir
  175. annotations:
  176. volume.alpha.kubernetes.io/storage-class: anything
  177. spec:
  178. accessModes:
  179. - "ReadWriteOnce"
  180. resources:
  181. requests:
  182. storage: 5Gi
  183. ---
  184. # This StatefulSet runs 3 replicas of Dgraph Alpha.
  185. apiVersion: apps/v1
  186. kind: StatefulSet
  187. metadata:
  188. name: dgraph-alpha
  189. spec:
  190. serviceName: "dgraph-alpha"
  191. replicas: 3
  192. selector:
  193. matchLabels:
  194. app: dgraph-alpha
  195. template:
  196. metadata:
  197. labels:
  198. app: dgraph-alpha
  199. spec:
  200. affinity:
  201. podAntiAffinity:
  202. preferredDuringSchedulingIgnoredDuringExecution:
  203. - weight: 100
  204. podAffinityTerm:
  205. labelSelector:
  206. matchExpressions:
  207. - key: app
  208. operator: In
  209. values:
  210. - dgraph-alpha
  211. topologyKey: kubernetes.io/hostname
  212. # Initializing the Alphas:
  213. #
  214. # You may want to initialize the Alphas with data before starting, e.g.
  215. # with data from the Dgraph Bulk Loader: https://dgraph.io/docs/deploy/#bulk-loader.
  216. # You can accomplish by uncommenting this initContainers config. This
  217. # starts a container with the same /dgraph volume used by Alpha and runs
  218. # before Alpha starts.
  219. #
  220. # You can copy your local p directory to the pod's /dgraph/p directory
  221. # with this command:
  222. #
  223. # kubectl cp path/to/p dgraph-alpha-0:/dgraph/ -c init-alpha
  224. # (repeat for each alpha pod)
  225. #
  226. # When you're finished initializing each Alpha data directory, you can signal
  227. # it to terminate successfully by creating a /dgraph/doneinit file:
  228. #
  229. # kubectl exec dgraph-alpha-0 -c init-alpha touch /dgraph/doneinit
  230. #
  231. # Note that pod restarts cause re-execution of Init Containers. Since
  232. # /dgraph is persisted across pod restarts, the Init Container will exit
  233. # automatically when /dgraph/doneinit is present and proceed with starting
  234. # the Alpha process.
  235. #
  236. # Tip: StatefulSet pods can start in parallel by configuring
  237. # .spec.podManagementPolicy to Parallel:
  238. #
  239. # https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees
  240. #
  241. # initContainers:
  242. # - name: init-alpha
  243. # image: dgraph/dgraph:latest
  244. # command:
  245. # - bash
  246. # - "-c"
  247. # - |
  248. # trap "exit" SIGINT SIGTERM
  249. # echo "Write to /dgraph/doneinit when ready."
  250. # until [ -f /dgraph/doneinit ]; do sleep 2; done
  251. # volumeMounts:
  252. # - name: datadir
  253. # mountPath: /dgraph
  254. containers:
  255. - name: alpha
  256. image: dgraph/dgraph:latest
  257. imagePullPolicy: IfNotPresent
  258. ports:
  259. - containerPort: 7080
  260. name: grpc-alpha-int
  261. - containerPort: 8080
  262. name: http-alpha
  263. - containerPort: 9080
  264. name: grpc-alpha
  265. volumeMounts:
  266. - name: datadir
  267. mountPath: /dgraph
  268. env:
  269. # This should be the same namespace as the dgraph-zero
  270. # StatefulSet to resolve a Dgraph Zero's DNS name for
  271. # Alpha's --zero flag.
  272. - name: POD_NAMESPACE
  273. valueFrom:
  274. fieldRef:
  275. fieldPath: metadata.namespace
  276. # dgraph versions earlier than v1.2.3 and v20.03.0 can only support one zero:
  277. # `dgraph alpha --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080`
  278. # dgraph-alpha versions greater than or equal to v1.2.3 or v20.03.1 can support
  279. # a comma-separated list of zeros. The value below supports 3 zeros
  280. # (set according to number of replicas)
  281. command:
  282. - bash
  283. - "-c"
  284. - |
  285. set -ex
  286. dgraph alpha --my=$(hostname -f):7080 --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080,dgraph-zero-1.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080,dgraph-zero-2.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080
  287. livenessProbe:
  288. httpGet:
  289. path: /health?live=1
  290. port: 8080
  291. initialDelaySeconds: 15
  292. periodSeconds: 10
  293. timeoutSeconds: 5
  294. failureThreshold: 6
  295. successThreshold: 1
  296. readinessProbe:
  297. httpGet:
  298. path: /health
  299. port: 8080
  300. initialDelaySeconds: 15
  301. periodSeconds: 10
  302. timeoutSeconds: 5
  303. failureThreshold: 6
  304. successThreshold: 1
  305. terminationGracePeriodSeconds: 600
  306. volumes:
  307. - name: datadir
  308. persistentVolumeClaim:
  309. claimName: datadir
  310. updateStrategy:
  311. type: RollingUpdate
  312. volumeClaimTemplates:
  313. - metadata:
  314. name: datadir
  315. annotations:
  316. volume.alpha.kubernetes.io/storage-class: anything
  317. spec:
  318. accessModes:
  319. - "ReadWriteOnce"
  320. resources:
  321. requests:
  322. storage: 5Gi
  323.  
RAW Paste Data