-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathtemplate.yaml.jinja
94 lines (90 loc) · 2.23 KB
/
template.yaml.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{%- set name = "" -%}
{%- set image = "" -%}
{%- set worker_replicas = 2 -%}
{%- set ps_replicas = 1 -%}
{%- set script = "" -%}
{%- set data_dir = "" -%}
{%- set train_dir = "" -%}
{%- set credential_secret_name = "" -%}
{%- set credential_secret_key = "" -%}
{%- set port = 5000 -%}
{%- set replicas = {"worker": worker_replicas, "ps": ps_replicas} -%}
{%- macro worker_hosts() -%}
{%- for i in range(worker_replicas) -%}
{%- if not loop.first -%},{%- endif -%}
{{ name }}-worker-{{ i }}:{{ port }}
{%- endfor -%}
{%- endmacro -%}
{%- macro ps_hosts() -%}
{%- for i in range(ps_replicas) -%}
{%- if not loop.first -%},{%- endif -%}
{{ name }}-ps-{{ i }}:{{ port }}
{%- endfor -%}
{%- endmacro -%}
{%- for job in ["worker", "ps"] -%}
{%- for i in range(replicas[job]) -%}
kind: Service
apiVersion: v1
metadata:
name: {{ name }}-{{ job }}-{{ i }}
spec:
selector:
name: {{ name }}
job: {{ job }}
task: "{{ i }}"
ports:
- port: {{ port }}
---
kind: ReplicaSet
apiVersion: extensions/v1beta1
metadata:
name: {{ name }}-{{ job }}-{{ i }}
spec:
replicas: 1
template:
metadata:
labels:
name: {{ name }}
job: {{ job }}
task: "{{ i }}"
spec:
containers:
- name: tensorflow
image: {{ image }}
{% if credential_secret_name != "" %}
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: "/etc/credential/{{ credential_secret_key }}"
{% endif %}
ports:
- containerPort: {{ port }}
{% if job == "tensorboard" %}
command:
- "tensorboard"
args:
- "--logdir={{ train_dir }}"
{% else %}
command:
- "/usr/bin/python"
- "{{ script }}"
args:
- "--data_dir={{ data_dir }}"
- "--train_dir={{ train_dir }}"
- "--task_index={{ i }}"
- "--job_name={{ job }}"
- "--worker_hosts={{ worker_hosts() }}"
- "--ps_hosts={{ ps_hosts() }}"
{% endif %}
{% if credential_secret_name != "" %}
volumeMounts:
- name: credential
mountPath: /etc/credential
readOnly: true
volumes:
- name: credential
secret:
secretName: {{ credential_secret_name }}
{% endif %}
---
{% endfor %}
{%- endfor -%}