{"id":220754,"date":"2021-06-25T10:42:39","date_gmt":"2021-06-25T02:42:39","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=220754"},"modified":"2021-06-18T10:43:43","modified_gmt":"2021-06-18T02:43:43","slug":"kubernetes-curl-api","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/kubernetes-curl-api.html","title":{"rendered":"Kubernetes\u4e4bcurl\u8c03\u8bd5"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | Kubernetes\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u3001\u7528\u4e8e\u7ba1\u7406\u4e91\u5e73\u53f0\u4e2d\u591a\u4e2a\u4e3b\u673a\u4e0a\u7684\u5bb9\u5668\u5316\u5e94\u7528\u7684\u7cfb\u7edf\u3002\u5176\u76ee\u6807\u662f\u8ba9\u90e8\u7f72\u5bb9\u5668\u5316\u7684\u5e94\u7528\u7b80\u5355\u5e76\u4e14\u9ad8\u6548(powerful),\u5b83\u63d0\u4f9b\u4e86\u5e94\u7528\u90e8\u7f72\uff0c\u89c4\u5212\uff0c\u66f4\u65b0\uff0c\u7ef4\u62a4\u7684\u4e00\u79cd\u673a\u5236\u3002 \n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n Kubernetes\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u3001\u7528\u4e8e\u7ba1\u7406\u4e91\u5e73\u53f0\u4e2d\u591a\u4e2a\u4e3b\u673a\u4e0a\u7684\u5bb9\u5668\u5316\u5e94\u7528\u7684\u7cfb\u7edf\u3002\u5176\u76ee\u6807\u662f\u8ba9\u90e8\u7f72\u5bb9\u5668\u5316\u7684\u5e94\u7528\u7b80\u5355\u5e76\u4e14\u9ad8\u6548(powerful),\u5b83\u63d0\u4f9b\u4e86\u5e94\u7528\u90e8\u7f72\uff0c\u89c4\u5212\uff0c\u66f4\u65b0\uff0c\u7ef4\u62a4\u7684\u4e00\u79cd\u673a\u5236\u3002<\/p>\n Kubernetes\u4e00\u4e2a\u6838\u5fc3\u7684\u7279\u70b9\u5c31\u662f\u80fd\u591f\u81ea\u4e3b\u7684\u7ba1\u7406\u5bb9\u5668\u6765\u4fdd\u8bc1\u4e91\u5e73\u53f0\u4e2d\u7684\u5bb9\u5668\u6309\u7167\u7528\u6237\u7684\u671f\u671b\u72b6\u6001\u8fd0\u884c\u7740(\u6bd4\u5982\u7528\u6237\u60f3\u8ba9apache\u4e00\u76f4\u8fd0\u884c\uff0c\u7528\u6237\u4e0d\u9700\u8981\u5173\u5fc3\u600e\u4e48\u53bb\u505a\uff0cKubernetes\u4f1a\u81ea\u52a8\u53bb\u76d1\u63a7\uff0c\u7136\u540e\u53bb\u91cd\u542f\uff0c\u65b0\u5efa\uff0c\u603b\u4e4b\uff0c\u8ba9apache\u4e00\u76f4\u63d0\u4f9b\u670d\u52a1)\u3002<\/p>\n \u7ba1\u7406\u5458\u53ef\u4ee5\u52a0\u8f7d\u4e00\u4e2a\u5fae\u578b\u670d\u52a1\uff0c\u8ba9\u89c4\u5212\u5668\u6765\u627e\u5230\u5408\u9002\u7684\u4f4d\u7f6e\uff0c\u540c\u65f6\uff0cKubernetes\u4e5f\u7cfb\u7edf\u63d0\u5347\u5de5\u5177\u4ee5\u53ca\u4eba\u6027\u5316\u65b9\u9762\uff0c\u8ba9\u7528\u6237\u80fd\u591f\u65b9\u4fbf\u7684\u90e8\u7f72\u81ea\u5df1\u7684\u5e94\u7528(\u5c31\u50cfcanary deployments)\u3002<\/p>\n \u73b0\u5728Kubernetes\u7740\u91cd\u4e8e\u4e0d\u95f4\u65ad\u7684\u670d\u52a1\u72b6\u6001(\u6bd4\u5982web\u670d\u52a1\u5668\u6216\u8005\u7f13\u5b58\u670d\u52a1\u5668)\u548c\u539f\u751f\u4e91\u5e73\u53f0\u5e94\u7528(Nosql),\u5728\u4e0d\u4e45\u7684\u5c06\u6765\u4f1a\u652f\u6301\u5404\u79cd\u751f\u4ea7\u4e91\u5e73\u53f0\u4e2d\u7684\u5404\u79cd\u670d\u52a1\uff0c\u4f8b\u5982\uff0c\u5206\u6279\uff0c\u5de5\u4f5c\u6d41\uff0c\u4ee5\u53ca\u4f20\u7edf\u6570\u636e\u5e93\u3002<\/p>\n \u5bf9\u4e8e\u6709\u4e9b\u4eba\u800c\u8a00\uff0cKubernetes\u662f\u4e00\u4e2a\u975e\u5e38\u590d\u6742\u8c03\u5ea6\u7cfb\u7edf\u3002<\/p>\n \u2026\u56e0\u4e3a\u5b83\u5f88\u590d\u6742\uff0c\u6240\u4ee5\u914d\u7f6e\u975e\u5e38\u5197\u957f\u3002<\/p>\n \u2026\u7531\u4e8e\u914d\u7f6eYAML\u592a\u591a\uff0c\u6211\u4eec\u9700\u8981\u914d\u5408\u5176\u4ed6\u591a\u79cd\u5de5\u5177\u8f6f\u4ef6\u6765\u5904\u7406\u8be5\u914d\u7f6e\u3002<\/p>\n \u4f46\u662f\uff0c\u5728\u672c\u6587\u4e2d\uff0c\u6211\u8ba4\u4e3a\u90a3\u4e9b\u8ba4\u4e3akubernetns\u590d\u6742\u7684\u4eba\uff0c\u662f\u56e0\u4e3a\u6ca1\u6709\u627e\u5230\u5408\u7406\u7684\u65b9\u5f0f\u53bb\u5b66\u4e60\u4ee5\u53ca\u4f7f\u7528kubernetns\uff0c\u5c31\u50cf\u65e9\u671f\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e00\u6837\u3002<\/p>\n Kubernetes\u5bf9\u4e8e\u5982\u4f55\u7ba1\u7406\u914d\u7f6e\u6709\u4e00\u4e2a\u7b80\u5355\u800c\u5de7\u5999\u7684\u65b9\u5f0f\uff0c\u672c\u6587\u4e5f\u5c06\u8ba8\u8bba\u8fd9\u79cd\u65b9\u5f0f\u3002<\/p>\n \u56e0\u4e3a\u8fd9\u79cd\u65b9\u5f0f\u7b80\u5355\uff0c\u4e00\u81f4\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u7ba1\u7406\u6bd4\u4ee5\u5f80\u66f4\u591a\u7684\u914d\u7f6e!\u73b0\u5728\uff0c\u6211\u4eec\u4e0d\u4ec5\u53ef\u4ee5\u7ba1\u7406\u66f4\u591a\u7684\u914d\u7f6e\uff0c\u4e5f\u53ef\u4ee5\u6784\u5efa\u590d\u6742\u7684\u7cfb\u7edf\u3002<\/p>\n \u5f53\u7136\uff0c\u914d\u7f6e\u672c\u8eab\u53ef\u80fd\u5f88\u590d\u6742\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u8df3\u8fc7\u914d\u7f6e\u3002\u6211\u5c06\u4ec5\u4e13\u6ce8\u4e8ekubernetes API\u673a\u5236\u4ee5\u53ca\u5982\u4f55\u63a2\u7d22\u8be5API\u3002<\/p>\n \u4ee5\u8fd9\u79cd\u65b9\u5f0f\u6784\u5efaAPI\u53ef\u4ee5\u4f7f\u8bb8\u591a\u5de5\u5177\u53d7\u76ca\u3002<\/p>\n \u662f\u5565\u65b9\u6cd5?<\/strong><\/div>\n \u4e3a\u4e86\u89e3\u91ca\u8fd9\u79cd\u7b80\u5355\u800c\u9ad8\u6548\u7684\u65b9\u5f0f\uff0c\u8ba9\u6211\u4eec\u4eceUnix\u7cfb\u7edf\u7684\u6700\u6838\u5fc3\u601d\u60f3\u5f00\u59cb\uff1a<\/p>\n Everything is a file. \u901a\u8fc7\u4e0b\u9762\u7684\u6f2b\u753b\u56fe\uff0c\u8ba9\u6211\u4eec\u4ed4\u7ec6\u770b\u770b\/proc\u3002<\/p>\n <\/p>\n \u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u7684\u65b9\u5f0f\u6765\u67e5\u770b\u4ee5\u53ca\u4e86\u89e3\u7cfb\u7edf\u4e0a\u6b63\u5728\u8fd0\u884c\u4ec0\u4e48\/proc\uff0c\u4f8b\u5982\uff1a<\/p>\n \u4ec0\u4e48\u662fKubernetes API?<\/strong><\/div>\n Kubernetes API\u662f\u96c6\u7fa4\u7cfb\u7edf\u4e2d\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0cKubernetes\u4e2d\u5404\u79cd\u8d44\u6e90(\u5bf9\u8c61)\u7684\u6570\u636e\u901a\u8fc7\u8be5API\u63a5\u53e3\u88ab\u63d0\u4ea4\u5230\u540e\u7aef\u7684\u6301\u4e45\u5316\u5b58\u50a8(etcd)\u4e2d\uff0cKubernetes\u96c6\u7fa4\u4e2d\u7684\u5404\u90e8\u4ef6\u4e4b\u95f4\u901a\u8fc7\u8be5API\u63a5\u53e3\u5b9e\u73b0\u89e3\u8026\u5408\uff0c\u540c\u65f6Kubernetes\u96c6\u7fa4\u4e2d\u4e00\u4e2a\u91cd\u8981\u4e14\u4fbf\u6377\u7684\u7ba1\u7406\u5de5\u5177kubectl\u4e5f\u662f\u901a\u8fc7\u8bbf\u95ee\u8be5API\u63a5\u53e3\u5b9e\u73b0\u5176\u5f3a\u5927\u7684\u7ba1\u7406\u529f\u80fd\u7684\u3002<\/p>\n Kubernetes API \u662f\u57fa\u4e8e\u8d44\u6e90\u7684(RESTful)\u3001\u901a\u8fc7 HTTP \u63d0\u4f9b\u7684\u7f16\u7a0b\u63a5\u53e3\u3002API \u652f\u6301\u901a\u8fc7\u6807\u51c6\u7684 HTTP \u52a8\u8bcd(POST\u3001PUT\u3001PATCH\u3001DELETE \u548c GET) \u68c0\u89c6\u3001\u521b\u5efa\u3001\u66f4\u65b0\u548c\u5220\u9664\u4e3b\u8981\u8d44\u6e90\uff0c\u4e3a\u5f88\u591a\u5141\u8bb8\u7ec6\u7c92\u5ea6\u6743\u9650\u63a7\u5236\u7684\u5bf9\u8c61\u63d0\u4f9b\u5b50\u8d44\u6e90 (\u5982\u5c06 Pod \u7ed1\u5b9a\u5230\u8282\u70b9\u4e0a)\uff0c\u5e76\u4e14\u51fa\u4e8e\u4fbf\u5229\u6027\u6216\u6548\u7387\u8003\u8651\uff0c\u652f\u6301\u5e76\u63d0\u4f9b\u8fd9\u4e9b\u8d44\u6e90\u7684 \u4e0d\u540c\u8868\u793a\u5f62\u5f0f\u3002<\/p>\n Kubernetes API \u8fd8\u901a\u8fc7 \"watch\" \u548c\u4e00\u81f4\u6027\u7684\u5217\u8868\u652f\u6301\u9ad8\u6548\u7684\u8d44\u6e90\u53d8\u66f4\u901a\u77e5\uff0c \u4ece\u800c\u5141\u8bb8\u5176\u4ed6\u7ec4\u4ef6\u5bf9\u8d44\u6e90\u7684\u72b6\u6001\u8fdb\u884c\u9ad8\u6548\u7684\u7f13\u5b58\u548c\u540c\u6b65\u3002<\/p>\n Kubernetes API\u9002\u7528\/proc\u4e8e\u5206\u5e03\u5f0f\u7cfb\u7edf\u3002<\/p>\n \u4e00\u5207\u90fd\u662f\u57fa\u4e8eHTTP\u7684\u8d44\u6e90\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9bHTTP GET\u547d\u4ee4\u63a2\u7d22\u6bcf\u4e2aKubernetes\u8d44\u6e90\u3002<\/p>\n \u5982\u679c\u8981\u7ee7\u7eed\u8fdb\u884c\u4e0b\u53bb\uff0c\u60a8\u9700\u8981\u719f\u6089\u4ee5\u4e0b\u7684\u51e0\u79cd\u5de5\u5177\uff1a<\/p>\n \u4e0b\u9762\uff0c\u8ba9\u6211\u4eec\u4ece\u5feb\u901f\u521b\u5efa\u96c6\u7fa4\u5f00\u59cb\uff1a<\/p>\n \r\n$ kind create cluster \r\nCreating cluster \"kind\" ... \r\n\u2713 Ensuring node image (kindest\/node:v1.19.1) 🖼 \r\n\u2713 Preparing nodes 📦 \r\n\u2713 Writing configuration 📜 \r\n\u2713 Starting control-plane 🕹️ \r\n\u2713 Installing CNI 🔌 \r\n\u2713 Installing StorageClass 💾 \r\nSet kubectl context to \"kind-kind\" \r\nYou can now use your cluster with: \r\n \r\nkubectl cluster-info --context kind-kind \r\n \r\nHave a nice day! 👋 \r\n \r\n$ kubectl proxy & \r\nStarting to serve on 127.0.0.1:8001 \r\n<\/pre>\n |