{"id":454243,"date":"2025-04-01T17:28:32","date_gmt":"2025-04-01T17:28:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=454243"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=454243","title":{"rendered":"<span>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c livenessProbe \u0434\u043b\u044f Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0438\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0442 \u2014 \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u0431\u0435\u0437 \u043f\u0430\u0434\u0435\u043d\u0438\u0439, \u043d\u043e \u0438 \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. LivenessProbe \u0432 Kubernetes \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043d\u043e \u0441 Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430\u043c\u0438 \u0432\u0441\u0451 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u0442. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c livenessProbe \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u00a0<strong>Heartbeat<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0438\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<h2>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h2>\n<ul>\n<li>\n<p><a href=\"#1\">\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d livenessProbe<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#2\">\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f livenessProbe \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0442\u0442\u0435\u0440\u043d HeartBeat<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 python<\/a><\/p>\n<ul>\n<li>\n<p><a href=\"#5\">\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 HeartBeat<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#7\">FileHeartBeat &#8212; \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#8\">FileHeartBeat &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0436\u0438\u0432 \u043b\u0438 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#9\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#10\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 CLI<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#11\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 livenessProbe<\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#12\">\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#13\">\u0412\u044b\u0432\u043e\u0434\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#13\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d livenessProbe<\/h3>\n<p>\u0412 Kubernetes <strong>livenessProbe<\/strong> \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434 (\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435) \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u043ec\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0415\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 <strong>API<\/strong> \u043d\u0430 <strong>FastAPI<\/strong>, \u0442\u043e \u043c\u044b \u0431\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 <strong>HTTP<\/strong> \u043a\u043e\u0434 <strong>200<\/strong> \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u043b\u043e \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u2013 <strong>livenessProbe<\/strong> \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0431\u044b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/276\/60a\/cd8\/27660acd8bc125f1264166c2fada7a43.png\" alt=\"Kubernetes \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e livenessProbe \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438\" title=\"Kubernetes \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e livenessProbe \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438\" width=\"3017\" height=\"3108\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/276\/60a\/cd8\/27660acd8bc125f1264166c2fada7a43.png\"\/><\/p>\n<div><figcaption>Kubernetes \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e livenessProbe \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438<\/figcaption><\/div>\n<\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 livenessProbe \u0434\u043b\u044f Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 <\/h3>\n<p>\u0414\u043b\u044f Kafka Consumer \u043d\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u0445\u043e\u0434\u0443 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438, \u0433\u0434\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 <strong>\u0421onsumer lag<\/strong>, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u0442\u0430\u043a-\u043a\u0430\u043a \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <strong>\u043b\u0430\u0433\u0430<\/strong> \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u0438\u043b\u0438 \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439. <\/p>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0440\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 (\u0443\u0432\u044b, \u043d\u0435 \u0432\u0441\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0436\u0438\u0437\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b):<\/p>\n<ul>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>consumer lag <\/strong>(<strong>\u043d\u0435\u0442\u043e\u0447\u043d\u044b\u0439<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>unix<\/strong> \u0441\u0438\u0433\u043d\u0430\u043b\u044b (\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441 \u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u041e\u0421, <strong>\u043d\u0435\u0442\u043e\u0447\u043d\u044b\u0439<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 <strong>\u043c\u0435\u0442\u0440\u0438\u043a\u0438<\/strong> \u043a\u0430\u0444\u043a\u0438 (<strong>\u0441\u043b\u043e\u0436\u043d\u043e<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <strong>heartbeat<\/strong> \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0435 (<strong>\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e <\/strong>\u0438<strong> \u0442\u043e\u0447\u043d\u043e<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 <strong>health<\/strong> \u0442\u043e\u043f\u0438\u043a\u0438 \u0438 \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0442\u043a\u0443 \u0432 <strong>livenessProbe <\/strong>(<strong>\u0442\u043e\u0447\u043d\u043e<\/strong>,<strong> <\/strong>\u043d\u043e<strong> \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e<\/strong>)<\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f livenessProbe \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0442\u0442\u0435\u0440\u043d HeartBeat \u2764\ufe0f<\/h3>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0445\u0430\u0440\u0442\u0431\u0438\u0442\u043e\u0432 \u0432 \u043b\u044e\u0431\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0432\u0435\u0440\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434, \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0437\u0430\u0432\u0438\u0441 \u0438 \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0437 \u0442\u043e\u043f\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043d\u0435\u043a\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0432 \u0444\u0430\u0439\u043b. Kubernetes \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0444\u0430\u0439\u043b, \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/25f\/41d\/04c\/25f41d04ca88338cc6ea91f0e762cdab.png\" alt=\"\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430\" title=\"\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430\" width=\"4615\" height=\"4049\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/25f\/41d\/04c\/25f41d04ca88338cc6ea91f0e762cdab.png\"\/><\/p>\n<div><figcaption>\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Python<\/h3>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430, \u0430 \u0434\u043b\u044f <strong>Kubernetes<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h4>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 HeartBeat<\/h4>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c <em>\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/em> <strong>HeartBeat<\/strong>, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b <strong>save<\/strong> \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f <strong>heartbeat<\/strong> \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u2013 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <strong>\u0444\u0430\u0439\u043b<\/strong>, \u0432 <strong>\u0440\u0435\u0434\u0438\u0441<\/strong> \u0438\u043b\u0438 <strong>\u0411\u0414<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/13e\/da5\/db0\/13eda5db0f0393f13cebf0c4948421fd.png\" width=\"4428\" height=\"1994\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13e\/da5\/db0\/13eda5db0f0393f13cebf0c4948421fd.png\"\/><\/figure>\n<pre><code class=\"python\">import abc  class HeartBeat(abc.ABC):     @abc.abstractmethod     def save(self) -&gt; None:         \"\"\"Save timestamp data to mark that worker is alive.\"\"\"              @abc.abstractmethod     def is_alive(self) -&gt; bool:         \"\"\"Check that worker is alive.\"\"\"        <\/code><\/pre>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e heartbeat. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0445\u043e\u0441\u0442\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f. \u0418 \u0434\u043e\u043b\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0432 JSON.<\/p>\n<pre><code class=\"json\">{     \"host_id\": \"00000000-0000-0000-0000-0242ac160007\",      \"last_beat\": \"2023-12-08T09:38:01.255909+00:00\" }<\/code><\/pre>\n<pre><code class=\"python\">class HeartBeatState(BaseModel):     host_id: str     last_beat: datetime<\/code><\/pre>\n<p><a class=\"anchor\" name=\"7\" id=\"7\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b \u2013 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <strong>FileHeartBeat. <\/strong>\u041f\u0440\u0438\u0434\u0443\u043c\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u0443 \u0438\u043c\u044f, \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043a \u043d\u0435\u043c\u0443 \u043f\u0443\u0442\u044c, \u0437\u0430\u0442\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c <strong>HeartBeat<\/strong> \u0432 JSON \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0444\u0430\u0439\u043b\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/883\/abf\/b28\/883abfb282e49830417f0b854068ccad.png\" width=\"3261\" height=\"750\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/883\/abf\/b28\/883abfb282e49830417f0b854068ccad.png\"\/><\/figure>\n<pre><code class=\"python\">HEART_BEAT_FILE_NAME = \"heartbeat.json\"  logger = logging.getLogger(__name__)   class FileHeartBeat(HeartBeat):     \"\"\"     Save heartbeats to a file to check if consumer is alive by livenessProbe.     \"\"\"      def save(self):         \"\"\"Save heartbeat timestamp data to indicate that worker is alive.\"\"\"         heartbeat_file_path = self._retrieve_heartbeat_file_path()         host_id = uuid.UUID(int=uuid.getnode())         last_beat = now()          state = HeartBeatState(             host_id=str(host_id),             last_beat=last_beat,         )         self._save_state_to_file(heartbeat_file_path, state)      def _save_state_to_file(             self,              heartbeat_file_path: Path,              state: HeartBeatState,     ) -&gt; None:         \"\"\"Save heartbeat timestamp and other information in a file.\"\"\"         logger.info(\"Saving heart beat to file: %s, %s\", heartbeat_file_path, str(state.json()))          with open(heartbeat_file_path, \"w+\") as worker_heartbeat_file:             worker_heartbeat_file.write(state.json())       def _retrieve_heartbeat_file_path(self) -&gt; Path:         \"\"\"Construct file path where heartbeat info is located.\"\"\"          base_dir = Path(settings.BASE_DIR)          heartbeat_file_name = HEART_BEAT_FILE_NAME         heartbeat_file_path = base_dir.joinpath(heartbeat_file_name)          return heartbeat_file_path <\/code><\/pre>\n<p><a class=\"anchor\" name=\"8\" id=\"8\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0436\u0438\u0432 \u043b\u0438 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0436\u0438\u0432, \u043e\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>is_alive<\/code>. \u041f\u0440\u043e\u0447\u0442\u0435\u043c \u0444\u0430\u0439\u043b, \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 JSON \u0432 \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0448\u043b\u043e \u0441\u0435\u043a\u0443\u043d\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430. \u0415\u0441\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u043c\u0435\u0440\u0442\u0432\u044b\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a21\/4db\/a06\/a214dba0623c9feb3007d8a2bfd6ac99.png\" width=\"3217\" height=\"998\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a21\/4db\/a06\/a214dba0623c9feb3007d8a2bfd6ac99.png\"\/><\/figure>\n<pre><code class=\"python\">class FileHeartBeat(HeartBeat):     \"\"\"     Saves heartbeats to a file to check if consumer is alive by livenessProbe.     \"\"\"      def is_alive(self, max_time_after_worker_dead: int = 15) -&gt; bool:         \"\"\" Main livenessProbe method to check if consumer is healthy. \"\"\"         heartbeat_file_path = self._retrieve_heartbeat_file_path()          try:             logger.info(\"Trying to check heartbeat file: %s\", heartbeat_file_path)             heart_beat_stats = self._read_heartbeat_file(heartbeat_file_path)         except FileNotFoundError:             logger.error(\"Heartbeat file not found: %s\", heartbeat_file_path)              return False          logger.info(\"Got last heartbeat info: %s\", str(heart_beat_stats.json()))          time_after_last_beat = now() - heart_beat_stats.last_beat         if time_after_last_beat.seconds &gt; max_time_after_worker_dead:             logger.error(                 \"Worker is dead. Time since last beat %s &gt; %s\",                 time_after_last_beat.seconds,                 time_offset,             )             return False          logger.info(             \"Worker is alive. Time since last beat %s &lt; %s\",             time_after_last_beat.seconds,             time_offset,         )         return True      def _read_heartbeat_file(self, heartbeat_file_path: Path) -&gt; HeartBeatState:         \"\"\"Read heartbeat timestamp and other information from a file.\"\"\"         with open(heartbeat_file_path) as worker_heartbeat_file:             heart_beat_stats_json: dict = json.load(worker_heartbeat_file)             heart_beat_state = HeartBeatState(**heart_beat_stats_json)              return heart_beat_state      def _retrieve_heartbeat_file_path(self) -&gt; Path:         \"\"\"Construct file path where heartbeat info is located.\"\"\"          base_dir = Path(settings.BASE_DIR)          heartbeat_file_name = HEART_BEAT_FILE_NAME         heartbeat_file_path = base_dir.joinpath(heartbeat_file_name)          return heartbeat_file_path <\/code><\/pre>\n<p><a class=\"anchor\" name=\"9\" id=\"9\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/h4>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u0434 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u0436\u0438\u0432\u044b.<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b6a\/915\/71f\/b6a91571fad8abc26866273b452e840f.png\" width=\"2604\" height=\"2243\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b6a\/915\/71f\/b6a91571fad8abc26866273b452e840f.png\"\/><\/figure>\n<pre><code class=\"python\">@dataclasses.dataclass class ConfluentKafkaConsumer:     heart_beat: HeartBeat      def run(self):         consumer = ...         ....                  while True:             message: ConfluentKafkaMessage = consumer.poll(2.0)             self.heart_beat.save()              if not message:                 # No message received                 continue              self._process_message(message)   confluent_kafka_consumer = ConfluentKafkaConsumer(     heart_beat=FileHeartBeat(), )<\/code><\/pre>\n<p><a class=\"anchor\" name=\"10\" id=\"10\"><\/a><\/p>\n<h4>FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 CLI<\/h4>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c CLI-\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 Kubernetes \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e\u0440\u043a\u0435\u0440 \u0436\u0438\u0432 \u0438\u043b\u0438 \u0443\u043c\u0435\u0440. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430:<\/p>\n<pre><code class=\"python\">ERROR_CODE = 1  ... # Your CLI  def health_check(max_time: Optional[int]):     heart_beat = FileHeartBeat()      is_alive = heart_beat.is_alive(max_time_after_worker_dead=max_time)      if not is_alive:         sys.exit(ERROR_CODE)<\/code><\/pre>\n<h4>FileHeartBeat \u2013 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 livenessProbe<\/h4>\n<p>\u0412 helm \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c <code>livenessProbe<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434. \u0423 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Django, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e. <\/p>\n<pre><code class=\"yaml\">    livenessProbe:       exec:         command:         - .\/manage.py         - consumer         - is_alive         - --max_time         - \"30\"<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u041c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b. \u041a\u043e\u0434 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439. <\/p>\n<p><a class=\"anchor\" name=\"11\" id=\"11\"><\/a><\/p>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 <strong>Heartbeat<\/strong> \u0432 <strong>\u0411\u0414<\/strong> \u0438\u043b\u0438 <strong>Redis<\/strong>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u0432. <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0439\u0442\u0438 \u0435\u0449\u0451 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0444\u0444\u0441\u0435\u0442\u044b \u0432 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 (\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0433\u0440\u0443\u043f\u043f\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430)<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p><a class=\"anchor\" name=\"12\" id=\"12\"><\/a><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b \u270d\ufe0f<\/h3>\n<p>\u0418\u0437 \u043e\u043f\u044b\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0433\u0443 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 <strong>Heartbeat<\/strong> \u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b \u0440\u0443\u043a\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. <\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0435\u0434\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u0442\u043e\u0447\u043d\u044b\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044e \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430\u043c\u0438 \u2013 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>Redis<\/strong>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u0434\u0435\u0432\u043e\u043f\u0441\u043e\u0432 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0430\u0434\u043c\u0438\u043d\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"13\" id=\"13\"><\/a><\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \ud83d\udcda<\/h3>\n<p>\u0412\u043e\u0442, \u0447\u0442\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/cloud.theodo.com\/en\/blog\/kubernetes-probes\">How to use probes in Kubernetes?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/blog.algomaster.io\/p\/heartbeats-in-distributed-systems\">HeartBeats: How Distributed Systems Stay Alive<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/kestra.io\/blogs\/2024-04-22-liveness-heartbeat\">Building A New Liveness and Heartbeat Mechanism For Better Reliability<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/blog.cloudflare.com\/intelligent-automatic-restarts-for-unhealthy-kafka-consumers\/\">Intelligent, automatic restarts for unhealthy Kafka consumers<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/blog.promaton.com\/a-simple-solution-for-configuring-liveness-probes-for-queue-consumers-in-kubernetes-2897930382ca\">A Simple Solution for Configuring Liveness Probes for Queue Consumers in Kubernetes<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/880684\/\"> https:\/\/habr.com\/ru\/articles\/880684\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u0430\u043a \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0442 \u2014 \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u0431\u0435\u0437 \u043f\u0430\u0434\u0435\u043d\u0438\u0439, \u043d\u043e \u0438 \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. LivenessProbe \u0432 Kubernetes \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043d\u043e \u0441 Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430\u043c\u0438 \u0432\u0441\u0451 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e: \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u0442. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c livenessProbe \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u00a0<strong>Heartbeat<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0438\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<h2>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h2>\n<ul>\n<li>\n<p><a href=\"#1\">\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d livenessProbe<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#2\">\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f livenessProbe \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0442\u0442\u0435\u0440\u043d HeartBeat<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 python<\/a><\/p>\n<ul>\n<li>\n<p><a href=\"#5\">\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 HeartBeat<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#7\">FileHeartBeat &#8212; \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#8\">FileHeartBeat &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0436\u0438\u0432 \u043b\u0438 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#9\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#10\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 CLI<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#11\">FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 livenessProbe<\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#12\">\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#13\">\u0412\u044b\u0432\u043e\u0434\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#13\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d livenessProbe<\/h3>\n<p>\u0412 Kubernetes <strong>livenessProbe<\/strong> \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434 (\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435) \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u043ec\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0415\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 <strong>API<\/strong> \u043d\u0430 <strong>FastAPI<\/strong>, \u0442\u043e \u043c\u044b \u0431\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 <strong>HTTP<\/strong> \u043a\u043e\u0434 <strong>200<\/strong> \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u043b\u043e \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u2013 <strong>livenessProbe<\/strong> \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0431\u044b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Kubernetes \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e livenessProbe \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438<\/figcaption><\/div>\n<\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 livenessProbe \u0434\u043b\u044f Kafka-\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 <\/h3>\n<p>\u0414\u043b\u044f Kafka Consumer \u043d\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u0445\u043e\u0434\u0443 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438, \u0433\u0434\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 <strong>\u0421onsumer lag<\/strong>, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u0442\u0430\u043a-\u043a\u0430\u043a \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <strong>\u043b\u0430\u0433\u0430<\/strong> \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u0438\u043b\u0438 \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439. <\/p>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0440\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 (\u0443\u0432\u044b, \u043d\u0435 \u0432\u0441\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0436\u0438\u0437\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b):<\/p>\n<ul>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>consumer lag <\/strong>(<strong>\u043d\u0435\u0442\u043e\u0447\u043d\u044b\u0439<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>unix<\/strong> \u0441\u0438\u0433\u043d\u0430\u043b\u044b (\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441 \u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u041e\u0421, <strong>\u043d\u0435\u0442\u043e\u0447\u043d\u044b\u0439<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 <strong>\u043c\u0435\u0442\u0440\u0438\u043a\u0438<\/strong> \u043a\u0430\u0444\u043a\u0438 (<strong>\u0441\u043b\u043e\u0436\u043d\u043e<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <strong>heartbeat<\/strong> \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0435 (<strong>\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e <\/strong>\u0438<strong> \u0442\u043e\u0447\u043d\u043e<\/strong>);<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 <strong>health<\/strong> \u0442\u043e\u043f\u0438\u043a\u0438 \u0438 \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0442\u043a\u0443 \u0432 <strong>livenessProbe <\/strong>(<strong>\u0442\u043e\u0447\u043d\u043e<\/strong>,<strong> <\/strong>\u043d\u043e<strong> \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e<\/strong>)<\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f livenessProbe \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0442\u0442\u0435\u0440\u043d HeartBeat \u2764\ufe0f<\/h3>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0445\u0430\u0440\u0442\u0431\u0438\u0442\u043e\u0432 \u0432 \u043b\u044e\u0431\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0432\u0435\u0440\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434, \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0437\u0430\u0432\u0438\u0441 \u0438 \u043d\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0437 \u0442\u043e\u043f\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u043d\u0435\u043a\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0432 \u0444\u0430\u0439\u043b. Kubernetes \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0444\u0430\u0439\u043b, \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 livenessProbe \u0434\u043b\u044f \u043a\u0430\u0444\u043a\u0430 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 Python<\/h3>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430, \u0430 \u0434\u043b\u044f <strong>Kubernetes<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h4>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 HeartBeat<\/h4>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c <em>\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/em> <strong>HeartBeat<\/strong>, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b <strong>save<\/strong> \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f <strong>heartbeat<\/strong> \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u2013 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <strong>\u0444\u0430\u0439\u043b<\/strong>, \u0432 <strong>\u0440\u0435\u0434\u0438\u0441<\/strong> \u0438\u043b\u0438 <strong>\u0411\u0414<\/strong>.<\/p>\n<figure class=\"full-width\"><\/figure>\n<pre><code class=\"python\">import abc  class HeartBeat(abc.ABC):     @abc.abstractmethod     def save(self) -&gt; None:         \"\"\"Save timestamp data to mark that worker is alive.\"\"\"              @abc.abstractmethod     def is_alive(self) -&gt; bool:         \"\"\"Check that worker is alive.\"\"\"        <\/code><\/pre>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e heartbeat. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0445\u043e\u0441\u0442\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f. \u0418 \u0434\u043e\u043b\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0432 JSON.<\/p>\n<pre><code class=\"json\">{     \"host_id\": \"00000000-0000-0000-0000-0242ac160007\",      \"last_beat\": \"2023-12-08T09:38:01.255909+00:00\" }<\/code><\/pre>\n<pre><code class=\"python\">class HeartBeatState(BaseModel):     host_id: str     last_beat: datetime<\/code><\/pre>\n<p><a class=\"anchor\" name=\"7\" id=\"7\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b \u2013 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <strong>FileHeartBeat. <\/strong>\u041f\u0440\u0438\u0434\u0443\u043c\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u0443 \u0438\u043c\u044f, \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043a \u043d\u0435\u043c\u0443 \u043f\u0443\u0442\u044c, \u0437\u0430\u0442\u0435\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c <strong>HeartBeat<\/strong> \u0432 JSON \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0444\u0430\u0439\u043b\u0435.<\/p>\n<figure class=\"full-width\"><\/figure>\n<pre><code class=\"python\">HEART_BEAT_FILE_NAME = \"heartbeat.json\"  logger = logging.getLogger(__name__)   class FileHeartBeat(HeartBeat):     \"\"\"     Save heartbeats to a file to check if consumer is alive by livenessProbe.     \"\"\"      def save(self):         \"\"\"Save heartbeat timestamp data to indicate that worker is alive.\"\"\"         heartbeat_file_path = self._retrieve_heartbeat_file_path()         host_id = uuid.UUID(int=uuid.getnode())         last_beat = now()          state = HeartBeatState(             host_id=str(host_id),             last_beat=last_beat,         )         self._save_state_to_file(heartbeat_file_path, state)      def _save_state_to_file(             self,              heartbeat_file_path: Path,              state: HeartBeatState,     ) -&gt; None:         \"\"\"Save heartbeat timestamp and other information in a file.\"\"\"         logger.info(\"Saving heart beat to file: %s, %s\", heartbeat_file_path, str(state.json()))          with open(heartbeat_file_path, \"w+\") as worker_heartbeat_file:             worker_heartbeat_file.write(state.json())       def _retrieve_heartbeat_file_path(self) -&gt; Path:         \"\"\"Construct file path where heartbeat info is located.\"\"\"          base_dir = Path(settings.BASE_DIR)          heartbeat_file_name = HEART_BEAT_FILE_NAME         heartbeat_file_path = base_dir.joinpath(heartbeat_file_name)          return heartbeat_file_path <\/code><\/pre>\n<p><a class=\"anchor\" name=\"8\" id=\"8\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0436\u0438\u0432 \u043b\u0438 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/h4>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0436\u0438\u0432, \u043e\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>is_alive<\/code>. \u041f\u0440\u043e\u0447\u0442\u0435\u043c \u0444\u0430\u0439\u043b, \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 JSON \u0432 \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0448\u043b\u043e \u0441\u0435\u043a\u0443\u043d\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u0438\u0442\u0430. \u0415\u0441\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u043c\u0435\u0440\u0442\u0432\u044b\u043c.<\/p>\n<figure class=\"full-width\"><\/figure>\n<pre><code class=\"python\">class FileHeartBeat(HeartBeat):     \"\"\"     Saves heartbeats to a file to check if consumer is alive by livenessProbe.     \"\"\"      def is_alive(self, max_time_after_worker_dead: int = 15) -&gt; bool:         \"\"\" Main livenessProbe method to check if consumer is healthy. \"\"\"         heartbeat_file_path = self._retrieve_heartbeat_file_path()          try:             logger.info(\"Trying to check heartbeat file: %s\", heartbeat_file_path)             heart_beat_stats = self._read_heartbeat_file(heartbeat_file_path)         except FileNotFoundError:             logger.error(\"Heartbeat file not found: %s\", heartbeat_file_path)              return False          logger.info(\"Got last heartbeat info: %s\", str(heart_beat_stats.json()))          time_after_last_beat = now() - heart_beat_stats.last_beat         if time_after_last_beat.seconds &gt; max_time_after_worker_dead:             logger.error(                 \"Worker is dead. Time since last beat %s &gt; %s\",                 time_after_last_beat.seconds,                 time_offset,             )             return False          logger.info(             \"Worker is alive. Time since last beat %s &lt; %s\",             time_after_last_beat.seconds,             time_offset,         )         return True      def _read_heartbeat_file(self, heartbeat_file_path: Path) -&gt; HeartBeatState:         \"\"\"Read heartbeat timestamp and other information from a file.\"\"\"         with open(heartbeat_file_path) as worker_heartbeat_file:             heart_beat_stats_json: dict = json.load(worker_heartbeat_file)             heart_beat_state = HeartBeatState(**heart_beat_stats_json)              return heart_beat_state      def _retrieve_heartbeat_file_path(self) -&gt; Path:         \"\"\"Construct file path where heartbeat info is located.\"\"\"          base_dir = Path(settings.BASE_DIR)          heartbeat_file_name = HEART_BEAT_FILE_NAME         heartbeat_file_path = base_dir.joinpath(heartbeat_file_name)          return heartbeat_file_path <\/code><\/pre>\n<p><a class=\"anchor\" name=\"9\" id=\"9\"><\/a><\/p>\n<h4>FileHeartBeat \u2013 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440<\/h4>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u0434 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u0436\u0438\u0432\u044b.<\/p>\n<figure class=\"bordered full-width\"><\/figure>\n<pre><code class=\"python\">@dataclasses.dataclass class ConfluentKafkaConsumer:     heart_beat: HeartBeat      def run(self):         consumer = ...         ....                  while True:             message: ConfluentKafkaMessage = consumer.poll(2.0)             self.heart_beat.save()              if not message:                 # No message received                 continue              self._process_message(message)   confluent_kafka_consumer = ConfluentKafkaConsumer(     heart_beat=FileHeartBeat(), )<\/code><\/pre>\n<p><a class=\"anchor\" name=\"10\" id=\"10\"><\/a><\/p>\n<h4>FileHeartBeat &#8212; \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 CLI<\/h4>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c CLI-\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 Kubernetes \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e\u0440\u043a\u0435\u0440 \u0436\u0438\u0432 \u0438\u043b\u0438 \u0443\u043c\u0435\u0440. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430:<\/p>\n<pre><code class=\"python\">ERROR_CODE = 1  ... # Your CLI  def health_check(max_time: Optional[int]):     heart_beat = FileHeartBeat()      is_alive = heart_beat.is_alive(max_time_after_worker_dead=max_time)      if not is_alive:         sys.exit(ERROR_CODE)<\/code><\/pre>\n<h4>FileHeartBeat \u2013 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0432 livenessProbe<\/h4>\n<p>\u0412 helm \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c <code>livenessProbe<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434. \u0423 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Django, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e. <\/p>\n<pre><code class=\"yaml\">    livenessProbe:       exec:         command:         - .\/manage.py         - consumer         - is_alive         - --max_time         - \"30\"<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u041c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b. \u041a\u043e\u0434 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439. <\/p>\n<p><a class=\"anchor\" name=\"11\" id=\"11\"><\/a><\/p>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 <strong>Heartbeat<\/strong> \u0432 <strong>\u0411\u0414<\/strong> \u0438\u043b\u0438 <strong>Redis<\/strong>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u0432. <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0439\u0442\u0438 \u0435\u0449\u0451 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0444\u0444\u0441\u0435\u0442\u044b \u0432 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 (\u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440 \u0433\u0440\u0443\u043f\u043f\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430)<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p><a class=\"anchor\" name=\"12\" id=\"12\"><\/a><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b \u270d\ufe0f<\/h3>\n<p>\u0418\u0437 \u043e\u043f\u044b\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0433\u0443 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 <strong>Heartbeat<\/strong> \u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u044b \u0440\u0443\u043a\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. <\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0435\u0434\u0438<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-454243","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=454243"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/454243\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=454243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=454243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=454243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}