Skip to content

Commit bebf84c

Browse files
committed
Automatically pick up the k8s pod namespace for DNS resolution.
The k8s DNS names contain the name of the namespace in which the pods are deployed. The configs assumed that Dgraph is running in the default namespace. This doesn't work when the config is deployed to the non-default namespace. By injecting the namespace name into the pod, we can automatically use the correct namespace for DNS names in the command.
1 parent 3dafddf commit bebf84c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

contrib/config/kubernetes/dgraph-ha.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ spec:
151151
volumeMounts:
152152
- name: datadir
153153
mountPath: /dgraph
154+
env:
155+
- name: POD_NAMESPACE
156+
valueFrom:
157+
fieldRef:
158+
fieldPath: metadata.namespace
154159
command:
155160
- bash
156161
- "-c"
@@ -162,7 +167,7 @@ spec:
162167
if [[ $ordinal -eq 0 ]]; then
163168
dgraph zero --my=$(hostname -f):5080 --idx $idx --replicas 3
164169
else
165-
dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.default.svc.cluster.local:5080 --idx $idx --replicas 3
170+
dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080 --idx $idx --replicas 3
166171
fi
167172
terminationGracePeriodSeconds: 60
168173
volumes:
@@ -225,12 +230,20 @@ spec:
225230
volumeMounts:
226231
- name: datadir
227232
mountPath: /dgraph
233+
env:
234+
# This should be the same namespace as the dgraph-zero
235+
# StatefulSet to resolve a Dgraph Zero's DNS name for
236+
# Alpha's --zero flag.
237+
- name: POD_NAMESPACE
238+
valueFrom:
239+
fieldRef:
240+
fieldPath: metadata.namespace
228241
command:
229242
- bash
230243
- "-c"
231244
- |
232245
set -ex
233-
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-zero-0.dgraph-zero.default.svc.cluster.local:5080
246+
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080
234247
terminationGracePeriodSeconds: 600
235248
volumes:
236249
- name: datadir

contrib/config/kubernetes/dgraph-single.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,17 @@ spec:
7979
volumeMounts:
8080
- name: datadir
8181
mountPath: /dgraph
82+
env:
83+
- name: POD_NAMESPACE
84+
valueFrom:
85+
fieldRef:
86+
fieldPath: metadata.namespace
8287
command:
8388
- bash
8489
- "-c"
8590
- |
8691
set -ex
87-
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-0.dgraph.default.svc.cluster.local:5080
92+
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-0.dgraph.${POD_NAMESPACE}.svc.cluster.local:5080
8893
terminationGracePeriodSeconds: 60
8994
volumes:
9095
- name: datadir

0 commit comments

Comments
 (0)