{"id":11599,"date":"2023-08-01T16:15:53","date_gmt":"2023-08-01T08:15:53","guid":{"rendered":"http:\/\/92it.top\/?p=11599"},"modified":"2025-07-29T14:26:31","modified_gmt":"2025-07-29T06:26:31","slug":"pod%e5%b8%b8%e7%94%a8%e6%8e%a7%e5%88%b6%e5%99%a8%e4%bb%8b%e7%bb%8d%ef%bc%88deployment%e3%80%81statefulset%e3%80%81job%e3%80%81cronjob%e3%80%81daemonset%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11599","title":{"rendered":"pod\u5e38\u7528\u63a7\u5236\u5668\u4ecb\u7ecd\uff08deployment\u3001StatefulSet\u3001Job\u3001CronJob\u3001DaemonSet\uff09"},"content":{"rendered":"\n<p><strong>\u4f55\u4e3apod\u63a7\u5236\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>pod\u63a7\u5236\u5668\uff0c\u662f\u7528\u4e8e\u7ba1\u7406\u3001\u90e8\u7f72pod\u7684\u4e00\u79cdk8s\u4e2d\u91cd\u8981\u7684\u8d44\u6e90\uff0c\u786e\u4fddpod\u8d44\u6e90\u7b26\u5408\u9884\u671f\u7684\u72b6\u6001\uff0cpod\u7684\u8d44\u6e90\u51fa\u73b0\u6545\u969c\u65f6\uff0c\u4f1a\u5c1d\u8bd5 \u8fdb\u884c\u91cd\u542f\uff0c\u5f53\u6839\u636e\u91cd\u542f\u7b56\u7565\u65e0\u6548\uff0c\u5219\u4f1a\u65b0\u5efapod\u7684\u8d44\u6e90\u3002\u8fd9\u6837\uff0c\u5f53\u6709\u4e86\u63a7\u5236\u5668\u6765\u7ba1\u7406pod\uff0c\u6211\u4eec\u5c31\u80fd\u8f7b\u677e\u7684\u901a\u8fc7\u914d\u7f6e\u63a7\u5236\u5668\uff0c\u8ba9\u63a7\u5236\u5668\u6765\u5e2e\u6211\u4eec\u5b9e\u73b0\u6211\u4eec\u6240\u671f\u671b\u7684pod\u6269\u5bb9\u3001\u7f29\u5bb9\uff0c\u5373\u4f7f\u5f53pod\u51fa\u73b0\u5f02\u5e38\u6302\u6389\uff0c\u63a7\u5236\u5668\u4e5f\u80fd\u7acb\u5373\u91cd\u65b0\u542f\u52a8\u4e00\u4e2apod\uff0c\u56e0\u4e3a\u63a7\u5236\u5668\u7684\u672c\u8d28\u5176\u5b9e\u5c31\u662f\u5b9e\u65f6\u68c0\u67e5pod\u6570\u91cf\u4f7f\u5176\u7b26\u5408\u6211\u4eec\u9884\u5148\u8bbe\u5b9a\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u5e38\u7528pod\u63a7\u5236\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u5e38\u7528\u7684pod\u63a7\u5236\u5668\u6709\u4e00\u4e0b\u51e0\u79cd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ReplicationController: \u6bd4\u8f83\u539f\u59cb\u7684pod\u63a7\u5236\u5668,\u5df2\u7ecf\u88ab\u5e9f\u5f03,\u4e86\u89e3\u5373\u53ef,\u6709ReplicaSet\u66ff\u4ee3;<br><br>ReplicaSet: \u4fdd\u8bc1\u6307\u5b9a\u6570\u91cf\u7684pod\u8fd0\u884c,\u5e76\u63d0\u4f9bpod\u6570\u636e\u53d8\u66f4,\u955c\u50cf\u7248\u672c\u53d8\u66f4;<br><br>DaemonSet: \u5728\u96c6\u7fa4\u6bcf\u4e2anode\u4e0a\u90fd\u8fd0\u884c\u4e00\u4e2apod,\u786e\u4fdd\u5168\u90e8Node \u4e0a\u8fd0\u884c\u4e00\u4e2a Pod \u7684\u526f\u672c,\u9002\u7528\u4e8e\u6bcf\u4e2anode\u5de5\u4f5c\u8282\u70b9\u540e\u53f0\u65e5\u5fd7\u6536\u96c6\u7b49\u573a\u666f;<br><br>CronJob: \u7528\u4e8e\u6267\u884c\u5468\u671f\u6027\u5b9a\u65f6\u4efb\u52a1\u7684pod,\u4e3b\u8981\u7528\u4e8e\u6267\u884c\u5468\u671f\u6027\u8ba1\u5212,\u7c7b\u4f3c\u4e8eLinux\u7684crontab\u5b9a\u65f6\u4efb\u52a1;<br><br>Job: \u7528\u4e8e\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\u7684pod\uff0c\u6267\u884c\u5b8c\u6bd5pod\u5c31\u7acb\u5373\u9000\u51fa,\u7c7b\u4f3c\u4e8eLinux\u7684at\u547d\u4ee4;<br><br>Deployment: \u901a\u8fc7\u521b\u5efaDaemonSet\u6765\u521b\u5efapod,\u652f\u6301\u6eda\u52a8\u5347\u7ea7,\u7248\u672c\u56de\u9000,Deployment\u662f\u6700\u5e38\u7528\u7684pod\u63a7\u5236\u5668;<br><br>Horizontal Pod Autoscaler: \u53ef\u4ee5\u6839\u636e\u96c6\u7fa4\u8d1f\u8f7d\u81ea\u52a8\u8c03\u6574pod\u7684\u6570\u91cf\uff0c\u5b9e\u73b0\u81ea\u52a8\u6269\u5bb9\u7f29\u5bb9,\u524a\u5cf0\u586b\u8c37;<br><br>StatefulSet: \u7ba1\u7406\u53c8\u72b6\u6001\u7684\u5e94\u7528;<br>\u3000<br><\/pre>\n\n\n\n<p><strong>ReplicationController\u4ecb\u7ecd\uff08\u5df2\u5e9f\u5f03\uff0c\u57fa\u672c\u4e0d\u4f1a\u7528\u5230\u8fd9\u79cd\u63a7\u5236\u5668\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>ReplicationController\uff0c\u7b80\u5199rc\uff0c\u662fk8s\u4e2d\u4e00\u79cdpod\u63a7\u5236\u5668\uff0c\u5728\u65b0\u7248\u672c\u4e2d\uff0crc\u5df2\u7ecf\u88ab\u53d6\u4ee3\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e86\u89e3rc\u5373\u53ef\uff1b<br>ReplicationController\u4f1a\u6301\u7eed\u76d1\u63a7\u6b63\u5728\u8fd0\u884c\u7684pod\u5217\u8868\uff0c\u5e76\u4fdd\u8bc1\u76f8\u5e94\u6807\u7b7e\u7c7b\u578b\u7684pod\u6570\u91cf\u4e0e\u671f\u671b\u7684\u76f8\u7b26\uff0c\u5982\u6b63\u5728\u8fd0\u884c\u7684pod\u592a\u5c11\uff0crc\u5c31\u4f1a\u6839\u636epod\u6a21\u677f\u6765\u521b\u5efa\u65b0\u7684\u526f\u672c\uff0c\u5982\u679c\u6b63\u5728\u8fd0\u884c\u7684pod\u592a\u591a\uff0crc\u5c06\u4f1a\u5220\u9664\u591a\u4f59\u7684pod\u3002<br>\u603b\u4e4b\uff0cReplicationController\u7684\u5de5\u4f5c\u5c31\u662f\u786e\u4fddpod\u6570\u636e\u59cb\u7ec8\u4e0e\u5176\u5b9a\u4e49\u7684\u6807\u7b7e\u9009\u62e9\u5668\u9009\u4e2d\u7684pod\u6570\u91cf\u76f8\u5339\u914d\uff0c\u5982\u679c\u4e0d\u5339\u914d\uff0crc\u5c06\u4f1a\u6839\u636e\u6240\u9700\uff0c\u91c7\u53d6\u9002\u5f53\u7684\u64cd\u4f5c\u6765\u534f\u8c03pod\u6570\u91cf\u3002<\/p>\n\n\n\n<p><strong>rc\u7684\u4e09\u5927\u90e8\u5206<\/strong><\/p>\n\n\n\n<ul>\n<li>1\u3001label selector\uff0c\u6807\u7b7e\u9009\u62e9\u5668\uff0c\u7528\u4e8e\u786e\u5b9arc\u4f5c\u7528\u4e8e\u54ea\u4e9bpod\uff0c\u53cd\u8fc7\u6765\u8bf4\u54ea\u4e9bpod\u53ef\u4ee5\u88abrc\u7ba1\u7406\uff1b<\/li>\n\n\n\n<li>2\u3001replica\uff0c\u526f\u672c\u6570\uff0c\u6307\u5b9a\u8fd0\u884c\u7684pod\u6570\u91cf\uff1b<\/li>\n\n\n\n<li>3\u3001pod template\uff0cpod\u6a21\u677f\uff0c\u7528\u4e8e\u521b\u5efa\u65b0\u7684pod\u526f\u672c\uff0cpod\u5c31\u662f\u6839\u636e\u6a21\u677f\u6765\u521b\u5efa\u7684\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>rc\u7684\u5b9e\u73b0\u539f\u7406<\/strong><\/p>\n\n\n\n<p>rc\u4e0epod\u5176\u5b9e\u662f\u901a\u8fc7\u6807\u7b7e\u548c\u6807\u7b7e\u9009\u62e9\u5668\u6765\u8fdb\u884c\u7ba1\u8054\u7684\uff0c\u5f53\u6539\u53d8\u4e00\u4e2apod\u7684\u6807\u7b7e\uff0c\u90a3\u4e48\u8be5pod\u5c31\u4f1a\u8131\u79bbrc\u7684\u7ba1\u7406\uff0c\u800crc \u53d1\u73b0\u5c11\u4e86\u4e00\u4e2apod\uff0c\u53c8\u4f1a\u6839\u636e\u6a21\u677f\u91cd\u65b0\u521b\u5efa\u4e00\u4e2apod\u6765\u6ee1\u8db3\u526f\u672c\u6570\u3002\u5982\u679c\u5148\u72ec\u7acb\u521b\u5efa\u4e86pod\u5e76\u5b9a\u4e49\u4e86\u6807\u7b7e\uff0c\u7136\u540e\u518d\u521b\u5efarc\uff0crc\u7684\u6807\u7b7e\u7b5b\u9009\u5668\u548c\u5df2\u5b58\u5728\u7684pod\u7684\u6807\u7b7e\u76f8\u540c\uff0c\u90a3\u4e48\u521b\u5efarc\u65f6\uff0crc\u76f4\u63a5\u63a5\u7ba1\u5df2\u5b58\u5728\u7684pod\uff0crc\u6839\u672c\u4e0d\u4f1a\u521b\u5efa\u65b0\u7684pod\uff0c\u8fd9\u5c31\u8bf4\u660e\uff0crc\u4e0epod\u7684\u6839\u672c\u5c31\u662f\u901a\u8fc7\u6807\u7b7e\u548c\u6807\u7b7e\u9009\u62e9\u5668\u6765\u8fdb\u884c\u7ba1\u8054\u7684\u3002<\/p>\n\n\n\n<p><strong>\u66f4\u6539rc\u7684\u6807\u7b7e\u9009\u62e9\u5668\u548cpod\u6a21\u677f\u4f1a\u600e\u6837<\/strong><\/p>\n\n\n\n<p>\u66f4\u6539rc\u7684\u6807\u7b7e\u9009\u62e9\u5668\u548cpod\u6a21\u677f\u5bf9\u6b63\u5728\u8fd0\u884c\u7684pod\u6ca1\u6709\u5f71\u54cd\uff0c\u66f4\u6539\u6807\u7b7e\u9009\u62e9\u5668\u4f1a\u4f7f\u73b0\u6709\u7684pod\u8131\u79bbrc\u7684\u8303\u56f4\uff0c\u56e0\u6b64rc\u4f1a\u505c\u6b62\u5173\u6ce8\u5b83\u4eec\uff0c\u5b83\u4eec\u79f0\u4e3a\u65e0\u4eba\u6258\u7ba1\u7684pod\u3002\u5982\u679c\u66f4\u6539\u4e86pod\u6a21\u677f\uff0c\u8be5\u6a21\u677f\u4ec5\u5f71\u54cd\u7531rc\u521b\u5efa\u7684\u65b0\u7684pod\u3002<\/p>\n\n\n\n<p><strong>\u521b\u5efa\u4e00\u4e2aReplicationController<\/strong><\/p>\n\n\n\n<p>\u4e0b\u9762\u5c31\u6765\u521b\u5efa\u4e00\u4e2aReplicationController\u8d44\u6e90\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=\"\">[root@master ~]# vim rc_nginx.yaml \napiVersion: v1\nkind: ReplicationController\t\t\t\t#\u521b\u5efa\u4e00\u4e2aReplicationController\u63a7\u5236\u5668\nmetadata:\n  name: rc-nginx\t\t\t\t\t\t#\u63a7\u5236\u5668\u540d\u79f0\n  namespace: default\t\t\t\t\t#\u547d\u540d\u7a7a\u95f4\nspec:\n  replicas: 3\t\t\t\t\t\t\t#\u8868\u793apod\u526f\u672c\u6570\n  selector:\t\t\t\t\t\t\t\t#\u5b9a\u4e49\u6807\u7b7e\u9009\u62e9\u5668\uff0c\u7528\u4e8e\u8bf4\u660erc\u63a7\u5236\u7ba1\u7406\u7684\u662f\u5e26\u6709\u54ea\u4e9b\u6807\u7b7e\u7684pod\n     app: nginx\t\t\t\t\t\t\t#\u6807\u7b7eapp=nginx\n  template:\t\t\t\t\t\t\t\t#\u5b9a\u4e49pod\u6a21\u677f\uff0cpod\u6a21\u677f\u5c31\u662f\u7528\u6765\u521b\u5efapod\n     metadata:\n       labels:\t\t\t\t\t\t\t#pod\u6807\u7b7e\uff0c\u6ce8\u610f\uff1apod\u6807\u7b7e\u5fc5\u987b\u4e0e\u4e0a\u9762\u6807\u7b7e\u9009\u62e9\u5668\u5b9a\u4e49\u7684\u6807\u7b7e\u76f8\u540c\uff0c\u5426\u8005rc\u5c31\u4e0d\u77e5\u9053\u5982\u4f55\u5173\u8054pod\n         app: nginx\n     spec:\n         containers:\n         - image: nginx:1.7.9\n           name: nginx-container\n           ports:\n           - containerPort: 80\n[root@master ~]# kubectl  apply  -f rc_nginx.yaml \t\t\t\t\t\t\t\t#\u5e94\u7528yaml\u6587\u4ef6\n[root@master ~]# kubectl  get rc,pod --show-labels \t\t\t\t\t\t\t\t#\u67e5\u770brc\u548cpod\nNAME                             DESIRED   CURRENT   READY   AGE   LABELS\nreplicationcontroller\/rc-nginx   3         3         3       43m   app=nginx\n\nNAME                 READY   STATUS    RESTARTS   AGE   LABELS\npod\/rc-nginx-4drqr   1\/1     Running   0          43m   app=nginx\npod\/rc-nginx-cn8wv   1\/1     Running   0          43m   app=nginx\npod\/rc-nginx-qwk9j   1\/1     Running   0          43m   app=nginx\n[root@master ~]# \n<\/pre>\n\n\n\n<ul>\n<li>1\u3001\u5728\u521b\u5efareplicationcontroller\u65f6\uff0cpod\u6a21\u677f\u4e2d\u7684\u6807\u7b7e\u5fc5\u987b\u8981\u4e0ereplicationcontroller\u7684\u6807\u7b7e\u9009\u62e9\u5668\u5339\u914d\uff0c\u5426\u5219rc\u5c06\u65e0\u4f11\u6b62\u7684\u521b\u5efapod\uff1b<\/li>\n\n\n\n<li>2\u3001\u53ef\u4ee5\u4e0d\u5199\u6807\u7b7e\u9009\u62e9\u5668\uff0c\u4f46\u6a21\u677f\u4e2d\u5fc5\u987b\u5199\u6807\u7b7e\uff0c\u8fd9\u65f6replicationcontroller\u4f1a\u6839\u636epod\u6a21\u677f\u4e2d\u7684\u6807\u7b7e\u81ea\u52a8\u5339\u914d\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>pod\u6269\u5bb9\u3001\u7f29\u5bb9<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528\u63a7\u5236\u5668\u7ba1\u7406\u7684pod\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u5b9e\u73b0\u6269\u5bb9\u548c\u7f29\u5bb9\uff0c\u5176\u539f\u7406\u5c31\u662f\u901a\u8fc7\u53d8\u66f4\u63a7\u5236\u5668\u7684\u526f\u672c\u6570\uff0c\u5982\u4e0b\u6240\u793a\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=\"\">1\u3001\u901a\u8fc7kubectl scale \u5bf9rc\u63a7\u5236\u5668\u7684pod\u8fdb\u884c\u6269\u5bb9\n[root@master ~]# kubectl scale rc rc-nginx --replicas=5\t\t\t#\u901a\u8fc7kubectl scale\u547d\u4ee4\u5bf9rc\u76f4\u63a5\u53d8\u66f4\u526f\u672c\u6570\u5b9e\u73b0\u6269\u5bb9\u7f29\u5bb9\n2\u3001\u901a\u8fc7kubectl edit \u547d\u4ee4\u76f4\u63a5rc\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u526f\u672c\u6570\n[root@master ~]# kubectl  edit rc rc-nginx\t\t\t\t\t\t#\u76f4\u63a5\u7f16\u8f91rc\u7684\u5b9a\u4e49\u4e2d\u7684\u526f\u672c\u6570\u5b9e\u73b0\u6269\u5bb9\u7f29\u5bb9\n<\/pre>\n\n\n\n<p><strong>\u5220\u9664replicationcontroller<\/strong><\/p>\n\n\n\n<p>\u5f53\u4e0d\u5728\u9700\u8981replicationcontroller\u65f6\uff0c\u53ef\u4ee5\u5220\u9664replicationcontroller\uff0c\u5220\u9664replicationcontroller\u9ed8\u8ba4\u60c5\u51b5\u4f1a\u628apod\u4e00\u8d77\u5220\u6389\uff0c\u5982\u679c\u4ec5\u60f3\u5220\u9664replicationcontroller\uff0c\u4ecd\u60f3\u4fdd\u7559pod\uff0c\u53ef\u4ee5\u4f7f\u7528\u2013cascade=orphan\uff0c\u6b64\u65f6\u7684pod\u5c31\u5904\u4e8e\u672a\u6258\u7ba1\u72b6\u6001\uff1b<\/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=\"\">[root@master ~]# kubectl delete rc rc-nginx\t\t\t\t\t\t#replicationcontroller\u548cpod\u4f1a\u88ab\u4e00\u8d77\u5220\u9664\n[root@master ~]# kubectl delete rc rc-nginx\t--cascade=orphan\t#\u4ec5\u5220\u9664replicationcontroller\uff0cpod\u4fdd\u7559\n<\/pre>\n\n\n\n<p><br>\u4ee5\u4e0a\u5c31\u662freplicationcontroller\uff0c\u6ce8\u610f\uff1areplicationcontroller\u5df2\u7ecf\u88ab\u6dd8\u6c70\uff0c\u6240\u4ee5\u4f60\u5728\u521b\u5efapod\u63a7\u5236\u5668\u65f6\u4e0d\u5e94\u8be5\u9009\u62e9\u521b\u5efareplicationcontroller\u4e86\uff0c\u4e0b\u9762\u6765\u4ecb\u7ecdReplicaSet\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>ReplicaSet\u4ecb\u7ecd\uff08\u4e00\u822c\u4e0d\u4f1a\u76f4\u63a5\u7528\u5230replicaset,\u4e00\u822c\u662fdeployment\u521b\u5efareplicaset\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>ReplicaSet\u662fReplication Controller\u7684\u4e0b\u4e00\u4ee3\u526f\u672c\u63a7\u5236\u5668\uff0c\u76ee\u524d\u4e24\u8005\u53ea\u5728\u6807\u7b7e\u9009\u62e9\u5668\u652f\u6301\u7684\u67e5\u627e\u65b9\u5f0f\u6709\u533a\u522b\uff0c\u5728\u65b0\u7248\u672c\u7684 Kubernetes \u4e2d\u4f7f\u7528 ReplicaSet\uff08\u7b80\u79f0\u4e3aRS \uff09\u6765\u53d6\u4ee3 ReplicationController\u3002ReplicaSet \u8ddf ReplicationController \u6ca1\u6709\u672c\u8d28\u7684\u4e0d\u540c\uff0c\u8bed\u6cd5\u5b9a\u4e49\u90fd\u4e00\u6837\uff0c\u4f46\u662f replicaset \u652f\u6301\u6807\u7b7e\u9009\u62e9\u5668\u7b49\u5f0f\u67e5\u627e\u4e0e\u96c6\u5408\u67e5\u627e\u4e24\u79cd\u65b9\u5f0f\u3002\u6bd4\u5982rs\u5141\u8bb8\u5339\u914d\u7f3a\u5c11\u67d0\u4e2a\u6807\u7b7e\u7684pod\uff0c\u6216\u5305\u542b\u7279\u5b9a\u6807\u7b7e\u540d\u7684pod\u800c\u4e0d\u7ba1\u5176\u6807\u7b7e\u503c\u5982\u4f55\uff0cReplicationController\u5c31\u65e0\u6cd5\u505a\u5230\u8fd9\u4e9b\uff0crc\u8fdb\u652f\u6301\u7b49\u503c\u5339\u914d\u7684\u6807\u7b7e\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=\"\">[root@master ~]# cat  rs_nginx.yaml \napiVersion: apps\/v1\nkind: ReplicaSet\nmetadata: \n  name: rs-nginx\n  namespace: default\nspec:\n  replicas: 3\n  selector:\n    matchLabels:\n      app: nginx-rs\n    matchExpressions:\n      - {key: env, operator: In, values: [dev]}\n  template:\n     metadata:\n       labels:\n         app: nginx-rs\n         env: dev\n     spec:\n         containers:\n         - image: nginx:1.7.9\n           name: nginx-container\n           ports:\n           - containerPort: 80\n<\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u53ea\u5bf9ReplicaSet\u505a\u4e86\u7b80\u5355\u4ecb\u7ecd\uff0c\u5b9e\u9645\u4e0akubernetes\u5b98\u65b9\u63a8\u8350\u4e0d\u8981\u76f4\u63a5\u4f7f\u7528ReplicaSet\uff0c\u7528Deployments\u53d6\u800c\u4ee3\u4e4b\uff0cDeployments\u662f\u6bd4ReplicaSet\u66f4\u9ad8\u7ea7\u7684\u6982\u5ff5\uff0c\u5b83\u4f1a\u7ba1\u7406ReplicaSet\u5e76\u63d0\u4f9b\u5f88\u591a\u5176\u5b83\u6709\u7528\u7684\u7279\u6027\uff0c\u6700\u91cd\u8981\u7684\u662fDeployments\u652f\u6301\u58f0\u660e\u5f0f\u66f4\u65b0\uff0c\u58f0\u660e\u5f0f\u66f4\u597d\u76f8\u6bd4\u4e8e\u547d\u4ee4\u5f0f\u66f4\u65b0\u7684\u597d\u5904\u662f\u4e0d\u4f1a\u4e22\u5931\u5386\u53f2\u53d8\u66f4\u3002\u603b\u7ed3\u8d77\u6765\u5c31\u662f\uff1a\u4e0d\u8981\u518d\u76f4\u63a5\u4f7f\u7528ReplicaSet\u3002<\/p>\n\n\n\n<p><strong>\u5220\u9664ReplicaSet<\/strong><\/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=\"\">[root@master ~]# kubectl delete rs rs-nginx-http --cascade=orphan\t\t#\u5220\u9664rs\uff0c\u4fdd\u7559pod\n[root@master ~]# kubectl delete rs rs-nginx-http\t\t\t\t\t\t#\u5220\u9664rs\u6240\u6709\uff0c\u542bpod\n<\/pre>\n\n\n\n<p><br>\u3000<\/p>\n\n\n\n<p><strong>DaemonSet\u4ecb\u7ecd\uff08DaemonSet\u7528\u4e8e\u786e\u4fdd\u6bcf\u4e2a\u8282\u70b9\u90fd\u8fd0\u884c\u4e00\u4e2apod\u7684\u573a\u666f\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>DaemonSet \u786e\u4fdd\u5168\u90e8\uff08\u6216\u8005\u4e00\u4e9b\uff09Node \u4e0a\u8fd0\u884c\u4e00\u4e2a Pod \u7684\u526f\u672c\u3002\u5f53\u6709 Node\u52a0\u5165\u96c6\u7fa4\u65f6\uff0c\u4e5f\u4f1a\u4e3a\u4ed6\u4eec\u65b0\u589e\u4e00\u4e2a Pod \u3002\u5f53\u6709 Node \u4ece\u96c6\u7fa4\u79fb\u9664\u65f6\uff0c\u8fd9\u4e9b Pod\u4e5f\u4f1a\u88ab\u56de\u6536\u3002\u5220\u9664 DaemonSet\u5c06\u4f1a\u5220\u9664\u5b83\u521b\u5efa\u7684\u6240\u6709 Pod\u3002DaemonSet \u7b80\u5199\u4e3ads\u3002<br>\u4f7f\u7528 DaemonSet \u7684\u4e00\u4e9b\u5178\u578b\u7528\u6cd5\uff1a<br>\u8fd0\u884c\u96c6\u7fa4\u5b58\u50a8 daemon\uff0c\u4f8b\u5982\u5728\u6bcf\u4e2a Node \u4e0a\u8fd0\u884c glusterd \u3001 ceph<br>\u5728\u6bcf\u4e2a Node \u4e0a\u8fd0\u884c\u65e5\u5fd7\u6536\u96c6 daemon\uff0c\u4f8b\u5982 fluentd \u3001 logstash<br>\u5728\u6bcf\u4e2a Node \u4e0a\u8fd0\u884c\u76d1\u63a7 daemon\uff0c\u4f8b\u5982 Prometheus Node Exporter\u3001 collectd \u3001Datadog \u4ee3\u7406\u3001New Relic \u4ee3\u7406\uff0c\u6216 Ganglia gmond<\/p>\n\n\n\n<p><strong>\u7f16\u5199\u4e00\u4e2aDaemonSet<\/strong><\/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=\"\">[root@master ~]#  vim ds.yaml \napiVersion: apps\/v1\nkind: DaemonSet\nmetadata: \n  name: nginx-ds\n  namespace: default\nspec:\n  selector:\n    matchLabels:\n      app: nginx \n      release: stable\n  template:\n    metadata:\n      labels:\n        app: nginx \n        release: stable\n    spec:\n      containers:\n      - name: nginx \n        image: nginx:1.14\n        imagePullPolicy: IfNotPresent\n        ports:\n        - name: http\n          containerPort: 80\n    \n[root@master ~]# kubectl apply -f ds.yaml \t\t\t\t\t\t#\u5e94\u7528yaml\u6587\u4ef6\u521b\u5efa\u8d44\u6e90\n[root@master ~]# kubectl  get pod -o wide\t\t\t\t\t\t#\u67e5\u770bpod\uff0c\u53d1\u73b0\u5df2\u7ecf\u67092\u4e2apod\uff0c\u5206\u522b\u4f4d\u4e8e\u5404\u4e2a\u8282\u70b9\u4e0a\nNAME                  READY   STATUS    RESTARTS   AGE     IP            NODE    NOMINATED NODE   READINESS GATES\nnginx-ds-5qnxs        1\/1     Running   0          4m10s   10.244.2.22   node2   &lt;none>           &lt;none>\nnginx-ds-l7kjk        1\/1     Running   0          4m10s   10.244.1.40   node1   &lt;none>           &lt;none>\n<\/pre>\n\n\n\n<p>\u518d\u6b21\u8bf4\u660e\uff1aDaemonSet\u521b\u5efa\u7684pod\u53ea\u4f1a\u5728\u6bcf\u4e2a\u8282\u70b9\u8fd0\u884c1\u4e2a\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u4e0d\u7528\u5728\u521b\u5efaDaemonSet\u7684yaml\u6587\u4ef6\u4e2d\u6307\u5b9a\u526f\u672c\u6570\uff0c\u6ca1\u5fc5\u8981\uff1b\u5f53\u6bcf\u4e2a\u8282\u70b9\u7684DaemonSet\u7ba1\u7406\u7684pod\u88ab\u5220\u9664\u6216\u8005pod\u5f02\u5e38\u9000\u51fa\u65f6\uff0cDaemonSet\u63a7\u5236\u5668\u53c8\u4f1a\u91cd\u65b0\u521b\u5efa\u4e00\u4e2apod\uff0c\u56e0\u4e3aDaemonSet\u4f1a\u5b9e\u65f6\u76d1\u7ba1\u6bcf\u4e2a\u8282\u70b9\u786e\u4fdd\u5b58\u5728\u4e00\u4e2apod\u8fd0\u884c\u3002<\/p>\n\n\n\n<p><strong>\u67e5\u770bdaemonset<\/strong><\/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=\"\">[root@master ~]# kubectl  get daemonset -n default\t\t\t\t#\u67e5\u770b\u96c6\u7fa4\u7684DaemonSet\nNAME       DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE\nnginx-ds   2         2         2       2            2           &lt;none>          14m\n<\/pre>\n\n\n\n<p><br><strong>\u5220\u9664daemonset<\/strong><\/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=\"\">[root@master ~]# kubectl delete pod nginx-ds-5qnxs\t\t\t\t#\u5220\u9664\u67d0\u4e2a\u8282\u70b9\u4e0a\u7684pod\uff0cds\u53c8\u4f1a\u91cd\u65b0\u521b\u5efa\u4e00\u4e2apod\npod \"nginx-ds-5qnxs\" deleted\n[root@master ~]# kubectl  delete daemonset nginx-ds\t\t\t\t#\u5220\u9664ds\uff0c\u5176\u521b\u5efa\u7684pod\u90fd\u88ab\u5220\u9664\ndaemonset.apps \"nginx-ds\" deleted\n[root@master ~]#\n<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>Job\u4ecb\u7ecd\uff08\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\uff0c\u7c7b\u4f3c\u4e8ecentos\u7684at\u547d\u4ee4\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u6709\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u4e00\u79cd\u8fd9\u6837\u7684pod\u63a7\u5236\u5668\uff0c\u5373\u8be5\u63a7\u5236\u5668\u80fd\u5b9e\u73b0pod\u6267\u884c\u5b8c\u4efb\u52a1\u5c31\u7ed3\u675f\uff0c\u4e0d\u9700\u8981\u91cd\u542f\u6216\u91cd\u5efapod\uff0c\u76f8\u5f53\u4e8e\u4e00\u6b21\u6027\u4efb\u52a1\u3002\u8fd9\u5c31\u53ef\u4ee5\u4f7f\u7528job\u63a7\u5236\u5668\u3002\uff08\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a\uff0cJob\u76f8\u5f53\u4e8eLinux\u4e2d\u7684at\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\uff09<\/p>\n\n\n\n<p><strong>\u521b\u5efajob<\/strong><\/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=\"\">[root@master ~]# cat Job.yaml \t\t\t\t\t\t\t\t#\u7f16\u5199\u4e00\u4e2ajob\u8d44\u6e90\uff0c\u4efb\u52a1\u4e3a\u7761\u7720120s\napiVersion: batch\/v1\t\t\t\t\t\t\t\t\t\t#job\u5c5e\u4e8ebatch API\u7ec4\uff0c\u7248\u672c\u4e3av1\nkind: Job\t\t\t\t\t\t\t\t\t\t\t\t\t#\u8d44\u6e90\u7c7b\u578b\nmetadata: \t\t\t\t\t\t\t\n  name: busybox-job\t\t\t\t\t\t\t\t\t\t\t#job\u7684\u540d\u79f0\u53ebbusybox-job\t\n  namespace: default\t\t\t\t\t\t\t\t\t\t#\u547d\u540d\u7a7a\u95f4\nspec:\n  template:\t\t\t\t\t\t\t\t\t\t\t\t\t#pod\u6a21\u677f\n    metadata:\n      labels:\t\t\t\t\t\t\t\t\t\t\t\t#pod\u6807\u7b7e\n        app: busybox\n        env: dev\n    spec:\n      restartPolicy: OnFailure\t\t\t\t\t\t\t\t#pod\u91cd\u542f\u7b56\u7565\uff0c\u9ed8\u8ba4\u4e3aAlways\uff0c\u4f46\u4e00\u5b9a\u4e0d\u80fd\u662fAlways\uff0c\u56e0\u4e3ajob\u7684\u7b56\u7565\u5c31\u53ea\u662f\u4e00\u6b21\u6027\u6267\u884c\uff0c\u6267\u884c\u5b8c\u4e0d\u9700\u8981\u91cd\u542f\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3aOnFailure\u6216Never\n      containers:\n      - name: busybox\n        image: busybox:latest\n        imagePullPolicy: IfNotPresent\t\t\t\t\t\t#\u955c\u50cf\u62c9\u53d6\u7b56\u7565\uff0c\u9ed8\u8ba4\u5c31\u662fIfNotPresent\uff0c\u4e0d\u5b58\u5728\u624d\u62c9\u53d6\n        command: [\"\/bin\/sh\",\"-c\",\"sleep 120s\"]\t\t\t\t#\u5bb9\u5668\u7684\u4efb\u52a1\u4e3a\u7761\u7720120s\n[root@master ~]# \n[root@master ~]# kubectl  create -f Job.yaml \t\t\t\t\t#\u521b\u5efajob\njob.batch\/busybox-job created\n<\/pre>\n\n\n\n<p><strong>\u67e5\u770bjob<\/strong><\/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=\"\">[root@master ~]# kubectl get pod,job\t\t\t\t\t\t\t#\u67e5\u770bjob\u548cpod\nNAME                       READY   STATUS    RESTARTS   AGE\npod\/busybox-job--1-2q87r   1\/1     Running   0          6s\n\nNAME                    COMPLETIONS   DURATION   AGE\njob.batch\/busybox-job   0\/1           6s         6s\n\n#\u7b49\u5f85120s\u540e\u518d\u6b21\u67e5\u770bpod\uff0c\u53d1\u73b0pod\u72b6\u6001\u53d8\u6210Completed\uff0c\u8868\u793apod\u5df2\u7ecf\u6267\u884c\u5b8c\u6210\u4e86\n[root@master ~]# kubectl get pod\t\t\t\t\t\t\t\t#pod\u72b6\u6001\u53d8\u6210Completed\nNAME                   READY   STATUS      RESTARTS   AGE\nbusybox-job--1-2q87r   0\/1     Completed   0          3m29s\n<\/pre>\n\n\n\n<p>job\u8fd8\u53ef\u4ee5\u8bbe\u8ba1\u4e3a\u8fd0\u884c\u591a\u4e2apod\u5b9e\u4f8b\uff0c\u6362\u53e5\u8bdd\u6765\u8bf4\u5c31\u662f\u521b\u5efa\u4e00\u4e2ajob\uff0c\u987a\u5e8f\u6216\u8005\u5e76\u884c\u7684\u8fd0\u884c\u591a\u4e2apod\uff0c\u5982\u4e0b\u6f14\u793a\uff1a<\/p>\n\n\n\n<p><strong>\u987a\u5e8f\u8fd0\u884c Job pod<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u9700\u8981\u4e00\u4e2ajob\u987a\u5e8f\u8fd0\u884c\u591a\u6b21\uff0c\u90a3\u4e48\u53ef\u4ee5\u6307\u5b9acompletions\u53c2\u6570\u6765\u8bbe\u7f6e\u5e0c\u671bjob\u7684pod\u8fd0\u884c\u591a\u5c11\u6b21\uff0c\u6240\u4e0b\u4ee3\u7801\u6240\u793a\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=\"\">[root@master ~]# cat Job.yaml \napiVersion: batch\/v1\nkind: Job\nmetadata: \n  name: busybox-job\n  namespace: default\nspec:\n  completions: 3\t\t\t\t\t\t\t\t\t\t\t\t#\u8868\u793a\u8fd0\u884c3\u6b21\n  template:\n    metadata:\n      labels:\n        app: busybox\n        env: dev\n    spec:\n      restartPolicy: OnFailure\n      containers:\n      - name: busybox\n        image: busybox:latest\n        imagePullPolicy: IfNotPresent\n        command: [\"\/bin\/sh\",\"-c\",\"sleep 20s\"]\n[root@master ~]# \n[root@master ~]# kubectl get pod\t\t\t\t\t\t\t\t#\u67e5\u770bpod\uff0c\u662f\u7b2c\u4e00\u4e2a\u8fd0\u884c\u5b8c\u6210\u4e4b\u540e\u624d\u521b\u5efa\u7b2c2\u4e2a\uff0c\u4f9d\u6b21\u8fd0\u884c\nNAME                   READY   STATUS      RESTARTS   AGE\nbusybox-job--1-9f7bs   0\/1     Completed   0          4m39s\nbusybox-job--1-mdqkb   0\/1     Completed   0          4m18s\nbusybox-job--1-s98wc   0\/1     Completed   0          5m\n<\/pre>\n\n\n\n<p><strong>\u5e76\u884c\u8fd0\u884c Job pod<\/strong><\/p>\n\n\n\n<p>\u4e0d\u5fc5\u4e00\u4e2a\u63a5\u7740\u4e00\u4e2a\u8fd0\u884c\u5355\u4e2aJob pod\uff0c\u4e5f\u53ef\u4ee5\u8ba9Job \u5e76\u884c\u8fd0\u884c\u591a\u4e2apod\uff0c\u53ef\u4ee5\u901a\u8fc7parallelism Job\u914d\u7f6e\u5c5e\u6027\uff0c\u6307\u5b9a\u5141\u8bb8\u591a\u4e2apod\u5e76\u884c\u6267\u884c\uff0c\u5982\u4e0b\u4ee3\u7801\u6240\u793a\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=\"\">[root@master ~]# vim  Job.yaml \napiVersion: batch\/v1\nkind: Job\nmetadata:\n  name: busybox-job\n  namespace: default\nspec:\n  completions: 4\n  parallelism: 2\t\t\t\t\t\t\t\t\t\t\t\t\t#\u6307\u5b9a\u53ef\u4ee5\u5e76\u884c\u8fd0\u884c\u591a\u5c11\u4e2apod\n  template:\n    metadata:\n      labels:\n        app: busybox\n        env: dev\n    spec:\n      restartPolicy: OnFailure\n      containers:\n      - name: busybox\n        image: busybox:latest\n        imagePullPolicy: IfNotPresent\n        command: [\"\/bin\/sh\",\"-c\",\"sleep 20s\"]\n[root@master ~]# kubectl  apply  -f Job.yaml &amp;&amp; kubectl get pod\t\t#\u67e5\u770bjob\u548cpod\uff0c\u53d1\u73b0\u5df2\u7ecf\u5728\u5e76\u884c\u8fd0\u884c2\u4e2apod\u4e86\njob.batch\/busybox-job created\nNAME                   READY   STATUS              RESTARTS   AGE\nbusybox-job--1-c8jb5   0\/1     ContainerCreating   0          0s\nbusybox-job--1-lsrbv   0\/1     ContainerCreating   0          0s\n<\/pre>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5982\u679crestartPolicy:\u8bbe\u4e3aOnFailure\uff0c\u5c31\u8868\u793apod\u51fa\u73b0\u5f02\u5e38\u65f6\u53ef\u4ee5\u91cd\u65b0\u521b\u5efapod\uff0c\u8fd9\u5c31\u610f\u5473\u7740completions\u5b9a\u4e49\u4e3an\u6b21\uff0c\u4f46\u5b9e\u9645job\u521b\u5efa\u7684pod\u53ef\u80fd\u4f1a\u5927\u4e8en\u3002<\/p>\n\n\n\n<p><strong>\u9650\u5236Job pod\u5b8c\u6210\u4efb\u52a1\u7684\u65f6\u95f4<\/strong><\/p>\n\n\n\n<p>\u901a\u8fc7pod\u914d\u7f6e\u4e2d\u8bbe\u7f6eactiveDeadlineSeconds\u5c5e\u6027\uff0c\u53ef\u4ee5\u9650\u5236pod\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u5982\u679cpod\u8fd0\u884c\u65f6\u95f4\u8d85\u8fc7\u6b21\u65f6\u95f4\uff0c\u7cfb\u7edf\u5c06\u5c1d\u8bd5\u7ec8\u6b62pod\uff0c\u5e76\u5c06job\u6807\u8bb0\u4e3a\u5931\u8d25\u3002<br>\u901a\u8fc7\u6307\u5b9aJob\u8d44\u6e90\u6e05\u5355\u4e2d\u7684spec.backoffLimit\u5b57\u6bb5\uff0c\u53ef\u4ee5\u914d\u7f6eJob\u5728\u88ab\u6807\u8bb0\u4e3a\u5931\u8d25\u4e4b\u524d\u53ef\u4ee5\u91cd\u8bd5\u7684\u91cd\u8bd5\uff0c\u5982\u679c\u4e3a\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a6\u6b21\u3002<\/p>\n\n\n\n<p><strong>\u5220\u9664Job<\/strong><\/p>\n\n\n\n<p>\u9ed8\u8ba4\u6267\u884c\u5b8c\u6bd5\u7684Job \u7684pod\u4e3aCompleted \u72b6\u6001\uff0ck8s\u5e76\u4e0d\u4f1a\u5220\u9664pod\uff0c\u662f\u4e3a\u4e86\u53ef\u4ee5\u8ba9\u4f60\u67e5\u770b\u65e5\u5fd7\uff0c\u5982\u679c\u9700\u8981\u5220\u9664Job\uff0c\u76f4\u63a5kubectl delete job Job_name\u5373\u53ef\uff0c\u5982\u4e0b\u6240\u793a\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=\"\">[root@master ~]# kubectl  delete job busybox-job \t\t\t#\u5220\u9664job\uff0c\u5176pod\u4e5f\u4f1a\u88ab\u5220\u9664\njob.batch \"busybox-job\" deleted\n<\/pre>\n\n\n\n<p><br>\u3000<\/p>\n\n\n\n<p><strong>CronJob\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u5982\u679c\u8bf4Job\u76f8\u5f53\u4e8eLinux\u4e2d\u7684at\u4e00\u6b21\u6027\u6fc0\u6d3b\u4efb\u52a1\uff0c\u90a3\u4e48CronJob\u5c31\u76f8\u5f53\u4e8eLinux\u4e2d\u7684Crontab\u5468\u671f\u6027\u5b9a\u65f6\u4efb\u52a1\u3002Job\u4e0eCronJob\u7684\u533a\u522b\u5728\u4e8e\uff0cJob\u5728\u521b\u5efa\u65f6\u5c31\u8fd0\u884c\uff0c\u800cCronJob\u5728\u521b\u5efa\u540e\u4f1a\u5b9a\u65f6\u7684\u8fd0\u884c\uff0c\u5728k8s\u96c6\u7fa4\u4e2d\u7684cron\u4efb\u52a1\u5c31\u662f\u901a\u8fc7CronJob\u8d44\u6e90\u8fdb\u884c\u5b9e\u73b0\u7684\u3002<br>\u5728\u914d\u7f6e\u7684\u65f6\u95f4\u91cc\uff0ck8s\u5c06\u6839\u636e\u5728CronJob\u5bf9\u8c61\u4e2d\u914d\u7f6e\u7684Job\u6a21\u677f\u521b\u5efaJob\u8d44\u6e90\u3002<br>cron\u8868\u8fbe\u5f0f\u683c\u5f0f\u4e0eLinux\u4e2dcron\u7684\u8868\u8fbe\u5f0f\u4e00\u6837\uff0c\u683c\u5f0f\u4e3a\uff1a\u5206 \u65f6 \u65e5 \u6708 \u5468<\/p>\n\n\n\n<p><strong>\u521b\u5efa\u4e00\u4e2aCronJob<\/strong><\/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=\"\">[root@master ~]# vim CronJob.yaml \napiVersion: batch\/v1\nkind: CronJob\t\t\t\t\t\t\t\t\t\t#\u521b\u5efaCronJob\nmetadata: \n  name: busyboy\n  namespace: default\nspec:\n  schedule: \"*\/5 * * * *\"\t\t\t\t\t\t\t#schedule\u5b57\u6bb5\u6307\u5b9a\u5b9a\u65f6\u4efb\u52a1\uff1a\u5206\u65f6\u65e5\u6708\u5468\n  startingDeadlineSeconds: 15\t\t\t\t\t\t#\u8868\u793a\u6700\u8fdf\u5728\u9884\u5b9a\u65f6\u95f4\u540e15\u79d2\u542f\u52a8pod\n  jobTemplate:\t\t\t\t\t\t\t\t\t\t#\u4efb\u52a1\u6a21\u677f\uff0c\u7528\u6765\u6307\u5b9a\u9700\u8981\u8fd0\u884c\u7684\u4efb\u52a1\n    spec:\n      template:\n        metadata:\n         labels:\n           app: CronJob\n           env: dev\n        spec:\n          restartPolicy: OnFailure\n          containers:\n             - name: busybox\n               image: busybox:latest\n               imagePullPolicy: IfNotPresent\n               command: [\"\/bin\/sh\",\"-c\",\"sleep 20s\"]\n[root@master ~]#\n<\/pre>\n\n\n\n<p><br><strong>\u67e5\u770bCronJob\u3001\u67e5\u770bpod<\/strong><\/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=\"\">[root@master ~]# kubectl get cronjob\t\t\t\t\t\t\t\t\t#\u67e5\u770bCronJob\nNAME      SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE\nbusyboy   *\/5 * * * *   False     0        4m12s           19m\n[root@master ~]# \n[root@master ~]# kubectl  get pods\t\t\t\t\t\t\t\t\t\t#\u6bcf\u96945\u5206\u949f\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2apod\nNAME                        READY   STATUS      RESTARTS   AGE\nbusyboy-27416295--1-k5t5h   0\/1     Completed   0          5m23s\nbusyboy-27416300--1-qs7mt   0\/1     Completed   0          23s\n<\/pre>\n\n\n\n<p><strong>\u5220\u9664CronJob<\/strong><\/p>\n\n\n\n<p>\u9ed8\u8ba4\u6267\u884c\u5b8c\u6bd5\u7684CronJob\u7684pod\u4e3aCompleted \u72b6\u6001\uff0ck8s\u5e76\u4e0d\u4f1a\u5220\u9664pod\uff0c\u662f\u4e3a\u4e86\u53ef\u4ee5\u8ba9\u4f60\u67e5\u770b\u65e5\u5fd7\uff0c\u5982\u679c\u9700\u8981\u5220\u9664CronJob\uff0c\u76f4\u63a5kubectl delete cronjob cronjob_name\u5373\u53ef\uff0c\u5982\u4e0b\u6240\u793a\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=\"\">[root@master ~]# kubectl  delete cronjob busyboy \t\t\t#\u5220\u9664job\uff0c\u5176pod\u4e5f\u4f1a\u88ab\u5220\u9664\ncronjob.batch \"busyboy\" deleted\n<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa Headless service \u548c \u6b63\u5e38Service\u670d\u52a1\u533a\u522b\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728 Kubernetes \u4e2d\uff0cHeadless \u670d\u52a1\u4e0e\u6b63\u5e38\u7684 ClusterIP \u670d\u52a1\uff08\u4e5f\u5305\u62ec NodePort\u3001LoadBalancer \u7b49\u7c7b\u578b\u7684\u670d\u52a1\uff0c\u5b83\u4eec\u5728\u8d1f\u8f7d\u5747\u8861\u7b49\u65b9\u9762\u903b\u8f91\u7c7b\u4f3c\uff09\u6709\u4e0d\u540c\u7279\u6027\uff0c\u76f4\u63a5\u7528\u6b63\u5e38\u670d\u52a1\u65e0\u6cd5\u6ee1\u8db3\u4e00\u4e9b\u7279\u5b9a\u9700\u6c42\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><strong>1. \u5bf9\u6709\u72b6\u6001\u5e94\u7528\u63d0\u4f9b\u7a33\u5b9a\u552f\u4e00\u6807\u8bc6<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u6b63\u5e38\u670d\u52a1<\/strong>\uff1aClusterIP \u7b49\u6b63\u5e38\u670d\u52a1\u63d0\u4f9b\u7684\u662f\u4e00\u4e2a\u865a\u62df\u7684\u96c6\u7fa4 IP\uff0c\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u5c06\u8bf7\u6c42\u5206\u53d1\u5230\u540e\u7aef\u591a\u4e2a Pod \u4e0a\uff0c\u5b83\u4e0d\u5173\u5fc3\u5177\u4f53\u662f\u54ea\u4e2a Pod \u54cd\u5e94\u8bf7\u6c42\uff0c\u4e5f\u4e0d\u4f1a\u4e3a\u6bcf\u4e2a Pod \u63d0\u4f9b\u72ec\u7acb\u7684\u7f51\u7edc\u6807\u8bc6\u3002\u4f8b\u5982\u5728\u90e8\u7f72\u6570\u636e\u5e93\u4e3b\u4ece\u96c6\u7fa4\uff08\u5982 MySQL \u4e3b\u4ece\u96c6\u7fa4\uff09\u8fd9\u7c7b\u6709\u72b6\u6001\u5e94\u7528\u65f6\uff0c\u6b63\u5e38\u670d\u52a1\u65e0\u6cd5\u6ee1\u8db3\u6bcf\u4e2a\u6570\u636e\u5e93\u5b9e\u4f8b\u9700\u8981\u552f\u4e00\u4e14\u7a33\u5b9a\u8bbf\u95ee\u5730\u5740\u7684\u9700\u6c42\u3002<\/li>\n\n\n\n<li><strong>Headless \u670d\u52a1<\/strong>\uff1a\u80fd\u591f\u4e3a StatefulSet \u7ba1\u7406\u7684\u6709\u72b6\u6001\u5e94\u7528\u7684\u6bcf\u4e2a Pod \u8d4b\u4e88\u56fa\u5b9a\u683c\u5f0f\u7684 DNS \u540d\u79f0\uff0c\u5982<code>&lt;pod-name>.&lt;service-name>.&lt;namespace>.svc.cluster.local<\/code>\u3002\u5728 MySQL \u4e3b\u4ece\u96c6\u7fa4\u573a\u666f\u4e2d\uff0c\u901a\u8fc7 Headless \u670d\u52a1\uff0c\u4e3b\u8282\u70b9\u548c\u4ece\u8282\u70b9\u90fd\u80fd\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u3001\u53ef\u88ab\u5176\u4ed6\u7ec4\u4ef6\u7a33\u5b9a\u8bbf\u95ee\u7684\u5730\u5740\uff0c\u8fd9\u5bf9\u4e3b\u4ece\u590d\u5236\u914d\u7f6e\uff08\u4ece\u8282\u70b9\u9700\u8981\u660e\u786e\u77e5\u9053\u4e3b\u8282\u70b9\u5730\u5740\u8fdb\u884c\u8fde\u63a5\uff09\u4ee5\u53ca\u6570\u636e\u540c\u6b65\u7b49\u64cd\u4f5c\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>2. \u5b9e\u73b0\u76f4\u63a5\u8bbf\u95ee\u7279\u5b9a Pod<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u6b63\u5e38\u670d\u52a1<\/strong>\uff1a\u6b63\u5e38\u670d\u52a1\u9ed8\u8ba4\u4f1a\u5bf9\u8bf7\u6c42\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\uff0c\u5b83\u4f1a\u6839\u636e\u4e00\u5b9a\u7684\u7b56\u7565\uff08\u5982\u8f6e\u8be2\u3001\u968f\u673a\u7b49\uff09\u5c06\u5ba2\u6237\u7aef\u8bf7\u6c42\u968f\u673a\u5206\u53d1\u5230\u540e\u7aef\u7684\u67d0\u4e2a Pod \u4e0a\uff0c\u65e0\u6cd5\u76f4\u63a5\u6307\u5b9a\u8bbf\u95ee\u67d0\u4e2a\u7279\u5b9a\u7684 Pod\u3002\u6bd4\u5982\u5728\u5206\u5e03\u5f0f\u5b58\u50a8\u7cfb\u7edf\u4e2d\uff0c\u5ba2\u6237\u7aef\u53ef\u80fd\u9700\u8981\u76f4\u63a5\u4e0e\u7279\u5b9a\u7684\u5b58\u50a8\u8282\u70b9 Pod \u901a\u4fe1\uff0c\u8fdb\u884c\u6570\u636e\u8bfb\u5199\u6216\u914d\u7f6e\u64cd\u4f5c\uff0c\u6b63\u5e38\u670d\u52a1\u65e0\u6cd5\u5b9e\u73b0\u8fd9\u6837\u7684\u7cbe\u51c6\u8bbf\u95ee\u3002<\/li>\n\n\n\n<li><strong>Headless \u670d\u52a1<\/strong>\uff1a\u4e0d\u4f1a\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\uff0c\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42\u65f6\uff0c\u4f1a\u76f4\u63a5\u89e3\u6790\u5230\u540e\u7aef Pod \u7684 IP \u5730\u5740\uff0c\u4ece\u800c\u76f4\u63a5\u8bbf\u95ee\u5230\u76ee\u6807 Pod\u3002\u8fd9\u4f7f\u5f97\u5e94\u7528\u53ef\u4ee5\u660e\u786e\u5730\u4e0e\u6307\u5b9a\u7684 Pod \u5b9e\u4f8b\u8fdb\u884c\u4ea4\u4e92\uff0c\u6ee1\u8db3\u4e86\u5bf9\u7279\u5b9a Pod \u7cbe\u51c6\u8bbf\u95ee\u7684\u9700\u6c42\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>3. \u81ea\u5b9a\u4e49\u8d1f\u8f7d\u5747\u8861\u903b\u8f91<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u6b63\u5e38\u670d\u52a1<\/strong>\uff1a\u4f7f\u7528\u7684\u662f Kubernetes \u5185\u7f6e\u7684\u8d1f\u8f7d\u5747\u8861\u673a\u5236\uff0c\u5982 kube-proxy \u5b9e\u73b0\u7684\u57fa\u4e8e iptables \u6216 IPVS \u7684\u8d1f\u8f7d\u5747\u8861\uff0c\u7528\u6237\u5f88\u96be\u6839\u636e\u81ea\u8eab\u590d\u6742\u4e1a\u52a1\u903b\u8f91\u5bf9\u5176\u8fdb\u884c\u5b9a\u5236\u4fee\u6539\u3002<\/li>\n\n\n\n<li><strong>Headless \u670d\u52a1<\/strong>\uff1a\u4e0d\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u529f\u80fd\uff0c\u53ea\u662f\u5c06\u540e\u7aef Pod \u7684 IP \u5730\u5740\u76f4\u63a5\u66b4\u9732\u7ed9\u5ba2\u6237\u7aef\u3002\u8fd9\u6837\u5f00\u53d1\u8005\u5c31\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u5c42\u9762\u6839\u636e\u4e1a\u52a1\u9700\u6c42\uff08\u5982\u6839\u636e Pod \u7684\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3001\u4efb\u52a1\u8fdb\u5ea6\u7b49\uff09\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u8d1f\u8f7d\u5747\u8861\u903b\u8f91\uff0c\u51b3\u5b9a\u8bf7\u6c42\u8be5\u53d1\u9001\u5230\u54ea\u4e2a Pod\uff0c\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u7075\u6d3b\u6027\uff0c\u9002\u7528\u4e8e\u5bf9\u8bf7\u6c42\u5206\u53d1\u7b56\u7565\u6709\u7279\u6b8a\u8981\u6c42\u7684\u573a\u666f\uff0c\u5982\u673a\u5668\u5b66\u4e60\u7684\u5206\u5e03\u5f0f\u8bad\u7ec3\u4efb\u52a1\u8c03\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>4. \u670d\u52a1\u53d1\u73b0\u573a\u666f\u4e0b\u83b7\u53d6 Pod \u5217\u8868<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u6b63\u5e38\u670d\u52a1<\/strong>\uff1a\u6b63\u5e38\u670d\u52a1\u7684 DNS \u89e3\u6790\u7ed3\u679c\u662f\u5176\u865a\u62df\u7684\u96c6\u7fa4 IP\uff0c\u5ba2\u6237\u7aef\u53ea\u80fd\u901a\u8fc7\u8fd9\u4e2a IP \u8bbf\u95ee\u670d\u52a1\uff0c\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\u5230\u540e\u7aef\u6240\u6709 Pod \u7684 IP \u5730\u5740\u5217\u8868\u3002\u5bf9\u4e8e\u4e00\u4e9b\u9700\u8981\u77e5\u6653\u6240\u6709\u670d\u52a1\u5b9e\u4f8b\u5730\u5740\u6765\u8fdb\u884c\u540e\u7eed\u64cd\u4f5c\uff08\u5982\u63a8\u9001\u914d\u7f6e\u3001\u8fdb\u884c\u5168\u5c40\u8c03\u5ea6\u7b49\uff09\u7684\u5e94\u7528\u6765\u8bf4\uff0c\u6b63\u5e38\u670d\u52a1\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\u3002<\/li>\n\n\n\n<li><strong>Headless \u670d\u52a1<\/strong>\uff1a\u5ba2\u6237\u7aef\u901a\u8fc7\u67e5\u8be2 Headless \u670d\u52a1\u7684 DNS \u8bb0\u5f55\uff0c\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u5230\u4e0e\u8be5\u670d\u52a1\u5173\u8054\u7684\u6240\u6709 Pod \u7684 IP \u5730\u5740\u5217\u8868\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0c\u914d\u7f6e\u4e2d\u5fc3\u9700\u8981\u5c06\u6700\u65b0\u914d\u7f6e\u7cbe\u51c6\u63a8\u9001\u7ed9\u6240\u6709\u5fae\u670d\u52a1\u5b9e\u4f8b\uff0c\u901a\u8fc7 Headless \u670d\u52a1\uff0c\u914d\u7f6e\u4e2d\u5fc3\u5c31\u80fd\u83b7\u53d6\u5230\u6240\u6709\u5fae\u670d\u52a1 Pod \u7684 IP \u5730\u5740\uff0c\u8fdb\u800c\u5b9e\u73b0\u914d\u7f6e\u7684\u7cbe\u51c6\u63a8\u9001\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f55\u4e3apod\u63a7\u5236\u5668 pod\u63a7\u5236\u5668\uff0c\u662f\u7528\u4e8e\u7ba1\u7406\u3001\u90e8\u7f72pod\u7684\u4e00\u79cdk8s\u4e2d\u91cd\u8981\u7684\u8d44\u6e90\uff0c\u786e\u4fddpod\u8d44\u6e90\u7b26\u5408\u9884\u671f\u7684\u72b6\u6001\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,22],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11599"}],"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=11599"}],"version-history":[{"count":5,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11599\/revisions"}],"predecessor-version":[{"id":18607,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11599\/revisions\/18607"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}