forked from googleforgames/agones
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocation.yaml
309 lines (299 loc) · 9.7 KB
/
allocation.yaml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{{- $useLoadBalancerIP := and (ne .Values.agones.allocator.http.loadBalancerIP "") (eq .Values.agones.allocator.http.serviceType "LoadBalancer") }}
{{- if .Values.agones.allocator.install }}
# Define a Service for the agones-allocator
apiVersion: v1
kind: Service
metadata:
name: agones-allocator
namespace: {{ .Release.Namespace }}
labels:
component: allocator
app: {{ template "agones.name" . }}
chart: {{ template "agones.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.agones.allocator.http.annotations }}
annotations:
{{ toYaml .Values.agones.allocator.http.annotations | indent 4 }}
{{- end }}
spec:
selector:
multicluster.agones.dev/role: allocator
ports:
- port: {{ .Values.agones.allocator.http.port }}
name: https
targetPort: 8443
protocol: TCP
type: {{ .Values.agones.allocator.http.serviceType }}
{{- if $useLoadBalancerIP }}
loadBalancerIP: {{ .Values.agones.allocator.http.loadBalancerIP }}
{{- end }}
---
# Deploy a pod to run the agones-allocator code
apiVersion: apps/v1
kind: Deployment
metadata:
name: agones-allocator
namespace: {{ .Release.Namespace }}
labels:
multicluster.agones.dev/role: allocator
app: {{ template "agones.name" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.agones.allocator.replicas }}
selector:
matchLabels:
multicluster.agones.dev/role: allocator
app: {{ template "agones.name" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
template:
metadata:
annotations:
{{- if .Values.agones.allocator.generateTLS }}
revision/tls-cert: {{ .Release.Revision | quote }}
{{- end }}
labels:
multicluster.agones.dev/role: allocator
app: {{ template "agones.name" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
annotations:
{{- if and (.Values.agones.metrics.prometheusServiceDiscovery) (.Values.agones.metrics.prometheusEnabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
{{- end }}
spec:
{{- if .Values.agones.allocator.affinity }}
affinity:
{{ toYaml .Values.agones.allocator.affinity | indent 8 }}
{{- end }}
{{- if .Values.agones.allocator.tolerations }}
tolerations:
{{ toYaml .Values.agones.allocator.tolerations | indent 8 }}
{{- end }}
serviceAccountName: agones-allocator
volumes:
- name: tls
secret:
secretName: allocator-tls
- name: client-ca
secret:
secretName: allocator-client-ca
containers:
- name: agones-allocator
image: "{{ .Values.agones.image.registry }}/{{ .Values.agones.image.allocator.name}}:{{ default .Values.agones.image.tag .Values.agones.image.allocator.tag }}"
imagePullPolicy: {{ .Values.agones.image.controller.pullPolicy }}
livenessProbe:
httpGet:
path: /live
port: 8080
initialDelaySeconds: {{ .Values.agones.allocator.healthCheck.initialDelaySeconds }}
periodSeconds: {{ .Values.agones.allocator.healthCheck.periodSeconds }}
failureThreshold: {{ .Values.agones.allocator.healthCheck.failureThreshold }}
timeoutSeconds: {{ .Values.agones.allocator.healthCheck.timeoutSeconds }}
readinessProbe:
httpGet:
path: /ready
port: 8080
env:
- name: PROMETHEUS_EXPORTER
value: {{ .Values.agones.metrics.prometheusEnabled | quote }}
- name: STACKDRIVER_EXPORTER
value: {{ .Values.agones.metrics.stackdriverEnabled | quote }}
- name: GCP_PROJECT_ID
value: {{ .Values.agones.metrics.stackdriverProjectID | quote }}
- name: STACKDRIVER_LABELS
value: {{ .Values.agones.metrics.stackdriverLabels | quote }}
- name: DISABLE_MTLS
value: {{ .Values.agones.allocator.disableMTLS | quote }}
- name: DISABLE_TLS
value: {{ .Values.agones.allocator.disableTLS | quote }}
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CONTAINER_NAME
value: "agones-allocator"
- name: FEATURE_GATES
value: {{ .Values.agones.featureGates | quote }}
ports:
- name: https
containerPort: 8443
volumeMounts:
- mountPath: /home/allocator/tls
name: tls
readOnly: true
- mountPath: /home/allocator/client-ca
name: client-ca
readOnly: true
{{- if .Values.agones.image.controller.pullSecret }}
imagePullSecrets:
- name: {{.Values.agones.image.controller.pullSecret}}
{{- end }}
---
# Create a ClusterRole in that grants access to the agones allocation api
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: agones-allocator
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.name" $ }}
chart: {{ template "agones.chart" $ }}
release: {{ $.Release.Name }}
heritage: {{ $.Release.Service }}
rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
- apiGroups: ["allocation.agones.dev"]
resources: ["gameserverallocations"]
verbs: ["create"]
- apiGroups: [""]
resources: ["nodes", "secrets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["agones.dev"]
resources: ["gameservers", "gameserversets"]
verbs: ["get", "list", "update", "watch"]
- apiGroups: ["agones.dev"]
resources: ["gameservers"]
verbs: ["patch"]
- apiGroups: ["multicluster.agones.dev"]
resources: ["gameserverallocationpolicies"]
verbs: ["get", "list", "watch"]
---
# Create a ServiceAccount that will be bound to the above role
apiVersion: v1
kind: ServiceAccount
metadata:
name: agones-allocator
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.name" $ }}
chart: {{ template "agones.chart" $ }}
release: {{ $.Release.Name }}
heritage: {{ $.Release.Service }}
---
# Bind the agones-allocator ServiceAccount to the agones-allocator ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: agones-allocator
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.name" $ }}
chart: {{ template "agones.chart" $ }}
release: {{ $.Release.Name }}
heritage: {{ $.Release.Service }}
subjects:
- kind: ServiceAccount
name: agones-allocator
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: agones-allocator
{{- end }}
---
# Allocation CA
{{- $selfSigned := genSelfSignedCert "" nil nil 3650 }}
{{- $ca := genCA "allocation-ca" 3650 }}
apiVersion: v1
kind: Secret
metadata:
name: allocator-client-ca
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
{{- if .Values.agones.allocator.generateClientTLS }}
allocator-client.default.crt: {{ b64enc $selfSigned.Cert }}
{{- end }}
{{- if .Values.agones.allocator.generateTLS }}
client-ca.crt: {{ b64enc $ca.Cert }}
{{- else }}
{{- (.Files.Glob "certs/allocator/client-ca/*").AsSecrets | nindent 2 }}
{{- end }}
---
# Allocation TLS certs
{{- $cert := genSignedCert "" ($useLoadBalancerIP | ternary (list .Values.agones.allocator.http.loadBalancerIP) nil) nil 3650 $ca }}
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
name: allocator-tls
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
{{- if .Values.agones.allocator.generateTLS }}
tls.crt: {{ b64enc $cert.Cert }}
tls.key: {{ b64enc $cert.Key }}
{{- else }}
tls.crt: {{ .Files.Get "certs/allocator/server.crt" | b64enc }}
tls.key: {{ .Files.Get "certs/allocator/server.key" | b64enc }}
{{- end }}
---
# Allocation TLS CA
apiVersion: v1
kind: Secret
metadata:
name: allocator-tls-ca
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "agones.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
{{- if .Values.agones.allocator.generateTLS }}
tls-ca.crt: {{ b64enc $ca.Cert }}
{{- else }}
tls-ca.crt: {{ .Files.Get "certs/allocator/server.crt" | b64enc }}
{{- end }}
---
# Default allocation client secret
{{- if .Values.agones.allocator.generateClientTLS }}
{{- range .Values.gameservers.namespaces }}
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
name: allocator-client.default
namespace: {{ . }}
labels:
app: {{ template "agones.fullname" $ }}
chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}"
release: "{{ $.Release.Name }}"
heritage: "{{ $.Release.Service }}"
data:
tls.crt: {{ b64enc $selfSigned.Cert }}
tls.key: {{ b64enc $selfSigned.Key }}
{{- end }}
{{- end }}