{"id":172286,"date":"2020-10-25T19:15:28","date_gmt":"2020-10-25T11:15:28","guid":{"rendered":"http:\/\/4563.org\/?p=172286"},"modified":"2020-10-25T19:15:28","modified_gmt":"2020-10-25T11:15:28","slug":"k8s-%e4%bd%bf%e7%94%a8-statefulset-%e5%a6%82%e4%bd%95%e5%9c%a8-pod-%e5%86%85%e8%8e%b7%e5%8f%96%e5%ba%8f%e5%8f%b7%e5%b9%b6%e8%ae%be%e7%bd%ae%e5%88%b0%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e9%87%8c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=172286","title":{"rendered":"k8s \u4f7f\u7528 statefulset \u5982\u4f55\u5728 pod \u5185\u83b7\u53d6\u5e8f\u53f7\u5e76\u8bbe\u7f6e\u5230\u73af\u5883\u53d8\u91cf\u91cc"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  k8s \u4f7f\u7528 statefulset \u5982\u4f55\u5728 pod \u5185\u83b7\u53d6\u5e8f\u53f7\u5e76\u8bbe\u7f6e\u5230\u73af\u5883\u53d8\u91cf\u91cc               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liunaijie <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5982\u9898\uff0c\u4f7f\u7528 statefulset\uff0c\u9700\u8981\u4e3a\u6bcf\u4e2a pod \u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u914d\u7f6e\u4e0d\u540c\u7684\u503c\uff0c\u6bd4\u5982\u5728 pod1 \u91cc\u9762\u7684\u503c\u662f value1\uff0cpod2 \u91cc\u9762\u7684\u503c\u662f value2 \u3002 \u53ef\u4ee5\u521b\u5efa\u591a\u4e2a configmap \u6765\u6302\u8f7d\uff0c\u4f46\u662f\u6211\u60f3\u4f7f\u7528\u4e00\u4e2a configmap \u7136\u540e\u4f7f\u7528\u52a8\u6001\u66ff\u6362\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u6240\u4ee5\u60f3\u5728 stateful-pod-0 \u4e2d\u83b7\u53d6 0\uff0c\u7136\u540e\u5c06\u5176\u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u5728 stateful-pod-1 \u4e2d\u83b7\u53d6 1 \u5c06\u5176\u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\u3002\u914d\u7f6e\u6587\u4ef6\u901a\u8fc7\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\u4e3a\u5176\u8d4b\u503c\u3002<\/p>\n<pre><code>        env:           - name: REPLICA             valueFrom:               fieldRef:                 fieldPath: metadata.name           - name: SHARD             value: $(REPLICA##*-) ## get the statefulset pod index, like stateful-0, get 0 <\/code><\/pre>\n<p>\u6211\u4e5f\u7528\u5176\u4ed6\u65b9\u6cd5\u5c1d\u8bd5\u8fc7\uff0c\u6bd4\u5982\u5728\u542f\u52a8\u5230\u65f6\u5019\u8fd0\u884c\u547d\u4ee4\uff0c\u4f46\u662f\u8fd9\u4e2a\u65f6\u5019 pod \u5c31\u8d77\u4e0d\u6765\u4e86<\/p>\n<pre><code>        command: [\"\/bin\/sh\", \"-c\", \"export SHARD=${HOSTNAME##*-}\"] <\/code><\/pre>\n<p>\u6709\u6ca1\u6709\u5927\u4f6c\u4e86\u89e3\u8fd9\u79cd\u60c5\u51b5\u8981\u600e\u4e48\u8bbe\u7f6e<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3874493\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acrisliu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 InitContainer \u8bfb\u53d6 HOSTNAME \u518d\u5199\u5165\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3874494\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhenjiachen <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u540c\u6c42\uff0c\u6211\u4e5f\u60f3\u77e5\u9053\uff0c\u641c\u4e86\u4e00\u5708\u6ca1\u6709\u5565\u597d\u7684\u89e3\u51b3\u65b9\u6848                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3874495\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JeromeCui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u4e2a\u73af\u5883\u53d8\u91cf\uff1aHOSTNAME=microservice-discovery-0\uff0c\u6700\u540e\u90a3\u4e2a 0 \u5c31\u662f\u5e8f\u53f7<br \/>\u4f60\u53ef\u4ee5\u8bfb\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u6216\u8005\u662f\u8bfb\u6587\u4ef6 \/etc\/hostname                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3874496\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 1423 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JeromeCui \u662f\u8fd9\uff0c\u6211\u4eec\u4e5f\u6709\u8fd9\u4e48\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3874497\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : liunaijie <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JeromeCui \u662f\u7684\uff0c\u53ef\u4ee5\u8bfb\u5230\u8fd9\u4e2a hostname\uff0c\u4f46\u662f\u8981\u622a\u53d6\u540e\u9762\u7684\u5e8f\u53f7\uff0c\u6ca1\u6cd5\u5728 env \u91cc\u9762\u505a\u8f6c\u6362                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3874498\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzbkl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u770b k8s downward API \u662f\u4e0d\u662f\u4f60\u60f3\u8981\u7684\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>k8s \u4f7f\u7528 statefulse&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172286"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172286"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172286\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}