{"id":1580,"date":"2020-06-09T16:26:48","date_gmt":"2020-06-09T08:26:48","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1580"},"modified":"2020-06-09T16:26:48","modified_gmt":"2020-06-09T08:26:48","slug":"kubernetes-replication-controller","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1580","title":{"rendered":"Kubernetes Replication Controller"},"content":{"rendered":"<header class=\\\"entry-header\\\">\n<h1 class=\\\"entry-title\\\">Kubernetes Replication Controller<\/h1>\n<\/header>\n<div class=\\\"entry-content\\\">\n<div id=\\\"toc_container\\\" class=\\\"no_bullets\\\">\n<ul class=\\\"toc_list\\\">\n<li><span class=\\\"toc_number toc_depth_1\\\">1<\/span>\u00a0ReplicationController \u5de5\u4f5c\u539f\u7406\n<ul>\n<li><span class=\\\"toc_number toc_depth_2\\\">1.1<\/span>\u00a0\u793a\u4f8b\uff1a<\/li>\n<li><span class=\\\"toc_number toc_depth_2\\\">1.2<\/span>\u00a0\u5220\u9664ReplicationController\u53ca\u5176Pods<\/li>\n<li><span class=\\\"toc_number toc_depth_2\\\">1.3<\/span>\u00a0\u53ea\u5220\u9664 ReplicationController<\/li>\n<li><span class=\\\"toc_number toc_depth_2\\\">1.4<\/span>\u00a0ReplicationController\u9694\u79bbpod<\/li>\n<\/ul>\n<\/li>\n<li><span class=\\\"toc_number toc_depth_1\\\">2<\/span>\u00a0RC\u5e38\u7528\u65b9\u5f0f<\/li>\n<li><span class=\\\"toc_number toc_depth_1\\\">3<\/span>\u00a0API\u5bf9\u8c61<\/li>\n<li><span class=\\\"toc_number toc_depth_1\\\">4<\/span>\u00a0RC \u66ff\u4ee3\u65b9\u6cd5\n<ul>\n<li><span class=\\\"toc_number toc_depth_2\\\">4.1<\/span>\u00a0ReplicaSet<\/li>\n<li><span class=\\\"toc_number toc_depth_2\\\">4.2<\/span>\u00a0Deployment\uff08\u63a8\u8350\uff09<\/li>\n<li><span class=\\\"toc_number toc_depth_2\\\">4.3<\/span>\u00a0Bare Pods<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<p>\u6ce8\u610f\uff1a\u5efa\u8bae\u4f7f\u7528Deployment\u00a0\u914d\u7f6e\u00a0ReplicaSet\u00a0\uff08\u7b80\u79f0RS\uff09\u65b9\u6cd5\u6765\u63a7\u5236\u526f\u672c\u6570\u3002<br \/>\nReplicationController\uff08\u7b80\u79f0RC\uff09\u662f\u786e\u4fdd\u7528\u6237\u5b9a\u4e49\u7684Pod\u526f\u672c\u6570\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<h2 id=\\\"how-a-replicationcontroller-works\\\"><span id=\\\"ReplicationController\\\">ReplicationController \u5de5\u4f5c\u539f\u7406<\/span><\/h2>\n<p>\u5728\u7528\u6237\u5b9a\u4e49\u8303\u56f4\u5185\uff0c\u5982\u679cpod\u589e\u591a\uff0c\u5219ReplicationController\u4f1a\u7ec8\u6b62\u989d\u5916\u7684pod\uff0c\u5982\u679c\u51cf\u5c11\uff0cRC\u4f1a\u521b\u5efa\u65b0\u7684pod\uff0c\u59cb\u7ec8\u4fdd\u6301\u5728\u5b9a\u4e49\u8303\u56f4\u3002\u4f8b\u5982\uff0cRC\u4f1a\u5728Pod\u7ef4\u62a4\uff08\u4f8b\u5982\u5185\u6838\u5347\u7ea7\uff09\u540e\u5728\u8282\u70b9\u4e0a\u91cd\u65b0\u521b\u5efa\u65b0Pod\u3002<br \/>\n\u6ce8\uff1a<\/p>\n<ul>\n<li>ReplicationController\u4f1a\u66ff\u6362\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\u800c\u88ab\u5220\u9664\u6216\u7ec8\u6b62\u7684pod\uff0c\u4f8b\u5982\u5728\u8282\u70b9\u6545\u969c\u6216\u4e2d\u65ad\u8282\u70b9\u7ef4\u62a4\uff08\u4f8b\u5982\u5185\u6838\u5347\u7ea7\uff09\u7684\u60c5\u51b5\u4e0b\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u5e94\u7528\u53ea\u9700\u8981\u4e00\u4e2apod\uff0c\u6211\u4eec\u4e5f\u5efa\u8bae\u4f7f\u7528ReplicationController\u3002<\/li>\n<li>RC\u8de8\u591a\u4e2aNode\u8282\u70b9\u76d1\u89c6\u591a\u4e2apod\u3002<\/li>\n<\/ul>\n<h3><span id=\\\"i\\\">\u793a\u4f8b\uff1a<\/span><\/h3>\n<p>replication.yaml<\/p>\n<pre>apiVersion: v1\nkind: ReplicationController\nmetadata:\n  name: nginx\nspec:\n  replicas: 3\n  selector:\n    app: nginx\n  template:\n    metadata:\n      name: nginx\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: nginx\n        ports:\n        - containerPort: 80<\/pre>\n<p>\u4e0b\u8f7d\u793a\u4f8b\u6587\u4ef6\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n<div>\n<pre>$ kubectl create -f .\/replication.yaml\nreplicationcontroller \\\"nginx\\\" created\n<\/pre>\n<\/div>\n<p>\u68c0\u67e5ReplicationController\u72b6\u6001\uff1a<\/p>\n<div>\n<pre>$ kubectl describe replicationcontrollers\/nginx\nName:        nginx\nNamespace:   default\nImage(s):    nginx\nSelector:    app=nginx\nLabels:      app=nginx\nReplicas:    3 current \/ 3 desired\nPods Status: 0 Running \/ 3 Waiting \/ 0 Succeeded \/ 0 Failed\nEvents:\n  FirstSeen       LastSeen     Count    From                        SubobjectPath    Type      Reason              Message\n  ---------       --------     -----    ----                        -------------    ----      ------              -------\n  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-qrm3m\n  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-3ntk0\n  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-4ok8v\n<\/pre>\n<\/div>\n<p>\u521b\u5efa\u4e86\u4e09\u4e2apod\uff1a<\/p>\n<div>\n<pre>Pods Status:    3 Running \/ 0 Waiting \/ 0 Succeeded \/ 0 Failed\n<\/pre>\n<\/div>\n<p>\u5217\u51fa\u5c5e\u4e8eReplicationController\u7684\u6240\u6709pod\uff1a<\/p>\n<div>\n<pre>$ pods=$(kubectl get pods --selector=app=nginx --output=jsonpath={.items..metadata.name})\necho $pods\nnginx-3ntk0 nginx-4ok8v nginx-qrm3m<\/pre>\n<\/div>\n<h3 id=\\\"deleting-a-replicationcontroller-and-its-pods\\\"><span id=\\\"ReplicationControllerPods\\\">\u5220\u9664ReplicationController\u53ca\u5176Pods<\/span><\/h3>\n<p>\u4f7f\u7528kubectl delete\u547d\u4ee4\u5220\u9664ReplicationController\u53ca\u5176\u6240\u6709pod\u3002<br \/>\n\u5f53\u4f7f\u7528REST API\u6216\u5ba2\u6237\u7aef\u5e93\u65f6\uff0c\u9700\u8981\u660e\u786e\u5730\u6267\u884c\u8fd9\u4e9b\u6b65\u9aa4\uff08\u5c06\u526f\u672c\u7f29\u653e\u4e3a0\uff0c\u7b49\u5f85pod\u5220\u9664\uff0c\u7136\u540e\u5220\u9664ReplicationController\uff09\u3002<\/p>\n<h3 id=\\\"deleting-just-a-replicationcontroller\\\"><span id=\\\"_ReplicationController\\\">\u53ea\u5220\u9664 ReplicationController<\/span><\/h3>\n<p>\u5728\u5220\u9664ReplicationController\u65f6\uff0c\u53ef\u4ee5\u4e0d\u5f71\u54cd\u4efb\u4f55pod\u3002<br \/>\n\u4f7f\u7528kubectl\uff0c\u4e3akubectl delete\u6307\u5b9a- cascade = false\u9009\u9879\u3002<br \/>\n\u4f7f\u7528REST API\u6216go\u5ba2\u6237\u7aef\u5e93\u65f6\uff0c\u53ea\u9700\u5220\u9664ReplicationController\u5bf9\u8c61\u5373\u53ef\u3002<br \/>\n\u539f\u59cb\u6587\u4ef6\u88ab\u5220\u9664\u540e\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684ReplicationController\u6765\u66ff\u6362\u5b83\u3002\u53ea\u8981\u65e7\u7684\u548c\u65b0.spec.selector \u76f8\u5339\u914d\uff0c\u90a3\u4e48\u65b0\u7684\u5c06\u4f1a\u91c7\u7528\u65e7\u7684Pod\u3002<\/p>\n<h3 id=\\\"isolating-pods-from-a-replicationcontroller\\\"><span id=\\\"ReplicationControllerpod\\\">ReplicationController\u9694\u79bbpod<\/span><\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u66f4\u6539\u6807\u7b7e\u6765\u4eceReplicationController\u7684\u76ee\u6807\u96c6\u4e2d\u5220\u9664Pod\u3002<\/p>\n<h2 id=\\\"common-usage-patterns\\\"><span id=\\\"RC\\\">RC\u5e38\u7528\u65b9\u5f0f<\/span><\/h2>\n<ul>\n<li>Rescheduling\uff08\u91cd\u65b0\u89c4\u5212\uff09<\/li>\n<li id=\\\"scaling\\\">\u6269\u5c55<\/li>\n<li id=\\\"rolling-updates\\\">\u6eda\u52a8\u66f4\u65b0<\/li>\n<li>\u591a\u7248\u672c\u8ddf\u8e2a<\/li>\n<li>\u4f7f\u7528ReplicationControllers\u4e0e\u5173\u8054\u7684Services<\/li>\n<\/ul>\n<h2 id=\\\"api-object\\\"><span id=\\\"API\\\">API\u5bf9\u8c61<\/span><\/h2>\n<p>Replication controller\u662fKubernetes REST API\u4e2d\u7684\u9876\u7ea7\u8d44\u6e90\u3002<\/p>\n<h2 id=\\\"alternatives-to-replicationcontroller\\\"><span id=\\\"RC-2\\\">RC \u66ff\u4ee3\u65b9\u6cd5<\/span><\/h2>\n<h3 id=\\\"replicaset\\\"><span id=\\\"ReplicaSet\\\">ReplicaSet<\/span><\/h3>\n<p><a href=\\\"http:\/\/docs.kubernetes.org.cn\/314.html\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">ReplicaSet<\/a>\u662f\u652f\u6301\u65b0\u7684set-based\u9009\u62e9\u5668\u8981\u6c42\u7684\u4e0b\u4e00\u4ee3ReplicationController\u00a0\u3002\u5b83\u4e3b\u8981\u7528\u4f5c<a href=\\\"http:\/\/docs.kubernetes.org.cn\/317.html\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">Deployment<\/a>\u534f\u8c03pod\u521b\u5efa\u3001\u5220\u9664\u548c\u66f4\u65b0\u3002\u8bf7\u6ce8\u610f\uff0c\u9664\u975e\u9700\u8981\u81ea\u5b9a\u4e49\u66f4\u65b0\u7f16\u6392\u6216\u6839\u672c\u4e0d\u9700\u8981\u66f4\u65b0\uff0c\u5426\u5219\u5efa\u8bae\u4f7f\u7528Deployment\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528ReplicaSets\u3002<\/p>\n<h3 id=\\\"deployment-recommended\\\"><span id=\\\"Deployment\\\">Deployment\uff08\u63a8\u8350\uff09<\/span><\/h3>\n<p><a href=\\\"http:\/\/docs.kubernetes.org.cn\/317.html\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">Deployment<\/a>\u662f\u4e00\u4e2a\u9ad8\u7ea7\u7684API\u5bf9\u8c61\uff0c\u4ee5\u7c7b\u4f3c\u7684\u65b9\u5f0f\u66f4\u65b0\u5176\u5e95\u5c42\u7684\u526f\u672c\u96c6\u548c\u5b83\u4eec\u7684Pods\u00a0kubectl rolling-update\u3002\u5982\u679c\u60a8\u5e0c\u671b\u4f7f\u7528\u8fd9\u79cd\u6eda\u52a8\u66f4\u65b0\u529f\u80fd\uff0c\u5efa\u8bae\u60a8\u8fdb\u884c\u90e8\u7f72\uff0c\u56e0\u4e3akubectl rolling-update\u5b83\u4eec\u662f\u58f0\u660e\u5f0f\u7684\uff0c\u670d\u52a1\u5668\u7aef\u7684\uff0c\u5e76\u5177\u6709\u5176\u4ed6\u529f\u80fd\u3002<\/p>\n<h3 id=\\\"bare-pods\\\"><span id=\\\"Bare_Pods\\\">Bare Pods<\/span><\/h3>\n<p>\u4e0e\u7528\u6237\u76f4\u63a5\u521b\u5efapod\u7684\u60c5\u51b5\u4e0d\u540c\uff0cReplicationController\u4f1a\u66ff\u6362\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\u800c\u88ab\u5220\u9664\u6216\u7ec8\u6b62\u7684pod\uff0c\u4f8b\u5982\u5728\u8282\u70b9\u6545\u969c\u6216\u4e2d\u65ad\u8282\u70b9\u7ef4\u62a4\uff08\u4f8b\u5982\u5185\u6838\u5347\u7ea7\uff09\u7684\u60c5\u51b5\u4e0b\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u5e94\u7528\u53ea\u9700\u8981\u4e00\u4e2apod\uff0c\u6211\u4eec\u4e5f\u5efa\u8bae\u4f7f\u7528ReplicationController\u3002\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes Replication Controller 1\u00a0ReplicationControll &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1580\"> <span class=\"screen-reader-text\">Kubernetes Replication Controller<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[104,123],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"Kubernetes Replication Controller 1\u00a0ReplicationControll&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1580"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1580"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1580\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1580"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}