{"id":1005,"date":"2018-03-22T23:35:07","date_gmt":"2018-03-22T15:35:07","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1005"},"modified":"2018-03-22T23:35:07","modified_gmt":"2018-03-22T15:35:07","slug":"kubernetes-service","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2018\/03\/kubernetes-service\/","title":{"rendered":"Kubernetes\u670d\u52a1service\u7684\u8d1f\u8f7d\u5747\u8861\u5206\u6790"},"content":{"rendered":"

Kubernetes\u670d\u52a1service\u7684\u8d1f\u8f7d\u5747\u8861\u5206\u6790.md<\/p>\n

Kubernetes\u662f\u5982\u4f55\u5b9e\u73b0service\u4e2d\u4e0d\u540cPod\u7684\u8d1f\u8f7d\u5747\u8861\u5462\uff1f<\/p>\n

\u7531\u4e8eKubernetes\u7684service\u662f\u901a\u8fc7iptables\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u9700\u8981\u5206\u6790iptable\u89c4\u5219\u3002<\/p>\n

\u521b\u5efa\u6d4b\u8bd5\u73af\u5883<\/h2>\n

\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2adeployment\uff0c\u5305\u542b4\u4e2aPod\uff0c\u7136\u540e\u5206\u522b\u521b\u5efa\u4e862\u4e2aservice\uff0c\u7c7b\u578b\u662fClusterIP\u548cNodePort\u90fd\u6307\u5411\u540c\u4e00\u4e2adeployment 'stilton'\u3002\u5982\u4e0b\uff0c<\/p>\n

\n
[root@idc-sm-rd-k8s-m-1 ~]# kubectl get deploy\nNAME      DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE\nstilton  4        4        4            4          6d\n[root@idc-sm-rd-k8s-m-1 ~]# kubectl get svc\nNAME        TYPE        CLUSTER-IP      EXTERNAL-IP  PORT(S)        AGE\nkubernetes  ClusterIP  10.254.0.1      <none>        443\/TCP        6d\nstilton      ClusterIP  10.254.206.15    <none>        80\/TCP        6d\nstilton02    NodePort    10.254.192.239  <none>        80:30735\/TCP  3d<\/code><\/pre>\n<\/div>\n

\u5206\u6790iptables\u89c4\u5219<\/h2>\n

\u4f7f\u7528iptables-save\u6253\u5370\u6240\u6709\u7684iptables\u89c4\u5219\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u5982\u4e0b\u76f8\u5173\u5185\u5bb9<\/p>\n

\n
-A KUBE-SVC-W6WAXM5BH6NL6XVI -m comment --comment \"default\/stilton:http\" -m statistic --mode random --probability 0.25000000000 -j KUBE-SEP-CNYVGC2BVT2LZTTQ\n-A KUBE-SVC-W6WAXM5BH6NL6XVI -m comment --comment \"default\/stilton:http\" -m statistic --mode random --probability 0.33332999982 -j KUBE-SEP-JIUL6WA4RDBFQM3A\n-A KUBE-SVC-W6WAXM5BH6NL6XVI -m comment --comment \"default\/stilton:http\" -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-N7FRCVWSMEQSSPP6\n-A KUBE-SVC-W6WAXM5BH6NL6XVI -m comment --comment \"default\/stilton:http\" -j KUBE-SEP-4IO5BXFRFMJKHYHX<\/code><\/pre>\n<\/div>\n

\u5173\u952e\u4e4b\u5904\u5c31\u5728-m statistic --mode random --probability 0.25 \u8fd9\u4e2a\u5730\u65b9\u4e86\uff0c\u5f88\u4e45\u4ee5\u524d\u6211\u4eec\u66fe\u7ecf\u4f7f\u7528\u8fd9\u4e2a\u72b6\u6001\u6765\u5b9e\u73b0\u6982\u7387\u6027\u4e22\u5305(\u6a21\u62df\u8f83\u5dee\u7684\u7f51\u7edc\u73af\u5883)<\/p>\n

\n
# for randomly dropping 10% of incoming packets:\niptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP<\/code><\/pre>\n<\/div>\n

\u8fd9\u91ccKubernetes\u4f7f\u7528\u4e86\u6982\u7387\u6765\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n

\u4e00\u51714\u4e2a\u5bb9\u5668\uff0c\u7b2c\u4e00\u4e2a\u5bb9\u5668\u5206\u5230\u4e861\/4\u7684\u6d41\u91cf\u3002
\n\u7b2c\u4e8c\u4e2a\u5bb9\u5668\uff0c\u56e0\u4e3a\u5269\u4f593\/4\uff0c\u6240\u4ee5\u4e58\u4ee51\/3\uff0c\u6240\u4ee5\u4e5f\u662f1\/4\u7684\u6d41\u91cf\u3002
\n\u7b2c\u4e09\u4e2a\u5bb9\u5668\u662f\uff0c1\/2\u4e58\u4ee51\/2\uff0c\u4e5f\u4f1a\u5f97\u52301\/4\u7684\u6d41\u91cf\u3002
\n\u7b2c\u56db\u4e2a\u5bb9\u5668\uff0c\u83b7\u53d6\u5269\u4f59\u76841\/4\u3002<\/p>\n

<\/p>\n

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n

<\/wiz_tmp_tag><\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » Kubernetes\u670d\u52a1service\u7684\u8d1f\u8f7d\u5747\u8861\u5206\u6790<\/a><\/p>","protected":false},"excerpt":{"rendered":"

Kubernetes\u670d\u52a1service\u7684\u8d1f\u8f7d\u5747\u8861\u5206\u6790.md Kubernetes\u662f\u5982\u4f55\u5b9e\u73b0service\u4e2d\u4e0d\u540cPod\u7684\u8d1f\u8f7d\u5747\u8861\u5462\uff1f \u7531\u4e8eKubernetes\u7684service\u662f\u901a\u8fc7iptables\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u9700\u8981\u5206\u6790iptable\u89c4\u5219\u3002 \u521b\u5efa\u6d4b\u8bd5\u73af\u5883 \u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2adeployment\uff0c\u5305\u542b4\u4e2aPod\uff0c\u7136\u540e\u5206\u522b\u521b\u5efa\u4e862\u4e2aservice\uff0c\u7c7b\u578b\u662fClusterIP\u548cNodePort\u90fd\u6307\u5411\u540c\u4e00\u4e2adeployment ‘stilton’\u3002\u5982\u4e0b\uff0c [root@idc-sm-rd-k8s-m-1 ~]# kubectl get deploy NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE stilton 4 4 4 4 6d [root@idc-sm-rd-k8s-m-1 ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.254.0.1 <none> 443\/TCP 6d stilton ClusterIP 10.254.206.15 <none> 80\/TCP 6d stilton02 NodePort 10.254.192.239 <none> 80:30735\/TCP 3d \u5206\u6790iptables\u89c4\u5219 \u4f7f\u7528iptables-save\u6253\u5370\u6240\u6709\u7684iptables\u89c4\u5219\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u5982\u4e0b\u76f8\u5173\u5185\u5bb9 -A […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[145,129,146,127],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1005"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1005"}],"version-history":[{"count":0,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1005\/revisions"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}