{"id":415398,"date":"2024-07-23T19:46:56","date_gmt":"2024-07-23T11:46:56","guid":{"rendered":"https:\/\/www.idc.net\/help\/?p=415398"},"modified":"2024-07-23T19:46:56","modified_gmt":"2024-07-23T11:46:56","slug":"kubernetes%e8%b0%83%e8%af%95%e7%bb%88%e6%9e%81%e6%ad%a6%e5%99%a8-k8sgpt","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/415398\/","title":{"rendered":"Kubernetes\u8c03\u8bd5\u7ec8\u6781\u6b66\u5668: K8sGPT"},"content":{"rendered":"<p>\u968f\u7740\u4eba\u5de5\u667a\u80fd\u548c\u673a\u5668\u5b66\u4e60\u6280\u672f\u7684\u8fdb\u6b65\uff0c\u4f01\u4e1a\u548c\u7ec4\u7ec7\u8d8a\u6765\u8d8a\u591a\u7684\u63a2\u7d22\u521b\u65b0\u6218\u7565\uff0c\u4ee5\u6c42\u5229\u7528\u8fd9\u4e9b\u80fd\u529b\u6765\u83b7\u5f97\u7ade\u4e89\u4f18\u52bf\u3002<\/p>\n<p>K8sGPT[2]\u5c31\u662f\u8be5\u9886\u57df\u6700\u5f3a\u5927\u7684\u5de5\u5177\u4e4b\u4e00\uff0c\u5b83\u662f\u4e00\u79cd\u57fa\u4e8ek8s\u7684GPT\u6a21\u578b\uff0c\u7ed3\u5408\u4e86k8s\u7f16\u6392\u7684\u4f18\u70b9\u4ee5\u53caGPT\u6a21\u578b\u590d\u6742\u7684\u81ea\u7136\u8bed\u8a00\u5904\u7406\u80fd\u529b\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ec0\u4e48\u662fK8sGPT?<\/p>\n<p>\u5148\u770b\u4e00\u4e2a\u4f8b\u5b50:<\/p>\n<p>&nbsp;<\/p>\n<p>\u6839\u636eK8sGPT\u5b98\u7f51\u89e3\u91ca\uff1a<\/p>\n<blockquote><p>K8sgpt\u662f\u4e00\u4e2a\u7528\u82f1\u8bed\u626b\u63cfkubernetes\u96c6\u7fa4\u3001\u8bca\u65ad\u548c\u5206\u7c7b\u95ee\u9898\u7684\u5de5\u5177\u3002\u5b83\u5c06SRE\u7ecf\u9a8c\u7f16\u5165\u5176\u5206\u6790\u7a0b\u5e8f\uff0c\u5e2e\u52a9\u63d0\u53d6\u6700\u76f8\u5173\u7684\u4fe1\u606f\uff0c\u5e76\u7528AI\u5145\u5b9e\u5176\u5185\u5bb9\u3002<\/p><\/blockquote>\n<p>K8sGPT\u662f\u5e72\u4ec0\u4e48\u7528\u7684?<\/p>\n<p>K8sGPT\u6700\u8fd1\u5df2\u7ecf\u4f5c\u4e3a\u6c99\u76d2\u9879\u76ee\u63d0\u4ea4\u7ed9\u4e91\u539f\u751f\u8ba1\u7b97\u57fa\u91d1\u4f1a(CNCF)\uff0c\u5c55\u793a\u4e86\u5176\u5bf9\u4e91\u539f\u751f\u793e\u533a\u7684\u6f5c\u5728\u4ef7\u503c\u3002<\/p>\n<p>CNCF\u76ee\u524d\u6b63\u5728\u5bf9\u5176\u8fdb\u884c\u521d\u6b65\u8bc4\u4f30\uff0c\u8fd9\u662f\u4ee4\u4eba\u9f13\u821e\u7684\u8fdb\u5c55\uff0c\u4f53\u73b0\u4e86\u5bf9\u521b\u5efa\u6ee1\u8db3Kubernetes\u7528\u6237\u9700\u6c42\u7684\u5de5\u5177\u7684\u5949\u732e\u7cbe\u795e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>K8sGPT\u53ef\u4ee5\u7528\u4f5c:<\/p>\n<p>\u5de5\u4f5c\u8d1f\u8f7d\u8fd0\u884c\u72b6\u51b5\u5206\u6790:\u00a0\u67e5\u627e\u5de5\u4f5c\u8d1f\u8f7d\u7684\u5173\u952e\u95ee\u9898<\/p>\n<p>\u5feb\u901f\u5206\u7c7b\uff0cAI\u5206\u6790:\u00a0\u68c0\u67e5\u6216\u7528AI\u6df1\u5165\u5206\u6790\u96c6\u7fa4<\/p>\n<p>\u8f85\u52a9\u7406\u89e3:\u00a0\u628a\u590d\u6742\u4fe1\u53f7\u8f6c\u5316\u4e3a\u5bb9\u6613\u7406\u89e3\u7684\u5efa\u8bae<\/p>\n<p>\u5b89\u5168CVE\u5ba1\u67e5:\u00a0\u8fde\u63a5\u5230Trivy\u7b49\u626b\u63cf\u7a0b\u5e8f\u5e76\u5bf9\u95ee\u9898\u8fdb\u884c\u5206\u7c7b<\/p>\n<h4>K8sGPT\u5982\u4f55\u5de5\u4f5c?<\/h4>\n<p>K8sGPT\u4f7f\u7528\u4e00\u7ec4\u4e13\u95e8\u8bbe\u8ba1\u7684\u5206\u6790\u5668\u6765\u68c0\u6d4b\u548c\u7b80\u5316Kubernetes\u96c6\u7fa4\u4e2d\u8bca\u65ad\u548c\u89e3\u51b3\u95ee\u9898\u7684\u4efb\u52a1\u3002\u8fd9\u4e9b\u5206\u6790\u5668\u57fa\u4e8eSRE\u7684\u667a\u6167\u7ecf\u9a8c\u7f16\u7801\uff0c\u64c5\u957f\u63d0\u4f9b\u9ad8\u5ea6\u51c6\u786e\u548c\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u5185\u7f6e\u5206\u6790\u5668\uff1a<\/p>\n<ul>\n<li>PodAnalyzer:\u00a0\u8be5\u5de5\u5177\u4ed4\u7ec6\u68c0\u67e5pod\u8bbe\u7f6e\uff0c\u641c\u7d22\u53ef\u80fd\u5bfc\u81f4\u590d\u6742\u95ee\u9898\u7684\u6f5c\u5728\u95ee\u9898\uff0c\u4f8b\u5982pod\u6545\u969c\u6216\u8fc7\u5ea6\u4f7f\u7528\u8d44\u6e90\u3002<\/li>\n<li>PVCAnalyzer:\u00a0\u8be5\u5de5\u5177\u68c0\u67e5\u6301\u4e45\u5377\u58f0\u660e(Persistent Volume Claim, PVC)\u7684\u914d\u7f6e\uff0c\u641c\u7d22\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u6216\u5176\u4ed6\u5b58\u50a8\u76f8\u5173\u6311\u6218\u7684\u4efb\u4f55\u5dee\u5f02\u3002<\/li>\n<li>ServiceAnalyzer:\u00a0\u8fd9\u4e2a\u5de5\u5177\u63a2\u6d4b\u670d\u52a1\u8bbe\u7f6e\uff0c\u5bfb\u627e\u4efb\u4f55\u53ef\u80fd\u5bfc\u81f4\u670d\u52a1\u4e2d\u65ad\u6216\u6027\u80fd\u4e0b\u964d\u7684\u6f5c\u5728\u95ee\u9898\u3002<\/li>\n<li>DeploymentAnalyzer:\u00a0\u8be5\u5de5\u5177\u68c0\u67e5Deployment\u914d\u7f6e\uff0c\u627e\u51fa\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u5229\u7528\u6548\u7387\u4f4e\u4e0b\u7684\u4efb\u4f55\u95ee\u9898\u3002<\/li>\n<li>NodeAnalyzer:\u00a0\u8be5\u5de5\u5177\u68c0\u67e5K8s\u96c6\u7fa4\u8282\u70b9\uff0c\u8bc6\u522b\u4e0e\u8282\u70b9\u8fd0\u884c\u72b6\u51b5\u3001\u4f7f\u7528\u60c5\u51b5\u548c\u5bb9\u91cf\u76f8\u5173\u7684\u4efb\u4f55\u6f5c\u5728\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h4>\u5982\u4f55\u5b89\u88c5K8sGPT?<\/h4>\n<p>(1) \u524d\u7f6e\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd\u6b63\u786e\u5b89\u88c5\u4e86k8sgpt<\/li>\n<li>\u73b0\u6210\u7684K8s\u96c6\u7fa4<\/li>\n<li>OpenAI\u63d0\u4f9b\u7684API\u5bc6\u94a5\u4f5c\u4e3a\u9ed8\u8ba4AI\u4f9b\u5e94\u5546<\/li>\n<\/ul>\n<p>Homebrew\uff1a<\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5K8sGPT:<\/p>\n<pre><code>$ brew install k8sgpt<\/code><\/pre>\n<p>\u57fa\u4e8eRPM\u7684\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ curl -LO https:\/\/github.com\/k8sgpt-ai\/k8sgpt\/releases\/download\/v0.2.7\/k8sgpt_amd64.rpm\r\n$ sudo rpm -ivh -i k8sgpt_amd64.rpm\r\nPreparing...                          ################################# [100%]\r\nUpdating \/ installing...\r\n   1:k8sgpt-0:0.2.7-1                 ################################# [100%]<\/code><\/pre>\n<p>\u57fa\u4e8eDEB\u7684\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ curl -LO https:\/\/github.com\/k8sgpt-ai\/k8sgpt\/releases\/download\/v0.2.7\/k8sgpt_amd64.deb\r\n$ sudo dpkg -i k8sgpt_amd64.deb<\/code><\/pre>\n<p>\u57fa\u4e8eAPK\u7684\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ curl -LO https:\/\/github.com\/k8sgpt-ai\/k8sgpt\/releases\/download\/v0.2.7\/k8sgpt_amd64.apk\r\n$ apk add k8sgpt_amd64.apk<\/code><\/pre>\n<p>\u9a8c\u8bc1\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ k8sgpt version\r\nk8sgpt version 0.2.7<\/code><\/pre>\n<p>(2) \u8bbe\u7f6e\u8ba4\u8bc1<\/p>\n<p>\u6ce8\u610f: \u5047\u8bbe\u5df2\u7ecf\u62e5\u6709OpenAI API-key<\/p>\n<pre><code>$ k8sgpt auth\r\nUsing openai as backend AI provider\r\nEnter openai Key: New provider added\r\nkey added<\/code><\/pre>\n<h4>\u5982\u4f55\u4f7f\u7528K8sGPT?<\/h4>\n<p>\u4e00\u65e6\u5b8c\u6210OpenAI\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5f00\u59cb\u4f7f\u7528K8sGPT:<\/p>\n<pre><code>$ k8sgpt\r\n\r\nKubernetes debugging powered by AI\r\n\r\nUsage:\r\n  k8sgpt [command]\r\n\r\nAvailable Commands:\r\n  analyze     This command will find problems within your Kubernetes cluster\r\n  auth        Authenticate with your chosen backend\r\n  completion  Generate the autocompletion script for the specified shell\r\n  filters     Manage filters for analyzing Kubernetes resources\r\n  generate    Generate Key for your chosen backend (opens browser)\r\n  help        Help about any command\r\n  integration Intergrate another tool into K8sGPT\r\n  serve       Runs k8sgpt as a server\r\n  version     Print the version number of k8sgpt\r\n\r\nFlags:\r\n      --config string        config file (default is $HOME\/.k8sgpt.yaml)\r\n  -h, --help                 help for k8sgpt\r\n      --kubeconfig string    Path to a kubeconfig. Only required if out-of-cluster. (default \"\/mnt\/efs\/data\/home\/txu\/.kube\/config\")\r\n      --kubecontext string   Kubernetes context to use. Only required if out-of-cluster.\r\n\r\nUse \"k8sgpt [command] --help\" for more information about a command.<\/code><\/pre>\n<p>\u6700\u5e38\u7528\u7684\u547d\u4ee4\u662fk8sgpt analyze:<\/p>\n<pre><code>$ k8sgpt analyze --explain<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e5f\u53ef\u4ee5\u8f93\u51faJSON\u683c\u5f0f:<\/p>\n<p>&nbsp;<\/p>\n<p>\u67e5\u770b\u53ef\u7528\u7684\u8fc7\u6ee4\u5668:<\/p>\n<pre><code>$ k8sgpt filters list\r\nActive:\r\n&gt; Service\r\n&gt; CronJob\r\n&gt; Node\r\n&gt; Pod\r\n&gt; Deployment\r\n&gt; Ingress\r\n&gt; StatefulSet\r\n&gt; ReplicaSet\r\n&gt; PersistentVolumeClaim\r\nUnused:\r\n&gt; HorizontalPodAutoScaler\r\n&gt; PodDisruptionBudget\r\n&gt; NetworkPolicy<\/code><\/pre>\n<h4>\u989d\u5916\u53c2\u6570<\/h4>\n<p>filters\uff1a<\/p>\n<pre><code>$ k8sgpt analyze --filter=Service\r\n $ k8sgpt analyze --namespace=default<\/code><\/pre>\n<p>anonymize\uff1a<\/p>\n<pre><code>$  k8sgpt analyze --anonymize<\/code><\/pre>\n<p>\u5176\u4ed6AI\u540e\u7aef\uff1a<\/p>\n<pre><code>$  k8sgpt auth -b<\/code><\/pre>\n<h4>\u7ed3\u8bba<\/h4>\n<p>&nbsp;<\/p>\n<p>\u968f\u7740\u4f01\u4e1a\u548c\u7ec4\u7ec7\u4e0d\u65ad\u63a2\u7d22\u521b\u9020\u6027\u65b9\u6cd5\u6765\u5229\u7528AI\u548c\u673a\u5668\u5b66\u4e60\u7684\u529b\u91cf\uff0cK8sGPT\u6b63\u5728\u6210\u4e3a\u5e2e\u52a9\u4ed6\u4eec\u5b9e\u73b0\u76ee\u6807\u7684\u6709\u529b\u5de5\u5177\u3002\u5229\u7528\u4f18\u8d8a\u7684\u81ea\u7136\u8bed\u8a00\u5904\u7406\u80fd\u529b\u548cK8s\u7f16\u6392\u4f18\u52bf\uff0cK8sGPT\u6709\u53ef\u80fd\u5f7b\u5e95\u6539\u53d8\u6211\u4eec\u5206\u6790\u548c\u7406\u89e3\u6587\u672c\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u4ece\u800c\u4fc3\u8fdb\u4f17\u591a\u9886\u57df\u7684\u521b\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u4eba\u5de5\u667a\u80fd\u548c\u673a\u5668\u5b66\u4e60\u6280\u672f\u7684\u8fdb\u6b65\uff0c\u4f01\u4e1a\u548c\u7ec4\u7ec7\u8d8a\u6765\u8d8a\u591a\u7684\u63a2\u7d22\u521b\u65b0\u6218\u7565\uff0c\u4ee5\u6c42\u5229\u7528\u8fd9\u4e9b\u80fd\u529b\u6765\u83b7\u5f97\u7ade\u4e89\u4f18\u52bf\u3002 K8sG [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7023],"tags":[],"class_list":["post-415398","post","type-post","status-publish","format-standard","hentry","category-chatgpt"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/415398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=415398"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/415398\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=415398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=415398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=415398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}