{"id":17368,"date":"2025-05-19T11:05:07","date_gmt":"2025-05-19T03:05:07","guid":{"rendered":"https:\/\/92it.top\/?p=17368"},"modified":"2025-05-22T08:10:19","modified_gmt":"2025-05-22T00:10:19","slug":"%e5%88%a9%e7%94%a8kubernetes%e6%90%ad%e5%bb%ba%e4%be%bf%e6%90%ba%e5%bc%8f%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e4%b9%8bmysql%e5%92%8credis","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=17368","title":{"rendered":"Kubernetes \u642d\u5efa\u5f00\u53d1\u73af\u5883\u4e4bMySQL\u548cRedis"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"http:\/\/\u5229\u7528Kubernetes\u642d\u5efa\u4fbf\u643a\u5f0f\u5f00\u53d1\u73af\u5883\u4e4bMySQL\u548cRedis\">\u5229\u7528Kubernetes\u642d\u5efa\u4fbf\u643a\u5f0f\u5f00\u53d1\u73af\u5883\u4e4bMySQL\u548cRedis<\/a><\/p>\n\n\n\n<p><strong>\u80cc\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e4b\u524d\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u8fc7\uff0c \u6211\u81ea\u5df1\u7528\u7684\u5f00\u53d1\u73af\u5883\u90fd\u662f\u5bb9\u5668\u5316\u7684\uff0c\u53ea\u4e0d\u8fc7\u524d\u4e24\u5e74\u4e0d\u4f1a\u7528K8\uff0c\u5927\u90e8\u5206\u90fd\u662f\u7528\u7684 Docker \u6216\u8005 Docker-Compose\u3002\u968f\u7740\u8fd9\u4e00\u5e74\u591a\u5bf9 K8 \u7684\u5b66\u4e60\u548c\u5de5\u4f5c\u4e2d\u7684\u4f7f\u7528\uff0c\u4e00\u76f4\u6709\u60f3\u6cd5\u7528K8 \u505a\u4e00\u5957\u4fbf\u643a\u5f0f\u5f00\u53d1\u73af\u5883\uff0c\u4ee5\u540e\u6362\u7535\u8111\u5c31\u4e0d\u7528\u518d\u6101\u6570\u636e\u5e93\u3001\u7f13\u5b58\u3001\u961f\u5217\u8fd9\u4e9b\u57fa\u7840\u8f6f\u4ef6\u7684\u5b89\u88c5\u4e86\u3002\u6b63\u597d\u4e0b\u4e2a\u6708\u6211\u5c31\u80fd\u6362\u65b0\u7684\u529e\u516c\u7535\u8111\u5566\uff0c\u4e5f\u4e0d\u80fd\u62ff\u300e\u80fd\u7528\u5c31\u884c\u300f\u7684\u7406\u7531\u518d\u62d6\u5ef6\u4e0b\u53bb\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u95ee\u4f60 \u201c \u5e73\u65f6\u5f00\u53d1\u7a0b\u5e8f\u4f9d\u8d56\u6700\u591a\u7684\u57fa\u7840\u8f6f\u4ef6\u65f6\u5565\uff1f\u201d\uff0c\u6211\u731c\u5927\u90e8\u5206\u4eba\u4f1a\u56de\u7b54\uff1a\u201cMySQL \u548c Redis\u201d\uff0c\u6bd5\u7adf\u4e07\u7269\u7686\u662f\u589e\u5220\u6539\u67e5\uff0c\u6574\u5929\u505aCURD\u7684\u6211\u4eec\u600e\u4e48\u80fd\u79bb\u5f00\u5b83\u4eec\u5462\u3002<\/p>\n\n\n\n<p><strong>\u51c6\u5907\u5de5\u4f5c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li>\u5de5\u5177\u9009\u62e9<\/li>\n<\/ul>\n\n\n\n<p>\u65e2\u7136\u662f\u8981\u5728\u672c\u5730 Kubernetes \u4e0a\u642d\u5efa\u5f00\u53d1\u73af\u5883\uff0c\u90a3\u7535\u8111\u4e0a\u5f97\u5148\u6709 Kubernetes \u96c6\u7fa4\u624d\u884c\u3002\u76ee\u524d\u53ef\u4ee5\u5728\u672c\u5730\u8fd0\u884c Kubernetes \u96c6\u7fa4\u7684\u5de5\u5177\u6709\uff1aMinikube \u3001Kind \u548c K3d \uff0c\u6211\u4eec\u7684MySQL\u548cRedis\u90fd\u662f\u9760\u5148\u7f16\u5199\u8d44\u6e90\u5b9a\u4e49YAML\u6587\u4ef6\uff0c\u518d\u901a\u8fc7 kubectl \u4ea4\u7ed9Kubernetes \u96c6\u7fa4\u6267\u884c\u7684\uff0c\u6240\u4ee5\u8fd9\u4e09\u79cd\u5de5\u5177\u7528\u54ea\u79cd\u90fd\u884c\u3002<\/p>\n\n\n\n<p>\u6211\u81ea\u5df1\u5728\u672c\u5730\u4f7f\u7528\u7684\u662fMinikube\uff0c\u8fd9\u662f Kubernetes \u5b98\u65b9\u63d0\u4f9b\u7684\u5de5\u5177\uff0c\u8bf4\u5b9e\u8bdd\u8fd0\u884c\u8d77\u6765\u540e\u7535\u8111\u6709\u70b9\u5361\uff0cMinikube\u7684\u5b89\u88c5\u6b65\u9aa4\u53ef\u4ee5\u53c2\u8003\u6211\u4ee5\u524d\u5199\u7684\u6587\u7ae0\u300c<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247485235&amp;idx=1&amp;sn=0cdd31c25b13790b336e0a8222f00b64&amp;scene=21#wechat_redirect\">Minikube-\u8fd0\u884c\u5728\u7b14\u8bb0\u672c\u7535\u8111\u4e0a\u7684Kubernetes\u96c6\u7fa4<\/a>\u300d\u3002\u53e6\u5916\u4e24\u79cd Kind \u548c K3d \u5219\u662f\u8f7b\u91cf\u7ea7\u96c6\u7fa4\uff0c\u652f\u6301\u591a\u8282\u70b9\u90e8\u7f72\u3002\u5176\u4e2d\u6211\u6bd4\u8f83\u63a8\u8350K3d\uff0c\u5c24\u5176\u662f\u4f7f\u7528 M1\u82af\u7247MacBook\u7684\u540c\u5b66\uff0c\u73b0\u5728\u6682\u65f6\u53ea\u80fd\u4f7f\u7528K3d\u5b89\u88c5Kubernetes\u96c6\u7fa4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">K3d \u662f\u4f7f\u7528 docker \u5bb9\u5668\u5728\u672c\u5730\u8fd0\u884c k3s \u96c6\u7fa4\uff0ck3s \u662f\u7531 Rancher Lab \u5f00\u6e90\u7684\u8f7b\u91cf\u7ea7 Kubernetes\u3002k3d \u5b8c\u7f8e\u7ee7\u627f\u4e86 k3s \u7684\u7b80\u5355\u3001\u5feb\u901f\u548c\u5360\u7528\u8d44\u6e90\u5c11\u7684\u4f18\u52bf\uff0c\u955c\u50cf\u5927\u5c0f\u53ea\u6709 100 \u591a M\uff0c\u542f\u52a8\u901f\u5ea6\u5feb\uff0c\u652f\u6301\u591a\u8282\u70b9\u96c6\u7fa4\u3002\u867d\u7136 k3s \u5bf9 Kubernetes \u8fdb\u884c\u4e86\u8f7b\u91cf\u5316\u7684\u88c1\u526a\uff0c\u4f46\u662f\u63d0\u4f9b\u4e86\u5b8c\u6574\u4e86\u529f\u80fd\uff0c\u50cf Istio \u8fd9\u6837\u590d\u6742\u7684\u4e91\u539f\u751f\u5e94\u7528\u90fd\u53ef\u4ee5\u5728 k3s \u4e0a\u987a\u5229\u8fd0\u884c\u3002<br><br>K3d \u9664\u4e86\u542f\u52a8\u901f\u5ea6\u5feb\u548c\u5360\u7528\u8d44\u6e90\u5c11\u4ee5\u5916\uff0c\u5728\u8fb9\u7f18\u8ba1\u7b97\u548c\u5d4c\u5165\u5f0f\u9886\u57df\u4e5f\u6709\u7740\u4e0d\u4fd7\u7684\u8868\u73b0\u3002\u56e0\u4e3a k3s \u672c\u8eab\u5e94\u7528\u573a\u666f\u4e3b\u8981\u5728\u8fb9\u7f18\u4fa7\uff0c\u6240\u4ee5\u652f\u6301\u7684\u8bbe\u5907\u548c\u67b6\u6784\u5f88\u591a\uff0c\u5982\uff1aARM64 \u548c ARMv7 \u5904\u7406\u5668\u3002\u5f88\u591a\u8001\u65e7 PC \u548c\u6811\u8393\u6d3e\u8fd9\u6837\u7684\u8bbe\u5907\u90fd\u53ef\u4ee5\u62ff\u6765\u505a\u6210 k3s \u96c6\u7fa4\uff0c\u4e3a\u672c\u5730\u7814\u53d1\u6d4b\u8bd5\u71c3\u5c3d\u6700\u540e\u7684\u751f\u547d\u3002<\/pre>\n\n\n\n<ul>\n<li>\u9884\u5907\u77e5\u8bc6\u70b9<\/li>\n<\/ul>\n\n\n\n<p>\u8bf4\u5b8c\u4e86\u5b89\u88c5\u5de5\u5177\u7684\u9009\u62e9\uff0c\u6211\u4eec\u518d\u6765\u8bf4\u4e00\u4e0b\u5728Kubernetes\u4e0a\u4ece\u96f6\u642d\u5efa\u5f00\u53d1\u73af\u5883\u9700\u8981\u63d0\u524d\u505a\u54ea\u4e9b\u77e5\u8bc6\u50a8\u5907\uff0c\u5982\u679c\u4f60\u5df2\u7ecf\u5bf9Kubernetes\u8fd9\u4e9b\u57fa\u7840\u6982\u5ff5\u5df2\u7ecf\u6709\u6240\u4e86\u89e3\u53ef\u4ee5\u76f4\u63a5\u8df3\u8fc7\u53bb\u770b\u5b9e\u64cd\u73af\u8282\u4e86\uff0c\u5982\u679c\u8fd8\u6bd4\u8f83\u751f\u758f\u7684\u8bdd\uff0c\u6211\u5efa\u8bae\u5927\u5bb6\u5148\u770b\u770b\u4e0b\u9762\u8fd9\u51e0\u7bc7\u6587\u7ae0\uff0c\u8fd9\u4e9b\u90fd\u662f\u6211\u4eec\u642d\u5efa\u5f00\u53d1\u73af\u5883\u65f6\u9700\u8981\u7528\u5230\u7684\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247485464&amp;idx=1&amp;sn=00ca443bbcd4b2996efdede396b6c667&amp;chksm=fa80d98fcdf7509944d63f618264e36cd8082a77e23aa36428a3d57a2f4189bcce4e52986967&amp;token=2033333242&amp;lang=zh_CN&amp;scene=21#wechat_redirect\">Kubernetes Pod\u5165\u95e8\u6307\u5357<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247485643&amp;idx=1&amp;sn=6460bf2e170e4b2e8ebb2882bfe7c60f&amp;scene=21#wechat_redirect\">\u5e94\u7528\u7f16\u6392\u5229\u5668\u4e4bDeployment<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247486082&amp;idx=1&amp;sn=42a9bc8fcfc9da09445e9e2f4cf2fb96&amp;chksm=fa80db15cdf752039494992f71a3bc488cf386841bd1aaaa44115f5e7f155ba55ce468ec89ee&amp;token=2033333242&amp;lang=zh_CN&amp;scene=21#wechat_redirect\">\u5b66\u7ec3\u7ed3\u5408\uff0c\u5feb\u901f\u638c\u63e1Kubernetes Service<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247486416&amp;idx=1&amp;sn=20d568f93d0f39e0f3c7ef3ce42ac1d8&amp;scene=21#wechat_redirect\">\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u7ba1\u7406\u914d\u7f6e\u6587\u4ef6<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUzNTY5MzU2MA==&amp;mid=2247486737&amp;idx=1&amp;sn=e7d0689fa74b108bae734515837c68e1&amp;chksm=fa80dc86cdf755909f2f29ee8cb9dce930b95a837cb045be5c9700a9000743c9cb7f8eed6731&amp;token=1423297622&amp;lang=zh_CN&amp;scene=21#wechat_redirect\">\u6df1\u5165\u7406\u89e3StatefulSet\uff0c\u7528Kubernetes\u7f16\u6392\u6709\u72b6\u6001\u5e94\u7528<\/a><\/p>\n\n\n\n<p><strong>\u5b89\u88c5MySQL<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728\u6b63\u5f0f\u5f00\u59cb\u5728Kubernetes\u4e0a\u5b89\u88c5MySQL\u548cRedis\u524d\u6211\u5148\u8bf4\u660e\u4e0b\u5b89\u88c5\u8fd9\u4e24\u4e2a\u57fa\u7840\u8f6f\u4ef6\u670d\u52a1\u7684\u601d\u8def\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"636\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-1024x636.png\" alt=\"\" class=\"wp-image-17369\" style=\"width:600px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-1024x636.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-300x186.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-768x477.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-830x516.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-230x143.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-350x217.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32-480x298.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-32.png 1346w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u4e0b\u9762\u8fd9\u5f20\u56fe\u5f88\u597d\u7684\u89e3\u91ca\u4e86\u8fd9\u56db\u90e8\u5206\u7684\u534f\u4f5c\u5173\u7cfb\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"612\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-1024x612.png\" alt=\"\" class=\"wp-image-17370\" style=\"width:570px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-1024x612.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-300x179.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-768x459.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-830x496.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-230x138.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-350x209.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33-480x287.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-33.png 1368w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u89e3\u91ca\u6e05\u695a\u6211\u4eec\u5728Kubernetes\u4e0a\u642d\u5efaMySQL\u548cRedis\u5f00\u53d1\u73af\u5883\u7684\u601d\u8def\u540e\uff0c\u4e0b\u9762\u5c31\u53ef\u4ee5\u8fdb\u5165\u5b9e\u64cd\u73af\u8282\u5566\uff0c\u6211\u4e3a\u5927\u5bb6\u51c6\u5907\u4e86\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u4f7f\u7528\u7684YAML\u8d44\u6e90\u5b9a\u4e49\u6587\u4ef6\u3002<\/p>\n\n\n\n<p><strong>\u521b\u5efaMySQL\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u4eec\u5148\u6765\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a mysql-db-config \u7684ConfigMap\uff0c\u7a0d\u540e\u4f1a\u628a\u8fd9\u4e9b\u914d\u7f6e\u4f5c\u4e3a my.cnf \u914d\u7f6e\u6587\u4ef6\u6302\u8f7d\u5230MySQL\u5e94\u7528Pod\u7684\u5bb9\u5668\u91cc\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">### \u6587\u4ef6\u540d mysql-configmap.yaml\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: mysql-db-config\n  namespace: default\n  labels:\n    app: mysql-db-config\ndata:\n  my.cnf: |\n    [client]\n    default-character-set=utf8mb4\n    [mysql]\n    default-character-set=utf8mb4\n    [mysqld]\n    character-set-server = utf8mb4\n    collation-server = utf8mb4_unicode_ci\n    init_connect='SET NAMES utf8mb4'\n    skip-character-set-client-handshake = true\n    max_connections=2000\n    secure_file_priv=\/var\/lib\/mysql\n    datadir=\/var\/lib\/mysql\n    bind-address=0.0.0.0\n    symbolic-links=0<\/pre>\n\n\n\n<p>\u5047\u5b9aMySQL\u76f8\u5173\u7684YAML\u5b9a\u4e49\u6587\u4ef6\u90fd\u653e\u5728 mysql-singleton \u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff0c\u901a\u8fc7 kubectl \u628a\u8fd9\u4e2aConfigMap \u63d0\u4ea4\u7ed9Kubernetes \u8fdb\u884c\u521b\u5efa\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f mysql-singleton\/mysql-configmap.yaml<\/pre>\n\n\n\n<p><strong>\u521b\u5efaMySQL\u5bb9\u5668\u548cService<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6709\u4e86MySQL\u914d\u7f6e\u76f8\u5173\u7684 ConfigMap\u540e\uff0c\u6211\u4eec\u5c31\u80fd\u5728\u521b\u5efa\u8fd0\u884cMySQL\u7684\u5bb9\u5668\u65f6\uff0c\u628a\u4ed6\u4f5c\u4e3a\u914d\u7f6e\u6587\u4ef6\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">### \u6587\u4ef6\u540d deployment-service.yaml\napiVersion: v1\nkind: Service\nmetadata:\n  name: mysql\nspec:\n  type: NodePort\n  ports:\n    - port: 3306\n      nodePort: 30306\n      targetPort: mysql\n  selector:\n    app: mysql\n---\napiVersion:\nkind: Deployment\nmetadata:\n  name: mysql\nspec:\n  selector:\n    matchLabels:\n      app: mysql\n  strategy:\n    type: Recreate\n  template:\n    metadata:\n      labels:\n        app: mysql\n    spec:\n      containers:\n        - image: mysql:5.7\n          name: mysql\n          env:\n            - name: MYSQL_ROOT_PASSWORD\n              value: root\n            - name: MYSQL_USER\n              value: user\n            - name: MYSQL_PASSWORD\n          ports:\n            - containerPort: 3306\n              name: mysql\n          volumeMounts:\n            - name: mysql-persistent-storage\n              mountPath: \/var\/lib\/mysql\n            - name: mysql-config\n              mountPath: \/etc\/mysql\/conf.d\/my.cnf\n              subPath: my.cnf\n      volumes:\n        - name: mysql-persistent-storage\n          emptyDir: {}\n        - name: mysql-config\n          configMap:\n            name: mysql-db-config\n            items:\n              - key: my.cnf\n                path: my.cnf<\/pre>\n\n\n\n<p>\u540c\u6837\u7684\uff0c\u4f7f\u7528kubectl \u628a YAML \u63d0\u4ea4\u7ed9Kubernetes\u540e\uff0c\u7b49\u8d44\u6e90\u521b\u5efa\u5b8c\u6bd5\u6211\u4eec\u7684\u5f00\u53d1\u73af\u5883MySQL\u5c31\u7b97\u642d\u5efa\u597d\u4e86<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f mysql-singleton\/deployment-service.yaml<\/pre>\n\n\n\n<p>\u901a\u8fc7\u4e0a\u9762\u7684YAML\u6587\u4ef6\u4e2d\uff0c\u6709\u4e09\u70b9\u9700\u8981\u8be6\u7ec6\u8bf4\u660e\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<ol>\n<li>\u4f7f\u7528 mysql-db-config \u8fd9\u4e2aConfigMap \u4e2dmy.cnf\u8fd9\u4e2a\u914d\u7f6e\u9879\u4ee5my.cnf\u6587\u4ef6\u540d\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d\u53bb\uff0c\u4f46\u662f\u56e0\u4e3a\u6302\u8f7d\u8fdb\u53bb\u540e\u4f1a\u8986\u76d6\u5bb9\u5668\u4e2dconf.d \u76ee\u5f55\u4e2d\u7684\u5185\u5bb9\u3002\u901a\u8fc7volumeMounts.subPath\u53ef\u4ee5\u652f\u6301\u9009\u5b9aConfigMap\u4e2d\u7684Key-Value\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d\u800c\u4e0d\u8986\u76d6\u5bb9\u5668\u4e2d\u539f\u6709\u7684\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>Service \u7528 30306 \u7aef\u53e3\u5411\u96c6\u7fa4\u5916\u66b4\u9732\u4e86MySQL\u670d\u52a1\uff0c\u5ba2\u6237\u7aef\u4ece\u7535\u8111\u4e0a\u4f7f\u7528NodeIP:NodePort\u5373\u53ef\u8fde\u63a5\u5230\u8fd9\u91cc\u521b\u5efa\u7684\u6570\u636e\u5e93\uff0c\u5982\u679c\u7528\u7684\u662fMinikube\u521b\u5efa\u7684Kubernetes\u96c6\u7fa4\uff0c \u53ef\u4ee5\u901a\u8fc7minikube ip \u547d\u4ee4\u67e5\u5230NodeIP\u3002<\/li>\n\n\n\n<li>emptyDir \u7c7b\u578b\u7684\u6570\u636e\u5377\u7684\u751f\u547d\u5468\u671f\u4e0ePod\u540c\u6b65\uff0c\u8fd9\u91cc\u7684\u540c\u6b65\u6307\u7684\u662fPod\u88abkubectl delete \u4e3b\u52a8\u5220\u9664\u65f6\u624d\u4f1a\u9500\u6bc1\u5bf9\u5e94\u7684\u6570\u636e\u5377\uff0c\u5982\u679c\u662fPod\u81ea\u5df1\u5d29\u6e83\uff0c\u6216\u8005\u662f\u96c6\u7fa4Shotdown\uff0c\u7b49\u6062\u590d\u540e\u91cd\u5efa\u51fa\u6765\u7684Pod\u4ecd\u7136\u4f1a\u4f7f\u7528\u4e4b\u524d\u7684\u6570\u636e\u5377\uff0c\u4e0d\u4f1a\u9020\u6210\u6570\u636e\u4e22\u5931\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5728Kubernetes\u4e0a\u521b\u5efa\u5b8cMySQL\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4efb\u610f\u5ba2\u6237\u7aef\u6216\u8005mysql\u547d\u4ee4\u884c\uff0c\u8fde\u63a5MySQL\u670d\u52a1\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mysql -uroot -proot -h {minikube-ip} -P 30306<\/pre>\n\n\n\n<p><strong>\u5b89\u88c5Redis<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u804a\u6e05\u695a\u4e86\u600e\u4e48\u7528Kubernetes\u521b\u5efa\u5355\u8282\u70b9\u7684MySQL\u540e\uff0c\u5bf9\u4e8e\u521b\u5efa\u5355\u4f8b\u7684Redis\u76f8\u4fe1\u5927\u5bb6\u5bf9\u5927\u81f4\u6d41\u7a0b\u4e5f\u5c31\u6bd4\u8f83\u6e05\u695a\u4e86\uff0c\u552f\u4e00\u5c11\u7684\u5c31\u662f\u5b9a\u4e49Redis\u670d\u52a1\u7684\u8fd9\u4e9bYAML\u6587\u4ef6\u4e86\u3002\u6211\u5df2\u7ecf\u5e2e\u4f60\u4eec\u8e29\u597d\u5751\u4e86\uff0c\u4e0b\u9762\u8fd9\u4e9bYAML\u90fd\u662f\u6211\u5728\u7ebf\u4e0b\u8c03\u8bd5\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7684\uff0c\u5e76\u4e14\u4e5f\u80fd\u6b63\u786e\u5b8c\u6210Redis\u6570\u636e\u7684\u6301\u4e45\u5316\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u58f0\u660e Redis \u914d\u7f6e\u7684 ConfigMap \u7bc7\u5e45\u592a\u957f\uff0c\u4e3a\u4e86\u4e0d\u5f71\u54cd\u6587\u7ae0\u7684\u9605\u8bfb\u6211\u5c31\u628a\u8fd9\u4e2a\u5b89\u88c5Redis\u9700\u8981\u7684YAML\u6587\u4ef6\u90fd\u653e\u5728GitHub\u4e0a\u4e86\uff0c\u53ef\u4ee5\u70b9\u51fb\u9605\u8bfb\u539f\u6587\u6216\u8005\u901a\u8fc7\u94fe\u63a5\uff1ahttps:\/\/github.com\/kevinyan815\/LearningKubernetes \u8bbf\u95ee\u4e0b\u8f7d\u3002<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u4ed3\u5e93\u91cc\u6211\u7ed9\u51fa\u4e86MySQL\u548cRedis\u7684\u8be6\u7ec6\u5b89\u88c5\u6b65\u9aa4\uff0c\u4ee5\u53ca\u5404\u79cd\u8d44\u6e90\u7684YAML\u5b9a\u4e49\u6587\u4ef6\uff0c\u5305\u62ec\u4e4b\u524d\u5b89\u88c5ETCD\u96c6\u7fa4\u7684\u6559\u7a0b\u4e5f\u6574\u5408\u5230\u4e86\u8fd9\u4e2a\u4ed3\u5e93\u91cc\u3002<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u8fd9\u7bc7\u6587\u7ae0\u91cc\u6574\u7406\u4e86\u5728Kubernetes\u4e0a\u5b89\u88c5MySQL\u548cRedis\u8fd9\u4e24\u6b3e\u6211\u4eec\u5e38\u7528\u7684\u57fa\u7840\u8f6f\u4ef6\u7684\u64cd\u4f5c\u6b65\u9aa4\uff0c\u7531\u4e8e\u76ee\u7684\u662f\u5728\u672c\u5730\u5f00\u53d1\u73af\u5883\u7528\uff0c\u6240\u4ee5\u529b\u6c42\u8d44\u6e90\u5b9a\u4e49\u5c3d\u91cf\u7b80\u5355\uff0c\u80fd\u505a\u5230\u6570\u636e\u53ef\u6301\u4e45\u5316\u5c31\u884c\u4e86\uff0c\u9ad8\u53ef\u7528\u4e0d\u518d\u8fd9\u91cc\u8ba8\u8bba\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1a\u5229\u7528Kubernetes\u642d\u5efa\u4fbf\u643a\u5f0f\u5f00\u53d1\u73af\u5883\u4e4bMySQL\u548cRedis \u80cc\u666f \u4e4b\u524d\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u8fc7\uff0c \u6211\u81ea\u5df1\u7528\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17368"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17368"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17368\/revisions"}],"predecessor-version":[{"id":17387,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17368\/revisions\/17387"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}