-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathkube-diagrams.yaml
497 lines (497 loc) · 19.4 KB
/
kube-diagrams.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# Configuration of kube-diagrams
default_namespace: default
edges:
REFERENCE:
color: black
REFERENCE-UP:
color: black
direction: up
SELECTOR:
color: black
style: dashed
SELECTOR-UP:
color: black
style: dashed
direction: up
CONTROLLED_BY:
xlabel: controller
color: black
style: dotted
OWNER:
color: black
style: dotted
COMMUNICATION:
color: brown
DEPENDENCE:
color: darkgrey
UNDEFINED:
color: red
INVISIBLE:
color: transparent
style: invisible
direction: up
clusters:
- label: app.kubernetes.io/instance
title: K8s Instance
recommended: true
- label: release
title: Release
recommended: false
- label: helm.sh/chart
title: Helm Chart
recommended: true
- label: chart
title: Chart
recommended: false
- label: app.kubernetes.io/name
title: K8s Application
recommended: true
- label: app
title: Application
recommended: false
- label: app.kubernetes.io/component
title: K8s Component
recommended: true
- label: service
title: Microservice
recommended: false
- label: tier
title: Tier
recommended: false
nodes:
APIService/apiregistration.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/apiservice.png
edges: |
service = query_path(resource, "spec.service")
if service != None:
edges.append([
f"{service['name']}/{service['namespace']}/Service/v1",
"REFERENCE"
])
APIService/apiregistration.k8s.io/v1beta1: APIService/apiregistration.k8s.io/v1
ClusterRole/rbac.authorization.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.rbac.CRole
edges: |
for clusterRoleSelector in query_path(resource, "aggregationRule.clusterRoleSelectors", []):
edges.add_all_resources_matching_labels("ClusterRole", "matchLabels", clusterRoleSelector)
ClusterRole/rbac.authorization.k8s.io/v1beta1: ClusterRole/rbac.authorization.k8s.io/v1
ClusterRoleBinding/rbac.authorization.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.rbac.CRB
edges: |
edges.add_role("roleRef")
edges.add_subjects()
ClusterRoleBinding/rbac.authorization.k8s.io/v1beta1: ClusterRoleBinding/rbac.authorization.k8s.io/v1
ConfigMap/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.podconfig.CM
# no edges
CronJob/batch/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.Cronjob
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.jobTemplate.spec.template.spec")
edges.add_all_volume_resources("spec.jobTemplate.spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.jobTemplate.spec.template.spec.containers")
edges.add_wait_for_services("spec.jobTemplate.spec.template.spec.initContainers")
edges.add_networks("spec.jobTemplate.spec.template.metadata.annotations")
edges.add_priority_class("spec.jobTemplate.spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.jobTemplate.spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
CronJob/batch/v1beta1: CronJob/batch/v1
CustomResourceDefinition/apiextensions.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.others.CRD
# no edges
CustomResourceDefinition/apiextensions.k8s.io/v1beta1: CustomResourceDefinition/apiextensions.k8s.io/v1
CSIDriver/storage.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/csidriver.png
# no edges
CSIDriver/storage.k8s.io/v1beta1: CSIDriver/storage.k8s.io/v1
CSINode/storage.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/csinode.png
edges: |
for driver in query_path(resource, "spec.drivers", []):
edges.append([f"{driver['name']}/CSIDriver/storage.k8s.io/v1", "REFERENCE"])
CSIStorageCapacity/storage.k8s.io/v1:
scope: Namescaped
custom_icon: $KD/icons/csisc.png
edges: |
storageClassName = query_path(resource, "storageClassName")
edges.append([f"{storageClassName}/StorageClass/storage.k8s.io/v1", "REFERENCE"])
DaemonSet/apps/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.DS
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
DaemonSet/apps/v1beta2: DaemonSet/apps/v1
Deployment/apps/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.Deploy
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
Deployment/apps/v1beta1: Deployment/apps/v1
Deployment/apps/v1beta2: Deployment/apps/v1
Endpoints/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.network.Endpoint
edges: |
for subset in resource.get("subsets", []):
for address in subset.get("addresses", []):
if "targetRef" in address:
target = address["targetRef"]
edges.append([
"%s/%s/%s/%s" % (
target["name"],
target["namespace"],
target["kind"],
"v1",
),
"REFERENCE"
])
EndpointSlice/discovery.k8s.io/v1:
scope: Namespaced
custom_icon: $KD/icons/eps.png
edges: |
for endpoint in resource.get("endpoints", []):
if "targetRef" in endpoint:
target = endpoint["targetRef"]
edges.add_edge_to(
"endpoints.targetRef",
target["name"],
target["namespace"],
target["kind"],
"v1",
"REFERENCE"
)
Group/rbac.authorization.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.rbac.Group
# no edges
HorizontalPodAutoscaler/autoscaling/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.clusterconfig.HPA
edges: |
edges.add_resource("spec.scaleTargetRef")
HorizontalPodAutoscaler/autoscaling/v2:
scope: Namespaced
diagram_node_classname: diagrams.k8s.clusterconfig.HPA
edges: |
edges.add_resource("spec.scaleTargetRef")
HorizontalPodAutoscaler/autoscaling/v2beta1: HorizontalPodAutoscaler/autoscaling/v2
HorizontalPodAutoscaler/autoscaling/v2beta2: HorizontalPodAutoscaler/autoscaling/v2
Ingress/networking.k8s.io/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.network.Ing
edges: |
for rule in query_path(resource, "spec.rules", []):
for path in query_path(rule, "http.paths", []):
edges.add_service("backend.service.name", path)
ic = "%s/IngressClass/networking.k8s.io/v1" % (
query_path(resource, "spec.ingressClassName"),
)
if ic in resources:
edges.append([ic, "REFERENCE"])
Ingress/networking.k8s.io/v1beta1: Ingress/networking.k8s.io/v1
IngressClass/networking.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/ic.png
edges: |
# TODO: Following works well with ingress-nginx but was not
# been tested with any other ingress implementations.
edges.add_all_resources_matching_labels("Pod", "metadata.labels",
edge_kind="CONTROLLED_BY")
IngressClass/networking.k8s.io/v1beta1: IngressClass/networking.k8s.io/v1
Job/batch/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.Job
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
Job/batch/v1beta1: Job/batch/v1
Lease/coordination.k8s.io/v1:
scope: Namespaced
custom_icon: $KD/icons/lease.png
# no edges
LimitRange/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.clusterconfig.LimitRange
# no edges
MutatingWebhookConfiguration/admissionregistration.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/mwc.png
edges: |
edges.add_webhooks()
MutatingWebhookConfiguration/admissionregistration.k8s.io/v1beta1: MutatingWebhookConfiguration/admissionregistration.k8s.io/v1
Namespace/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.group.NS
# no edges
NetworkAttachmentDefinition/k8s.cni.cncf.io/v1:
scope: Namespaced
diagram_node_classname: diagrams.azure.network.NetworkInterfaces
# no edges
NetworkPolicy/networking.k8s.io/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.network.NetworkPolicy
edges: |
edges.add_all_workload_resources(
"spec.podSelector.matchLabels",
{},
edge_kind="SELECTOR-UP"
)
edges.add_ingress_and_egress_rules()
Node/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.infra.Node
edges: |
edges.add_owned_resources()
PersistentVolume/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.storage.PV
edges: |
edges.add_storage_class("spec.storageClassName")
PersistentVolumeClaim/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.storage.PVC
edges: |
edges.add_storage_class("spec.storageClassName")
edges.add_volume("spec.volumeName")
PriorityClass/scheduling.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/pc.png
# no edges
PriorityClass/scheduling.k8s.io/v1beta1: PriorityClass/scheduling.k8s.io/v1
Pod/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.Pod
edges: |
edges.add_service_account("spec")
edges.add_all_volume_resources("spec.volumes")
edges.add_containers_env_value_from("spec.containers")
edges.add_wait_for_services("spec.initContainers")
nid = "%s/Node/v1" % (
query_path(resource, "spec.nodeName"),
)
if nid in resources:
edges.append([nid, "REFERENCE"])
edges.add_networks("metadata.annotations")
edges.add_priority_class("spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
PodDisruptionBudget/policy/v1:
scope: Namespaced
custom_icon: $KD/icons/pdb.png
edges: |
edges.add_all_workload_resources(
"spec.selector.matchLabels",
edge_kind="SELECTOR-UP"
)
PodDisruptionBudget/policy/v1beta1: PodDisruptionBudget/policy/v1
PodSecurityPolicy/policy/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.others.PSP
# no edges
PodSecurityPolicy/policy/v1beta1: PodSecurityPolicy/policy/v1
PodTemplate/v1:
scope: Namespaced
custom_icon: $KD/icons/podtemplate.png
edges: |
edges.add_service_account("template.spec")
edges.add_all_volume_resources("template.spec.volumes")
edges.add_containers_env_value_from("template.spec.containers")
edges.add_wait_for_services("template.spec.initContainers")
nid = "%s/Node/v1" % (
query_path(resource, "template.spec.nodeName"),
)
if nid in resources:
edges.append([nid, "REFERENCE"])
edges.add_networks("template.metadata.annotations")
edges.add_priority_class("template.spec.priorityClassName")
runtimeClassName = query_path(resource, "template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
ReplicaSet/apps/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.compute.RS
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
ReplicationController/v1:
scope: Namespaced
custom_icon: $KD/icons/rc.png
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
ResourceQuota/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.clusterconfig.Quota
# no edges
Role/rbac.authorization.k8s.io/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.rbac.Role
# no edges
Role/rbac.authorization.k8s.io/v1beta1: Role/rbac.authorization.k8s.io/v1
RoleBinding/rbac.authorization.k8s.io/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.rbac.RB
edges: |
edges.add_role("roleRef")
edges.add_subjects()
RoleBinding/rbac.authorization.k8s.io/v1beta1: RoleBinding/rbac.authorization.k8s.io/v1
RuntimeClass/node.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/runtimeclass.png
Secret/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.podconfig.Secret
# no edges
Service/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.network.SVC
edges: |
edges.add_edges_for_service()
ServiceAccount/v1:
scope: Namespaced
diagram_node_classname: diagrams.k8s.rbac.SA
# no edges
StatefulSet/apps/v1:
scoped: Namespaced
diagram_node_classname: diagrams.k8s.compute.STS
nodes: |
namespace = resource["metadata"].get("namespace")
for vct in query_path(resource, "spec.volumeClaimTemplates", []):
pvc = {
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
**vct
}
pvc["metadata"]["name"] = f'{pvc["metadata"]["name"]}-{resource["metadata"]["name"]}'
if namespace != None:
pvc["metadata"]["namespace"] = namespace
nodes.append(pvc)
edges: |
edges.add_owned_resources()
edges.add_service_account("spec.template.spec")
edges.add_all_volume_resources("spec.template.spec.volumes")
edges.add_containers_env_value_from("spec.template.spec.containers")
edges.add_wait_for_services("spec.template.spec.initContainers")
edges.add_networks("spec.template.metadata.annotations")
edges.add_priority_class("spec.template.spec.priorityClassName")
runtimeClassName = query_path(resource, "spec.template.spec.runtimeClassName")
if runtimeClassName != None:
edges.append([f"{runtimeClassName}/RuntimeClass/node.k8s.io/v1", "REFERENCE"])
edges.add_volume_claim_templates("spec.volumeClaimTemplates")
edges.add_service("spec.serviceName")
StatefulSet/apps/v1beta1: StatefulSet/apps/v1
StatefulSet/apps/v1beta2: StatefulSet/apps/v1
StorageClass/storage.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.storage.SC
edges: |
pid = f"{resource['provisioner']}/CSIDriver/storage.k8s.io/v1"
if pid in resources:
edges.append([pid, "REFERENCE"])
StorageClass/storage.k8s.io/v1beta1: StorageClass/storage.k8s.io/v1
User/rbac.authorization.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.rbac.User
# no edges
ValidatingWebhookConfiguration/admissionregistration.k8s.io/v1:
scope: Cluster
custom_icon: $KD/icons/vwc.png
edges: |
edges.add_webhooks()
ValidatingWebhookConfiguration/admissionregistration.k8s.io/v1beta1: ValidatingWebhookConfiguration/admissionregistration.k8s.io/v1
VerticalPodAutoscaler/autoscaling.k8s.io/v1:
scoped: Namespaced
custom_icon: $KD/icons/vpa.png
edges: |
edges.add_resource("spec.targetRef")
VolumeAttachment/storage.k8s.io/v1:
scope: Cluster
diagram_node_classname: diagrams.k8s.storage.Volume
edges: |
nid = "%s/Node/v1" % (
query_path(resource, "spec.nodeName"),
)
if nid in resources:
edges.append([nid, "REFERENCE"])
cluster-resources:
# default namespace
- default/default/ServiceAccount/v1
- kube-root-ca.crt/default/ConfigMap/v1
- kubernetes/default/Service/v1
# kube-system namespace
- extension-apiserver-authentication-reader/kube-system/Role/rbac.authorization.k8s.io/v1
- horizontal-pod-autoscaler/kube-system/ServiceAccount/v1
# cluster scope
- admin/ClusterRole/rbac.authorization.k8s.io/v1
- cluster-admin/ClusterRole/rbac.authorization.k8s.io/v1
- edit/ClusterRole/rbac.authorization.k8s.io/v1
- generic-garbage-collector/kube-system/ServiceAccount/v1
- standard/StorageClass/storage.k8s.io/v1
- system:anonymous/User/rbac.authorization.k8s.io/v1
- system:auth-delegator/ClusterRole/rbac.authorization.k8s.io/v1
- system:authenticated/Group/rbac.authorization.k8s.io/v1
- system:coredns/ClusterRole/rbac.authorization.k8s.io/v1
- system:discovery/ClusterRole/rbac.authorization.k8s.io/v1
- system:node-proxier/ClusterRole/rbac.authorization.k8s.io/v1
- system:nodes/Group/rbac.authorization.k8s.io/v1
- system:unauthenticated/Group/rbac.authorization.k8s.io/v1
- system:persistent-volume-provisioner/ClusterRole/rbac.authorization.k8s.io/v1
- system:service-account-issuer-discovery/ClusterRole/rbac.authorization.k8s.io/v1
- system:serviceaccounts/Group/rbac.authorization.k8s.io/v1
- system:volume-scheduler/ClusterRole/rbac.authorization.k8s.io/v1
- system-cluster-critical/PriorityClass/scheduling.k8s.io/v1
- system-node-critical/PriorityClass/scheduling.k8s.io/v1
- view/ClusterRole/rbac.authorization.k8s.io/v1