In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
PS: recently refactoring the company's business containerization platform, recording a piece. With regard to container logs, kubernetes python API itself provides log streaming data, which will not output new data in previous versions, which has been improved in subsequent versions.
Directly go to the code Flask front-end route block # Router "get the project pod log" @ api_cluster_pod.route ('/ pod//log') @ env_rulesdef api_cluster_pod_log (env, cluster_name, pod_name): "" View pod's log "" tail_lines = request.values.get ("tail_lines", 1000) namespace = request.values.get ("namespace") "") # generate Config Object try: cluster_config = ClusterConfig (env=env, cluster_name=cluster_name, namespace=namespace) except Exception as e: return jsonify (dict (code=5000, message=') did not find the corresponding entry when obtaining the cluster interface Information: {0} '.format (str (e) try: poder = Pod (cluster_config) resp = Response (stream_with_context (poder.get_pod_log (pod_name, tail_lines)), mimetype= "text/plain") return resp except Exception as e: return jsonify (dict (code=7000) Message=str (e)) Flask backend code block # background function class Pod:. Def get_pod_log (self, pod_name, tail_lines=100): "get the log of pod: param tail_lines: # shows the last number of lines: return:" try: # stream pod log streams = self.cluster.api.read_namespaced_pod_log (pod_name Self.cluster_config.namespace, follow=True, _ preload_content=False Tail_lines=tail_lines) .stream () return streams except ApiException as e: if e.status = = 404: logger.exception ("Get Log not fund Podname: {0}" .format (pod_name)) raise PodNotFund ("when getting logs This pod: {0} ".format (pod_name)) if e.status = = 400: raise PodNotFund was not found (" the container has not been created successfully, please contact the operator for troubleshooting. ") Raise e except Exception as e: logger.exception ("Get Log Fail: {0}" .format (str (e)) raise eHTML Flushed ajax test # log-container {height: 800px; / * width: 800pxdomestic / overflow-x: scroll; padding: 10px } .logs {background-color: black; color: aliceblue; font-size: 18px;} var last_response_len = false; var logs = $("# log-container") $.ajax ('http://localhost/api/pre/ops-test/pod/ops-test-1211763235-jfbst/log?tail_lines=100', {xhrFields: {onprogress: function (e) {var this_response, response = e.currentTarget.response; if (last_response_len = false) {this_response = response) Last_response_len = response.length;} else {this_response = response.substring (last_response_len); last_response_len = response.length;} / / console.log (this_response) / / receive the real-time log from the server and add it to the HTML page $("# log-container pre") .append (this_response); / / scroll to the lowest $("# log-container") .scrollTop ($("# log-container pre"). Height ()-$("# log-container") .append () + 10) ) .done (function (data) {console.log ('Complete response =' + data);}) .fail (function (data) {console.log ('Error:', data);}); console.log ('Request Sent'); other
Our application is separated from the front and back ends, so just put the core code in html into VUE.
Effect picture
The log is streaming, and if Container has a log, the window will be updated.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.