-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8gb.py
355 lines (312 loc) · 17.5 KB
/
k8gb.py
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
from manim import *
import os
# camera: https://docs.manim.community/en/stable/examples.html#special-camera-settings
# interactions / calls https://docs.manim.community/en/stable/examples.html#pointwithtrace
# add k8gb as black box first
# then zoom in into it and show different components: coredns, externaldns
# revealjs plugin https://github.com/RickDW/manim-revealjs
class FailOver(MovingCameraScene):
# color scheme: https://www.reddit.com/r/manim/comments/dzxoen/predefined_color_scheme/
cfg = {
"no_text": os.getenv('NO_TEXT', "False") == "True",
"font": "Noto Sans",
"code_font": "Arial Rounded MT Bold",
"font_color": BLACK,
"boxes_color": BLACK,
"dns_color": RED_E,
"http_color": BLUE,
"color": BLACK,
}
def construct(self):
self.camera.background_color = WHITE
self.play_all()
# self.display_images()
# self.speech_bubble()
def play_all(self):
self.camera.frame.save_state()
dns_c = self.cfg["dns_color"]
font_c = self.cfg["font_color"]
http_c = self.cfg["http_color"]
font = self.cfg["font"]
k8s1 = Rectangle(width=8.0, height=5.0, color=self.cfg["boxes_color"])
k8s_text1 = Text("Kubernetes", color=font_c, font_size=23, font=font)
k8s_text1.next_to(k8s1, UP)
dep1 = RoundedRectangle(width=3.0, height=2.7, stroke_width=1.0, corner_radius=0.5).set_stroke(GRAY, opacity=0.5).shift(UP*0.1+RIGHT*0.1)
dep_text1 = Text("App Deployment (1 pod)", color=font_c, font_size=20, font=font)
dep_text1.next_to(dep1, UP)
dep_text12 = Text("App Deployment (2 pods)", color=font_c, font_size=20, font=font)
dep_text12.next_to(dep1, UP)
pod11 = Rectangle(width=2.0, height=1.5, color=self.cfg["boxes_color"], fill_color=WHITE, fill_opacity = 1)
pod_text11 = Text("</>", color=http_c, font_size=35,font=self.cfg["code_font"], weight=BOLD)
pod_text11.move_to(pod11)
pod12 = Rectangle(width=2.0, height=1.5, color=self.cfg["boxes_color"], fill_color=WHITE, fill_opacity = 1)
pod_text12 = Text("</>", color=http_c, font_size=35, font=self.cfg["code_font"], weight=BOLD)
pod_text12.move_to(pod12)
deployment1 = Group(dep1, pod11, pod_text11)
pod2group = Group(pod12, pod_text12)
self.play(Create(k8s1))
self.play(Write(k8s_text1))
self.play(FadeIn(deployment1), run_time=1.5)
self.play(FadeIn(dep_text1), run_time=0.5)
self.play(pod2group.animate.shift(RIGHT*0.2).shift(UP*0.2).set_z(1), TransformMatchingShapes(dep_text1, dep_text12))
self.wait(1)
happy_tux = ImageMobject(fr"images/happy_tux.png")
happy_tux.set_height(1.3) # deprecated
happy_tux.to_edge(LEFT)
self.play(FadeIn(happy_tux))
dot1 = Dot(color=http_c)
dot1.move_to(happy_tux.get_edge_center(RIGHT))
dot3 = dot1.copy()
dot2 = dot1.copy().move_to(pod11)
user_interaction = self.say("User sends HTTP requests to app.example.com", False)
# first interactions
tail = TracedPath(dot1.get_center, stroke_color=http_c, stroke_width=2.5, dissipating_time=0.2, stroke_opacity=[1, 0])
self.add(dot1, tail)
self.play(dot1.animate.move_to(dot2))
tail.set_stroke(opacity=[0, 1])
self.play(dot1.animate.move_to(dot3))
self.wait(0.7)
tail.set_stroke(opacity=[1, 0])
self.play(dot1.animate.move_to(dot2))
tail.set_stroke(opacity=[0, 1])
self.play(dot1.animate.move_to(dot3))
self.play(FadeOut(user_interaction))
t = self.say("Oh no! Application went down", False)
self.play(FadeOut(pod_text12), run_time=0.3)
self.remove(pod_text11)
self.play(FadeOut(pod12), run_time=0.6)
self.play(FadeOut(pod11), run_time=0.3)
dep_text13 = Text("App Deployment (0 pods)", color=font_c, font_size=20, font=font).next_to(dep1, UP)
self.play(Transform(dep_text12, dep_text13), run_time=0.7)
tail.set_stroke(opacity=[1, 0])
self.play(dot1.animate.move_to(dot2))
sad_tux = ImageMobject(fr"images/sad_tux.png")
sad_tux.set_height(1.3) # deprecated
sad_tux.to_edge(LEFT)
self.play(Transform(happy_tux, sad_tux))
self.play(FadeOut(t,dot1), run_time=0.5)
self.say("Let's see how k8gb can help here")
self.say("First we need to introduce some redundancy, so let's scale out")
self.play(FadeOut(happy_tux), run_time=0.5)
# zoom out
self.play(self.camera.frame.animate.scale(2))
self.wait(0.2)
k8s2 = Rectangle(width=8.0, height=5.0, color=self.cfg["boxes_color"])
k8s_text2 = Text("Kubernetes", color=font_c, font_size=23, font=font)
k8s_text2.next_to(k8s2, UP)
dep2 = RoundedRectangle(width=3.0, height=2.7, stroke_width=1.0, corner_radius=0.5).set_stroke(GRAY, opacity=0.5).shift(UP*0.1+RIGHT*0.1)
dep_text2 = Text("App Deployment (2 pods)", color=font_c, font_size=20, font=font)
dep_text2.next_to(dep2, UP)
pod21 = Rectangle(width=2.0, height=1.5, color=self.cfg["boxes_color"], fill_color=WHITE, fill_opacity = 1)
pod22 = Rectangle(width=2.0, height=1.5, color=self.cfg["boxes_color"], fill_color=WHITE, fill_opacity = 1)
pod22.shift(RIGHT*0.2).shift(UP*0.2).set_z(1)
pod_text22 = Text("</>", color=http_c, font_size=35, font=self.cfg["code_font"], weight=BOLD)
pod_text22.move_to(pod22)
dep_text14 = Text("App Deployment (2 pods)", color=font_c, font_size=20, font=font).next_to(dep1, UP)
cl1 = Group(k8s1,k8s_text1,dep1, dep_text14, pod11, pod12, pod_text12)
cl2 = Group(k8s2,k8s_text2,dep2, dep_text2, pod21, pod22, pod_text22)
self.add(cl2)
self.remove(pod_text11, dep_text12)
self.play(cl2.animate.move_to(RIGHT*4.6 + UP), cl1.animate.move_to(LEFT* 4.6 + UP))
k8s_text12 = Text("Cluster 1 (eu)", color=font_c, font_size=23, font=font)
k8s_text22 = Text("Cluster 2 (us)", color=font_c, font_size=23, font=font)
k8s_text12.next_to(k8s1, UP)
k8s_text22.next_to(k8s2, UP)
self.play(TransformMatchingShapes(k8s_text1, k8s_text12), TransformMatchingShapes(k8s_text2, k8s_text22))
self.wait(0.5)
# add k8gb
self.say_scaled("Add k8gb operator")
self.play(Group(dep1, dep_text14, pod11, pod12, pod_text12).animate.shift(LEFT*2), Group(dep2, dep_text2, pod21, pod22, pod_text22).animate.shift(LEFT*2))
k8gb1 = ImageMobject(fr"images/k8gb-logo.png")
k8gb1.move_to(dep1).shift(RIGHT*4).scale(1.5)
k8gb2 = ImageMobject(fr"images/k8gb-logo.png")
k8gb2.move_to(dep2).shift(RIGHT*4).scale(1.5)
self.play(FadeIn(Group(k8gb1, k8gb2)), run_time=1.5)
self.say_scaled("Configure k8gb to use edge dns server")
route = ImageMobject(fr"images/route53.png").scale(0.7)
route.to_edge(DOWN).shift(DOWN*1.5)
self.play(FadeIn(route))
self.say_scaled("Setup load balancing strategy")
k8s_text13 = Text("Primary Cluster 1 (eu)", color=font_c, font_size=23, font=font)
k8s_text23 = Text("Secondary Cluster 2 (us)", color=font_c, font_size=23, font=font)
k8s_text13.next_to(k8s1, UP)
k8s_text23.next_to(k8s2, UP)
self.play(TransformMatchingShapes(k8s_text12, k8s_text13), TransformMatchingShapes(k8s_text22, k8s_text23))
self.say_scaled("and edge DNS server")
route_bubble = self.speech_bubble().scale(0.9).next_to(route, direction=RIGHT, buff=0)
self.play(Create(route_bubble))
dns_bubble_title = Text("app.example.com", color=dns_c, font_size=25, font=font)
dns_bubble_title.next_to(route_bubble, direction=UP, buff=0.1).shift(RIGHT*0.3)
self.play(Write(dns_bubble_title))
dns_bubble_r1 = Text("192.168.0.1 (node @ eu)", color=dns_c, font_size=17, font=font)
# dns_bubble_r2 = Text("192.168.0.2 (node 2 @ eu)", dns_c, font_size=18, font=font)
dns_bubble_r1.next_to(dns_bubble_title, direction=DOWN, buff=0.4).shift(RIGHT*0.1)
# dns_bubble_r2.next_to(dns_bubble_r1, direction=DOWN, buff=0.2)
ttl_text = Text("(TTL = 30sec)", color=dns_c, font_size=25, font=font)
ttl_text.next_to(route_bubble, direction=RIGHT)
self.play(Write(dns_bubble_r1), run_time=0.5)
# self.play(Write(dns_bubble_r2), run_time=0.5)
self.play(Write(ttl_text), run_time=1)
self.camera.frame.save_state()
self.play(self.camera.frame.animate.scale(0.35).move_to(route_bubble))
self.wait(0.2)
detail_font = 11
dns_bubble_r1_detailed1 = Text(";; AUTHORITY SECTION:", color=dns_c, font_size=detail_font, font=font)
dns_bubble_r1_detailed2 = Text("example.com. 30 IN NS gslb-ns-us-app.example.com.", color=dns_c, font_size=detail_font, font=font)
dns_bubble_r1_detailed3 = Text("example.com. 30 IN NS gslb-ns-eu-app.example.com.", color=dns_c, font_size=detail_font, font=font)
dns_bubble_r1_detailed4 = Text(";; ADDITIONAL SECTION:", color=dns_c, font_size=detail_font, font=font)
dns_bubble_r1_detailed5 = Text("gslb-ns-us-app.example.com. 30 IN A 10.0.0.1", color=dns_c, font_size=detail_font, font=font)
dns_bubble_r1_detailed6 = Text("gslb-ns-eu-app.example.com. 30 IN A 10.0.1.1", color=dns_c, font_size=detail_font, font=font)
detailed_dns = VGroup(dns_bubble_r1_detailed1,dns_bubble_r1_detailed2,dns_bubble_r1_detailed3,dns_bubble_r1_detailed4,dns_bubble_r1_detailed5,dns_bubble_r1_detailed6)
detailed_dns.arrange(DOWN, center=False, buff=0.1, aligned_edge=LEFT)
detailed_dns.next_to(dns_bubble_title, direction=DOWN, buff=0.3).shift(RIGHT*0.2)
self.play(FadeOut(dns_bubble_r1))
self.play(FadeIn(detailed_dns))
self.say_zoomed("In fact it's a glue record that enables the zone delegation")
self.say_zoomed("Route53 is recursive DNS server delegating the calls for our domain to one of our internal CoreDNS servers", wait=2.7)
self.say_zoomed("K8gb controller makes sure that CoreDNS contains updated DNS records based on the load balancing strategy", wait=2.7)
self.say_zoomed("For the sake of simplicity, let's pretend it can directly resolve app.example.com to one of the k8s nodes", wait=2.7)
self.play(FadeOut(detailed_dns))
self.play(FadeIn(dns_bubble_r1))
self.play(Restore(self.camera.frame))
self.say_scaled("Let's look how failover strategy works")
# show tux again
happy_tux2 = ImageMobject(fr"images/happy_tux.png")
happy_tux2.scale(0.7)
happy_tux2.move_to(self.camera.frame.get_left()).shift(RIGHT*1.5+DOWN*3)
happy_tux2_orig = happy_tux2.copy()
dot_dns = Dot(color=dns_c, radius=DEFAULT_DOT_RADIUS*2).move_to(self.camera.frame.get_left()).shift(RIGHT*1.5+UP*1)
dot_http = Dot(color=http_c, radius=DEFAULT_DOT_RADIUS*2).next_to(dot_dns, direction=DOWN, buff=0.5)
dot_dns_text = Text("dns resolution", font_size=24, color=dns_c, font=font).next_to(dot_dns, direction=RIGHT, buff=0.7)
dot_http_text = Text("HTTP request", font_size=24, color=http_c, font=font).next_to(dot_http, direction=RIGHT, buff=0.7)
dot_legend = VGroup(dot_dns, dot_http, dot_dns_text, dot_http_text)
self.play(FadeIn(happy_tux2, dot_legend), run_time=0.5)
dot_t = dot1.scale(2).move_to(happy_tux2.get_edge_center(RIGHT)).copy()
dot_moving = dot_t.copy()
tail2 = TracedPath(dot_moving.get_center, stroke_color=dns_c, stroke_width=5, dissipating_time=0.2, stroke_opacity=[1, 0])
dot_r = dot_t.copy().move_to(route)
dot_c1 = dot_t.copy().move_to(pod11)
dot_c2 = dot_t.copy().move_to(pod21)
self.say_scaled("Tux wants to send http request to app.example.com")
self.say_scaled("He asks the Route53 to resolve 'app.example.com'")
dot_moving.set_color(dns_c)
self.add(dot_moving, tail2)
self.play(dot_moving.animate.move_to(dot_r))
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t))
self.wait(0.4)
self.say_scaled("For the next 30 seconds it's 192.168.0.1")
tail2.set_stroke(opacity=[1, 0], color=http_c)
dot_moving.set_color(http_c)
dot_rt = 0.5
self.play(dot_moving.animate.move_to(dot_c1), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
tail2.set_stroke(opacity=[1, 0])
self.play(dot_moving.animate.move_to(dot_c1), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
tail2.set_stroke(opacity=[1, 0])
self.play(dot_moving.animate.move_to(dot_c1), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
self.say_scaled("Oh no! The pods on cluster in eu went down.")
# scale pods on cl1 to 0
pod_text12.add_updater(lambda x: x.move_to(pod12.get_center()))
self.play(pod12.animate.move_to(pod11), run_time=0.4)
self.play(FadeOut(pod_text12), run_time=0.3)
dep_text13.next_to(dep1, UP)
self.play(FadeOut(VGroup(pod11, pod12)), Transform(dep_text14, dep_text13))
# make tux sad
sad_tux2 = ImageMobject(fr"images/sad_tux.png")
sad_tux2.scale(0.7)
sad_tux2.move_to(self.camera.frame.get_left()).shift(RIGHT*1.5+DOWN*3)
self.play(Transform(happy_tux2, sad_tux2), run_time=1.5)
self.say_scaled("Luckily, k8gb controller on cluster 1 kicks in")
self.play(Wiggle(k8gb1))
self.say_scaled("and updates the DNS records to point to cluster 2")
# change the records in the bubble
dns_bubble_r3 = Text("192.168.1.1 (node @ us)", color=dns_c, font_size=17, font=font)
# dns_bubble_r4 = Text("192.168.1.2 (node 2 @ us)", dns_c, font_size=18, font=font)
dns_bubble_r3.next_to(dns_bubble_title, direction=DOWN, buff=0.4).shift(RIGHT*0.1)
# dns_bubble_r4.next_to(dns_bubble_r1, direction=DOWN, buff=0.2)
self.play(Unwrite(dns_bubble_r1), run_time=0.5)
# self.play(Unwrite(dns_bubble_r2), run_time=0.5)
self.play(Write(dns_bubble_r3), run_time=0.5)
# self.play(Write(dns_bubble_r4), run_time=0.5)
self.say_scaled("When TTL expires, Tux creates another DNS request")
dot_rt = 0.8
dot_moving.set_color(dns_c)
tail2.set_stroke(opacity=[1, 0], color=dns_c)
self.play(dot_moving.animate.move_to(dot_r), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
self.say_scaled("and starts communicating with the correct cluster")
dot_moving.set_color(http_c)
tail2.set_stroke(opacity=[1, 0], color=http_c)
self.play(dot_moving.animate.move_to(dot_c2), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
tail2.set_stroke(opacity=[1, 0])
self.play(dot_moving.animate.move_to(dot_c2), run_time=dot_rt)
tail2.set_stroke(opacity=[0, 1])
self.play(dot_moving.animate.move_to(dot_t), run_time=dot_rt)
# make tux happy
self.play(Transform(happy_tux2, happy_tux2_orig), run_time=1.5)
self.say_scaled("Cluster in 'us' took over all the communication and Tux is happy again")
self.say_scaled("Once the pods on cluster 1 are ok, it'll switch the communication back to the eu cluster")
self.wait()
self.play(
*[FadeOut(mob)for mob in self.mobjects]
)
self.play(FadeIn(ImageMobject(fr"images/k8gb-logo.png").scale(2.5)))
self.play(Write(Text("k8gb.io", color=font_c, font_size=55, font=font).shift(DOWN*2)), run_time=2)
self.wait()
def say_zoomed(self, what, ephemeral=True, wait=1.5):
if self.cfg["no_text"]:
return Text("")
t = Text(what, color=self.cfg["font_color"], font_size=14, font=self.cfg["font"])
t.move_to(self.camera.frame.get_right() + self.camera.frame.get_bottom()).shift(UP*4.5+LEFT*(4.8+t.width*0.48))
self.play(Write(t))
if ephemeral:
self.wait(wait)
self.play(FadeOut(t))
else:
return t
def say(self, what, ephemeral=True):
if self.cfg["no_text"]:
return Text("")
t = Text(what, color=self.cfg["font_color"], font_size=23, font=self.cfg["font"])
t.to_edge(DR, buff=0.5)
self.play(Write(t))
if ephemeral:
self.wait(1)
self.play(FadeOut(t))
else:
return t
def say_scaled(self, what, ephemeral=True):
if self.cfg["no_text"]:
return Text("")
t = Text(what, color=self.cfg["font_color"], font_size=46, font=self.cfg["font"])
t.move_to(self.camera.frame.get_right() + self.camera.frame.get_bottom()).shift(UP*1.5+LEFT*(t.width*0.6))
self.play(Write(t))
if ephemeral:
self.wait(1)
self.play(FadeOut(t))
else:
return t
def speech_bubble(self):
Bubble = [(0,0,0),
(1.0,-0.1, 0),
(1.0, 0.7, 0),
(5.9, 0.7, 0),
(5.9,-1.7, 0),
(1.0,-1.7, 0),
(1.0,-0.55,0),
]
return Polygon(*Bubble, color=self.cfg["dns_color"])
class Dummy(MovingCameraScene):
def construct(self):
text=Text("Hello k8gb")
self.play(Write(text))
self.wait()