{"id":1205,"date":"2022-04-07T18:24:31","date_gmt":"2022-04-07T10:24:31","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1205"},"modified":"2022-04-25T10:37:46","modified_gmt":"2022-04-25T02:37:46","slug":"2-k8s%e5%b8%b8%e7%94%a8%e7%9a%84%e8%b5%84%e6%ba%90","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1205","title":{"rendered":"2.k8s\u5e38\u7528\u7684\u8d44\u6e90"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.pod\u8d44\u6e90<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fpod<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pod\u662f\u6700\u5c0f\u8d44\u6e90\u5355\u4f4d.\n\u4efb\u4f55\u7684\u4e00\u4e2ak8s\u8d44\u6e90\u90fd\u53ef\u4ee5\u7531yaml\u6e05\u5355\u6587\u4ef6\u6765\u5b9a\u4e49\nk8s yaml\u6587\u4ef6\u7684\u4e3b\u8981\u7ec4\u6210\napiVersion: v1  api\u7248\u672c\nkind: pod   \u8d44\u6e90\u7c7b\u578b\nmetadata:   \u5c5e\u6027\nspec:       \u8be6\u7ec6\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u521b\u5efa\u4e00\u4e2apod\u8d44\u6e90<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>##\u521b\u5efayaml\u76ee\u5f55<\/strong>\n&#91;root@k8s-master ~]# mkdir  k8s_yaml\n&#91;root@k8s-master ~]# cd k8s_yaml\/\n&#91;root@k8s-master ~\/k8s_yaml]# mkdir pod\n&#91;root@k8s-master ~\/k8s_yaml]# cd pod\/\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# pwd\n\/root\/k8s_yaml\/pod\n<strong>###\u7f16\u5199yaml\u6587\u4ef6<\/strong>\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# cat k8s_pod.yaml \napiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx\n  labels:\n    app: web\nspec:\n  containers:\n    - name: nginx\n      image: 10.0.0.11:5000\/nginx:1.13\n      ports:\n        - containerPort: 80\n<strong>####\u8fd9\u91cc\u7528nginx1.13\u662f\u4e3a\u4e86\u540e\u9762\u6f14\u793a\u6eda\u52a8\u5347\u7ea7<\/strong>\n<strong>###\u521b\u5efa\u5e76\u68c0\u67e5pod\u8d44\u6e90<\/strong>\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# kubectl create -f k8s_pod.yaml \npod \"nginx\" created\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# kubectl get pod\nNAME      READY     STATUS              RESTARTS   AGE\nnginx     0\/1       ContainerCreating   0          1m\n<strong>###\u4e0b\u8f7dnginx\u955c\u50cf\u5e76\u4e0a\u4f20\u81f3\u79c1\u6709\u955c\u50cf\u4ed3\u5e93<\/strong>\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# cd\n&#91;root@k8s-master ~]# docker pull nginx:1.13\n&#91;root@k8s-master ~]# docker tag docker.io\/nginx:1.13 10.0.0.11:5000\/nginx:1.13\n&#91;root@k8s-master ~]# docker push 10.0.0.11:5000\/nginx:1.13\n<strong>###\u8fd9\u65f6\u5019\u53d1\u73b0pod\u8d44\u6e90\u7684\u5bb9\u5668\u8fd8\u662f\u6ca1\u6709\u542f\u52a8\n\u5e76\u4e14kubectl get pod -o wide\u67e5\u770b\u88ab\u8c03\u5ea6\u5230\u4e8610.0.0.13\u8fd9\u53f0\u673a\u5668<\/strong>\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"140\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-17.png\" alt=\"\" class=\"wp-image-1206\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-17.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-17-300x49.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-17-768x124.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>###\u67e5\u770b\u4e00\u4e0b\u8d44\u6e90\u7684\u72b6\u6001<\/strong>\uff0c\u662f\u5728\u54ea\u4e00\u6b65\u88ab\u5361\u4e3b\u4e86kubectl describe pod nginx<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"550\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-18.png\" alt=\"\" class=\"wp-image-1207\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-18.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-18-300x191.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-18-768x488.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>####\u67e5\u770b\u4e00\u4e0b\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u5230\u5e95\u5728\u4e0d\u5728<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"235\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-19.png\" alt=\"\" class=\"wp-image-1208\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-19.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-19-300x82.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-19-768x209.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>###\u90a3\u73b0\u5728\u4e0d\u4e0b\u8f7d\u8f6f\u4ef6\u5305\uff0c\u53c8\u9700\u8981\u4e0b\u8f7d\u7ea2\u5e3d\u7684\u90a3\u4e2a\u5bb9\u5668\u600e\u4e48\u529e<\/strong>\n\u5148\u628a\u955c\u50cfpull\u4e0b\u6765\u7136\u540e\u4e0a\u4f20\u5230\u81ea\u5df1\u7684\u79c1\u6709\u4ed3\u5e93\n&#91;root@k8s-master ~]# docker pull tianyebj\/pod-infrastructure\n&#91;root@k8s-master ~]# docker tag  docker.io\/tianyebj\/pod-infrastructure:latest 10.0.0.11:5000\/sunfuyang\/pod-infrastructure:latest\n&#91;root@k8s-master ~]# docker push  10.0.0.11:5000\/sunfuyang\/pod-infrastructure:latest\n<strong>####\u90a3\u4e3a\u4ec0\u4e48\u8c37\u6b4c\u7684k8s\u4f1a\u53bbredhat\u4e0b\u8f7d\u955c\u50cf\u5462<\/strong><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"842\" height=\"307\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-20.png\" alt=\"\" class=\"wp-image-1209\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-20.png 842w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-20-300x109.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-20-768x280.png 768w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6240\u4ee5\u9700\u8981\u4fee\u6539\u8fd9\u91cc\u7684\u914d\u7f6e\u6587\u4ef6\u5c06\u7ea2\u5e3d\u7684\u7f51\u5740\u66ff\u6362\u4e3a\u79c1\u6709\u4ed3\u5e93\u7684\u5730\u5740\uff0c\u7136\u540e\u91cd\u542fk8s\n&#91;root@k8s-node02 ~]# systemctl restart kubelet.service\n##\u518d\u6b21\u56de\u5230master\u67e5\u770b\uff0c\u53d1\u73b0\u5df2\u7ecf\u8fd0\u884c\u8d77\u6765\u4e86\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"78\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-21.png\" alt=\"\" class=\"wp-image-1210\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-21.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-21-300x27.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-21-768x69.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>###\u67e5\u770bnode\u8282\u70b9\u7684docker\u955c\u50cf\u548c\u5bb9\u5668\uff0c\u53d1\u73b0\u591a\u4e86\u4e24\u4e2a\u955c\u50cf\u548c\u4e24\u4e2a\u5bb9\u5668<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"167\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-22.png\" alt=\"\" class=\"wp-image-1211\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-22.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-22-300x58.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-22-768x148.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>3.pod\u8d44\u6e90\u662f\u4ec0\u4e48<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>###\u4e3a\u4ec0\u4e48pod\u521b\u5efa\u7684nginx\u5bb9\u5668\u6ca1\u6709ip<\/strong>\n\u6211\u4eec\u80fd\u901a\u8fc7172.18.28.2ping\u901anginx\u5bb9\u5668\uff0c\u4f46\u662fnginx\u5bb9\u5668\u7684ip\u5730\u5740\u786e\u662f\u7a7a\u7684<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"85\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-23.png\" alt=\"\" class=\"wp-image-1212\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-23.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-23-300x29.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-23-768x75.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u90a3\u4e3a\u4ec0\u4e48\u8fd8\u80fd\u8bbf\u95ee\u5230nginx\u5bb9\u5668\u5462\uff1f\u662f\u56e0\u4e3a\u4f7f\u7528\u7684\u662fdocker\u56db\u79cd\u7f51\u7edc\u7c7b\u578b\u4e2d\u7684container\u7f51\u7edc\u7c7b\u578b\nPod\u5bb9\u5668\u4e0d\u5360\u7528\u7aef\u53e3\uff0c\u6240\u4ee5\u8bbf\u95ee\u4efb\u4f55\u7aef\u53e3\u90fd\u4e0d\u4f1a\u548cnginx\u5bb9\u5668\u51b2\u7a81\n\u6bcf\u8dd1\u4e00\u4e2apod\u8d44\u6e90\uff0c\u90fd\u4f1a\u8d77\u4e00\u4e2apod\u5bb9\u5668\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"58\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-24.png\" alt=\"\" class=\"wp-image-1213\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-24.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-24-300x20.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-24-768x51.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u90a3\u4e3a\u4ec0\u4e48\u8981\u8d77\u4e00\u4e2apod\u5bb9\u5668\u5462<\/strong>\n\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a\u81ea\u52a8\u53d1\u73b0\u5bb9\u5668\uff0cpod\u5bb9\u5668\u76f8\u5f53\u4e8ek8s\u5ba2\u6237\u7aef\uff0c\u4f1a\u5411\u670d\u52a1\u7aef\u901a\u77e5\uff0c\u65b0\u52a0\u4e86\u4e00\u4e2a\u5bb9\u5668\u3002\u4e5f\u662f\u4e3a\u4e86\u5b9e\u73b0k8s\u7684\u9ad8\u7ea7\u529f\u80fd\u3002\nPod\u5bb9\u5668\u5360\u7528\u8d44\u6e90\u975e\u5e38\u5c11\u8fd8\u4e0d\u52301M\n\u6240\u4ee5\u6bcf\u521b\u5efa\u4e00\u4e2apod\u8d44\u6e90\u90fd\u81f3\u5c11\u8d77\u4e24\u4e2a\u5bb9\u5668<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"64\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-25.png\" alt=\"\" class=\"wp-image-1214\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-25.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-25-300x22.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-25-768x57.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Pod\u521b\u5efa\u4e24\u4e2a\u5bb9\u5668<\/strong>\npod\u8d44\u6e90:\u81f3\u5c11\u7531\u4e24\u4e2a\u5bb9\u5668\u7ec4\u6210,pod\u57fa\u7840\u5bb9\u5668\u548c\u4e1a\u52a1\u5bb9\u5668\u7ec4\u6210(\u6700\u591a1+4)\npod\u914d\u7f6e\u6587\u4ef62\uff1a\n&#91;root@k8s-master ~\/k8s_yaml\/pod]# cat k8s_pod2.yaml \napiVersion: v1\nkind: Pod\nmetadata:\n  name: test\n  labels:\n    app: web\nspec:\n  containers:\n    - name: nginx\n      image: 10.0.0.11:5000\/nginx:1.13\n      ports:\n        - containerPort: 80\n    - name: alpine\n      image: 10.0.0.11:5000\/alpine:latest\n      command: &#91;\"sleep\",\"1000\"]\n####\u6ce8\u610f\uff0c\u4ed6\u4eec\u662f\u516c\u7528\u7f51\u7edc\u7684\u3002\u8981\u907f\u514d\u4e24\u4e2a\u5bb9\u5668\u95f4\u7684\u901a\u8baf\u662f\u672c\u5730\u5730\u5740127\n<strong>\u5982\u4f55\u8fdb\u5165\u5230\u8fdb\u5165pod\u5bb9\u5668<\/strong>\nkubectl exec -it pod_name \/bin\/bash###\u8fd8\u53ef\u4ee5\u52a0-c\u53c2\u6570\u6307\u5b9a\u8fdb\u5165\u90a3\u4e2a\u5bb9\u5668\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.ReplicationController\u8d44\u6e90\uff08\u65b0\u7248\u672c\u5df2\u88ab\u5f03\u7528\uff09<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662frc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rc:\u4fdd\u8bc1\u6307\u5b9a\u6570\u91cf\u7684pod\u59cb\u7ec8\u5b58\u6d3b,rc\u901a\u8fc7\u6807\u7b7e\u9009\u62e9\u5668\u6765\u5173\u8054pod<\/code><\/pre>\n\n\n\n<p><strong><em>2.k8s\u8d44\u6e90\u7684\u5e38\u89c1\u64cd\u4f5c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create -f xxx.yaml\nkubectl get pod|rc\nkubectl describe pod nginx\nkubectl delete pod nginx \u6216\u8005kubectl delete -f xxx.yaml\nkubectl edit pod nginx\nkubectl apply -f xxx.yaml<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u521b\u5efa\u4e00\u4e2arc<\/em><\/strong><\/p>\n\n\n\n<p>\u521b\u5efak8s_rc1.yaml\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&#91;root@k8s-master ~]# mkdir -p  k8s_yaml\/rc\n&#91;root@k8s-master ~]# cd k8s_yaml\/rc\n&#91;root@k8s-master ~\/k8s_yaml\/rc]# cat k8s_rc1.yaml \napiVersion: v1\nkind: ReplicationController\nmetadata:\n  name: nginx###\u76f8\u540c\u7c7b\u578b\u8d44\u6e90\u540d\u5b57\u4e0d\u80fd\u76f8\u540c\nspec:\n  replicas: 5##\u526f\u672c\u6570\n  selector:##\u6807\u7b7e\u9009\u62e9\u5668\n    app: myweb\n  template:\n    metadata:\n      labels:\n        app: myweb\n    spec:\n      containers:\n      - name: myweb\n        image: 10.0.0.11:5000\/nginx:1.13\n        ports:\n        - containerPort: 80\n&#91;root@k8s-master ~\/k8s_yaml\/rc]# kubectl create -f k8s_rc1.yaml\n<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u4e00\u4e0b\u521b\u5efa\u7684\u7ed3\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"199\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-26.png\" alt=\"\" class=\"wp-image-1223\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-26.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-26-300x69.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-26-768x177.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u7b2c\u4e00\u5217\u540d\u5b57\uff0c\u7b2c\u4e8c\u5217\u671f\u671b\u6570\uff0c\u5c31\u662f\u914d\u7f6e\u6587\u4ef6\u91ccreplicas\u7684\u6570\u91cf\uff0c\u7b2c\u4e09\u5217\u662f\u5df2\u521b\u5efa\u7684\u6570\uff0c\u7b2c\u56db\u5217\u662f\u5df2\u8fd0\u884c\u6570\u3002\n\u53ef\u4ee5\u770b\u5230pod\u8d44\u6e90\u88ab\u5747\u5300\u7684\u5206\u914d\u5230\u4e0d\u540c\u7684\u8282\u70b9\uff0c\u5e76\u4e14pod\u8d44\u6e90\u540d\u5b57\u4e5f\u662f\u968f\u673a\u7684\n<\/code><\/pre>\n\n\n\n<p>Rc\u5bf9\u5bb9\u5668\u7684\u6545\u969c\u6062\u590d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5220\u9664\u4e00\u4e2apod\u8d44\u6e90\u4f1a\u600e\u4e48\u6837\n&#91;root@k8s-master ~\/k8s_yaml\/rc]# kubectl delete pod nginx-1zpdh\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"319\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-27.png\" alt=\"\" class=\"wp-image-1225\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-27.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-27-300x111.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-27-768x283.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>node\u8282\u70b9\u6545\u969c\u4e86\u600e\u4e48\u529e\uff1f\n&#91;root@k8s-node01 ~]# systemctl stop kubelet.service\n\u7b49\u5f85\u4e00\u4f1a\uff0cmaster\u53d1\u73b0node1\u8282\u70b9\u6ca1\u4e86\uff0c\u4f1a\u81ea\u52a8\u8fc1\u79fbpod\u8d44\u6e90\u81f3node2\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"246\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-28.png\" alt=\"\" class=\"wp-image-1226\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-28.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-28-300x85.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-28-768x218.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u660e\u663e\u770b\u5230node1\u8282\u70b9\u5df2\u7ecf\u6302\u4e86\uff0c\u4f46\u662fpod\u8d44\u6e90\u6ca1\u6709\u88ab\u8fc1\u79fb\uff0c\u8fd9\u662f\u56e0\u4e3a\u6709\u65f6\u95f4\u95f4\u9694\uff0c\u4e3a\u4e86\u52a0\u5feb\u901f\u5ea6\uff0c\u53ef\u4ee5\u8fdb\u884c\u76d1\u63a7\uff0c\u5f53node\u8282\u70b9\u627e\u4e0d\u5230\u4e86\uff0c\u5c31\u4ecemaster\u4e2d\u79fb\u9664\u8282\u70b9\uff0c\u8fd9\u6837\u5c31\u4f1a\u7acb\u523b\u8fc1\u79fbpod\u8d44\u6e90\u4e86\n&#91;root@k8s-master ~\/k8s_yaml\/rc]# kubectl delete node 10.0.0.12\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"181\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-29.png\" alt=\"\" class=\"wp-image-1227\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-29.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-29-300x63.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-29-768x161.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p>RC\u4e0d\u540cRC\u7684selector\u80fd\u4e0d\u80fd\u4e00\u6837\uff1f\uff08lable\u6807\u7b7e\u7684\u4f5c\u7528\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"299\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-30.png\" alt=\"\" class=\"wp-image-1228\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-30.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-30-300x104.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-30-768x265.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>Rc\u4e4b\u95f4\u4f1a\u4e0d\u4f1a\u51fa\u73b0\u5982\u4e0a\u56fe\u6240\u793a\u60c5\u51b5\nrc1\u7ba1\u7406\u7684\u662f5\u4e2apod\u8d44\u6e90\uff0c\u4f46\u662frc2\u662f3\u4e2a\uff0c\u5f53rc2\u53d1\u73b0rc1\u62c9\u8d775\u4e2apod\u4f1a\u6740\u6b7b\u4e24\u4e2apod\u8d44\u6e90\u3002\u6740\u6b7b\u4e4b\u540e\uff0c\u53c8\u4e0d\u6ee1\u8db3rc1\u7684\u671f\u671b\u4e86\uff0c\u53c8\u4f1a\u62c9\u8d772\u4e2apod\u8d44\u6e90\uff0c\u5982\u6b64\u5f80\u590d\uff0c\u5f88\u9ebb\u70e6\n\u6240\u4ee5\u4f53\u73b0\u4e86\u6807\u7b7e\u7684\u91cd\u8981\u6027\n&#91;root@k8s-master ~\/k8s_yaml\/rc]# kubectl edit pod nginx\u4fee\u6539\u6807\u7b7e\n\u53ef\u4ee5\u770b\u5230\u6807\u7b7e\u6539\u4e86\u4e4b\u540epod\u88ab\u6740\u6b7b\u4e86\u4e00\u4e2a\n\u6240\u4ee5rc\u901a\u8fc7\u6807\u7b7e\u9009\u62e9\u5668\uff08selector\uff09\u6765\u8bc6\u522bpod\u8d44\u6e90\u662f\u5426\u5f52\u81ea\u5df1\u7ba1\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"229\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-31.png\" alt=\"\" class=\"wp-image-1229\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-31.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-31-300x79.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-31-768x203.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>4.rc\u7684\u6eda\u52a8\u5347\u7ea7<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master rc]# cp k8s_rc1.yaml k8s_rc2.yaml\n&#91;root@k8s-master rc]# cat k8s_rc2.yaml \napiVersion: v1\nkind: ReplicationController\nmetadata:\n  name: nginx\nspec:\n  replicas: 5\n  selector:\n    app: myweb2\n  template:\n    metadata:\n      labels:\n        app: myweb2\n    spec:\n      containers:\n      - name: myweb2\n        image: k8s-master:5000\/sunfuyang\/nginx:1.15\n        ports:\n        - containerPort: 80\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"349\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-32.png\" alt=\"\" class=\"wp-image-1232\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-32.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-32-300x121.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-32-768x310.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5347\u7ea7 kubectl rolling-update nginx -f k8s_rc2.yaml --update-period=1s\n\u56de\u6eda kubectl rolling-update nginx2 -f k8s_rc1.yaml --update-period=1s\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.service\u8d44\u6e90<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fsvc<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"376\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-33.png\" alt=\"\" class=\"wp-image-1235\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-33.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-33-300x130.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-33-768x334.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5982\u4e0a\u56fe\u6240\u793a\uff0cService\u662f\u4e00\u7ec4Pod\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\uff0c\u5bf9\u5916\u63d0\u4f9b\u7edf\u4e00\u8bbf\u95ee\u5165\u53e3\u3002Pod\u548cService\u7684\u5173\u7cfb\u5982\u4e0b\u6240\u793a:\n\t(1)service\u901a\u8fc7\u6807\u7b7e\u5173\u8054\u4e00\u7ec4Pod;\n\t(2)service\u4f7f\u7528iptable\u6216\u8005ipvs\u4e3a\u4e00\u7ec4Pod\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u80fd\u529b;\n\nservice\u7684\u5f15\u5165\u4e3b\u8981\u89e3\u51b3Pod\u7684\u52a8\u6001\u53d8\u5316\uff0c\u63d0\u4f9b\u7edf\u4e00\u7684\u8bbf\u95ee\u5165\u53e3\u3002service\u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u4e24\u4e2a\u529f\u80fd:\n\t(1)\u9632\u6b62Pod\u5931\u8054\uff0c\u51c6\u5907\u627e\u5230\u63d0\u4f9b\u540c\u4e00\u4e2a\u670d\u52a1\u7684Pod(\u670d\u52a1\u53d1\u73b0);\n\t(2)\u5b9a\u4e49\u4e00\u7ec4Pod\u7684\u8bbf\u95ee\u7b56\u7565(\u8d1f\u8f7d\u5747\u8861);\n\nservice\u7684\u5de5\u4f5c\u6d41\u7a0b\u56fe\u5982\u4e0b\u56fe\u6240\u793a\u3002\u6211\u4eec\u5927\u81f4\u603b\u7ed3\u4ee5\u4e0bservice\u7684\u5de5\u4f5c\u6d41\u7a0b:\n    (1)\u5f53client\u8bbf\u95ee\u5de5\u4f5c\u8282\u70b9\u7684service\u65f6\uff0c\u9996\u5148\u4ed6\u4f1a\u6839\u636eiptables\/ipvs\u89c4\u5219\u505a\u76f8\u5e94\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u627e\u5230\u540e\u7aef\u7684Pod\u4ee5\u63d0\u4f9b\u670d\u52a1;\n    (2)\u5176\u4e2diptables\/ipvs\u7684\u89c4\u5219\u662f\u7531kube-proxy\u7ec4\u4ef6\u6765\u5b9e\u73b0\u7684;\n\t(3)kubelet\u4f1a\u5b9e\u65f6\u76d1\u63a7\u5bf9\u5e94\u5de5\u4f5c\u8282\u70b9\u7684Pod\u4fe1\u606f;\n\n\u751f\u4ea7\u73af\u5883\u5728\u4f7f\u7528iptables\u548cipvs\u7684\u5bf9\u6bd4\n    iptables:\n        (1)\u7075\u6d3b\uff0c\u529f\u80fd\u5f3a\u5927;\n        (2)\u89c4\u5219\u4ece\u4e0a\u81f3\u4e0b\u904d\u5386\u5339\u914d\u548c\u66f4\u65b0\uff0c\u56e0\u6b64\u5728\u96c6\u7fa4\u89c4\u6a21\u8fc7\u5927\u65f6\uff0c\u53ef\u80fd\u7f3a\u70b9\u5c31\u8d8a\u660e\u663e\uff0c\u56e0\u4e3a\u6bcf\u6b21\u90fd\u9700\u8981\u904d\u5386\u5927\u91cf\u7684\u89c4\u5219;\n\n    ipvs:\n        (1)\u5de5\u4f5c\u5728\u5185\u6838\u6001\uff0c\u6709\u66f4\u597d\u7684\u6027\u80fd;\n        (2)\u8c03\u5ea6\u7b97\u6cd5\u4e30\u5bcc:\"rr\"\uff0c\"wrr\"\uff0c\"lc\"\uff0c\"wlc\"\uff0c\"ip hash\"\u7b49;\n\n    \u7efc\u4e0a\u6240\u8ff0\uff0c\u63a8\u8350\u5927\u5bb6\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528\"ipvs\"\u6a21\u5f0f\u3002k8s 1.8+\u7248\u672c\u4e2d\u63a8\u8350\u4f7f\u7528lvs(\u56db\u5c42\u8d1f\u8f7d\u5747\u8861 \u4f20\u8f93\u5c42tcp,udp)\uff0c\u5728\u65e9\u671f\u7248\u672c\u4e2d\uff0c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fiptables\u89c4\u5219\u54df\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u521b\u5efa\u4e00\u4e2asvc\u8d44\u6e90<\/em><\/strong><\/p>\n\n\n\n<p>\u521b\u5efak8s_svc1.yaml\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master k8s_yaml]# mkdir svc\n&#91;root@k8s-master k8s_yaml]# cd svc\/\n&#91;root@k8s-master svc]# cat k8s_svc.yaml \napiVersion: v1\nkind: Service   #\u7b80\u79f0svc\nmetadata:\n  name: myweb\nspec:\n  #clusterIP: 10.254.86.101 ##\u6307\u5b9asvc\u7684IP\u5730\u5740\n  type: NodePort  #\u9ed8\u8ba4ClusterIP\n  ports:\n    - port: 80          #clusterIP\n      nodePort: 30000   #node port\n      targetPort: 80    #pod port\n  selector:\n    app: myweb2\n&#91;root@k8s-master svc]# kubectl create -f k8s_svc.yaml\n<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u4e00\u4e0b\u521b\u5efa\u7684\u7ed3\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"357\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-34.png\" alt=\"\" class=\"wp-image-1238\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-34.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-34-300x124.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-34-768x317.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"452\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-35.png\" alt=\"\" class=\"wp-image-1239\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-35.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-35-300x157.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-35-768x401.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53ef\u4ee5\u770b\u5230svc\u901a\u8fc7\u6807\u7b7e\u5173\u8054\u4e86pod\uff0c\u540c\u65f6\u4e24\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u8bbf\u95ee\u5230\u8d44\u6e90\n\u4fee\u6539\u526f\u672c\u6570\u91cf\uff0c\u5e76\u89c2\u5bdf\u5bf9\u5e94service\u7684Endpoints\u4fe1\u606f\u53d8\u5316\nkubectl scale rc nginx --replicas=2 #\u8c03\u6574rc\u7684\u526f\u672c\u4e66\nkubectl exec -it pod_name \/bin\/bash #\u8fdb\u5165pod\u5bb9\u5668\n<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u4fee\u6539nodePort\u8303\u56f4<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim  \/etc\/kubernetes\/apiserver \nKUBE_API_ARGS=\"--service-node-port-range=3000-60000\"<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u547d\u4ee4\u884c\u521b\u5efasvc\u8d44\u6e90<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl expose rc nginx --type=NodePort --port=80\nservice\u9ed8\u8ba4\u4f7f\u7528iptables\u6765\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861, k8s 1.8\u65b0\u7248\u672c\u4e2d\u63a8\u8350\u4f7f\u7528lvs(\u56db\u5c42\u8d1f\u8f7d\u5747\u8861 \u4f20\u8f93\u5c42tcp,udp)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><em><strong>5.service\u8d44\u6e90\u5e38\u7528\u7684\u7c7b\u578b<\/strong><\/em><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>ClusterIP\u7c7b\u578b\n\u9ed8\u8ba4\u7684\u7c7b\u578b\uff0c\u5206\u914d\u4e00\u4e2a\u7a33\u5b9a\u7684IP\u5730\u5740\uff0c\u5373VIP\uff0c\u53ea\u80fd\u5728\u96c6\u7fa4\u5185\u90e8\u8bbf\u95ee\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u9002\u7528\u4e8eK8S\u96c6\u7fa4\u5185\u90e8\uff0c\u8fd9\u610f\u5473\u7740k8s\u96c6\u7fa4\u5916\u90e8\u5c06\u65e0\u6cd5\u8bbf\u95ee\u5230\nNodePort\u7c7b\u578b\n\u9002\u7528\u4e8e\u5bf9K8S\u96c6\u7fa4\u5916\u90e8\u66b4\u9732\u5e94\u7528\uff0c\u4f1a\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u542f\u7528\u4e00\u4e2a\u7aef\u53e3\u6765\u66b4\u9732\u670d\u52a1\uff0c\u53ef\u4ee5\u5728\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee\u3002\u4e5f\u4f1a\u5206\u914d\u4e00\u4e2a\u7a33\u5b9a\u5185\u90e8\u96c6\u7fa4IP\u5730\u5740\u3002\nLoadBalancer\u7c7b\u578b\n\u9002\u5408\u5728\u516c\u6709\u4e91\u4e0a\u5bf9K8S\u96c6\u7fa4\u5916\u90e8\u66b4\u9732\u5e94\u7528\u3002\n\u4e0eNodePort\u7c7b\u4f3c\uff0c\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u542f\u7528\u4e00\u4e2a\u7aef\u53e3\u6765\u66b4\u9732\u670d\u52a1\u3002\u9664\u6b64\u4e4b\u5916\uff0ckubernetes\u4f1a\u8bf7\u6c42\u5e95\u5c42\u4e91\u5e73\u53f0(\u4f8b\u5982\u963f\u91cc\u4e91\uff0c\u817e\u8baf\u4e91\uff0cAWS\u7b49)\u4e0a\u7684\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u5c06\u6bcf\u4e2aNode(&lt;NodeIP&gt;:&lt;NodePort&gt;)\u4f5c\u4e3a\u540e\u7aef\u6dfb\u52a0\u8fdb\u53bb\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.deployment\u8d44\u6e90<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fdeployment<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6709rc\u5728\u6eda\u52a8\u5347\u7ea7\u4e4b\u540e,\u4f1a\u9020\u6210\u670d\u52a1\u8bbf\u95ee\u4e2d\u65ad\u3002\u8fd9\u662f\u56e0\u4e3a\u57fa\u4e8erc\u6eda\u52a8\u5347\u7ea7\u65f6\u5176\u5bf9\u5e94\u7684Pod\u6807\u7b7e\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u60f3\u8981\u5feb\u901f\u6062\u590d\u4e1a\u52a1\uff0c\u5219\u9700\u8981\u4eba\u5de5\u624b\u52a8\u4fee\u6539\"svc\"\u8d44\u6e90\u7ba1\u7406\u7684pod\u6807\u7b7e\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5c3d\u7ba1\u60a8\u7684\u624b\u901f\u518d\u5feb\u4e5f\u662f\u4f1a\u5728\u77ed\u65f6\u95f4\u5185\u9020\u6210\u670d\u52a1\u7684\u4e2d\u65ad\u3002\n\u7efc\u4e0a\u6240\u8ff0\uff0c\u4e8e\u662fk8s\u5f15\u5165\u4e86deployment\u8d44\u6e90\u3002Deployment\u662f\u6700\u5e38\u89c1\u7684\u63a7\u5236\u5668\uff0c\u7528\u4e8e\u66f4\u9ad8\u7ea7\u90e8\u7f72\u548c\u7ba1\u7406Pod\u3002\nDeployment\u529f\u80fd:\n         (1)\u7ba1\u7406ReplicaSet,\u901a\u8fc7RS\u8d44\u6e90\u7ba1\u7406Pod;\n         (2)\u5177\u6709\u4e0a\u7ebf\u90e8\u7f72\uff0c\u526f\u672c\u8bbe\u5b9a\uff0c\u6eda\u52a8\u5347\u7ea7\uff0c\u56de\u6eda\u7b49\u529f\u80fd;\n         (3)\u63d0\u4f9b\u58f0\u660e\u5f0f\u66f4\u65b0\uff08\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c31\u662f\u544a\u8bc9deployment\u8d44\u6e90\u66f4\u65b0\u4ec0\u4e48\u5185\u5bb9\uff09\uff0c\u4f8b\u5982\u53ea\u66f4\u65b0\u4e00\u4e2a\u65b0\u7684Image;\n\u5e94\u7528\u573a\u666f:         \u7f51\u7ad9\uff0cAPI\uff0c\u5fae\u670d\u52a1\u7b49\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u57fa\u4e8edeployment\u90e8\u7f72Pod\u5e76\u8fdb\u884c\u8d44\u6e90\u9650\u5236<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master k8s_yaml]# mkdir deployment\n&#91;root@k8s-master k8s_yaml]# cd deployment\/\n&#91;root@k8s-master deployment]# cat k8s_deployment1.yaml\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n  name: nginx\nspec:\n  replicas: 3\n  strategy:   \n    rollingUpdate:\n      maxSurge: 1  \n      maxUnavailable: 1 \n    type: RollingUpdate\n  minReadySeconds: 30\n  template:\n    metadata:\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: k8s-master\/sunfuyang\/nginx:1.13\n        ports:\n        - containerPort: 80\n        resources:  ###\u8d44\u6e90\n          limits:   ###\u8d44\u6e90\u9650\u5236\n            cpu: 100m\n            memory: 10M\n          requests:   ###\u8d44\u6e90\u9700\u6c42\n            cpu: 100m\n            memory: 10M\n&#91;root@k8s-master deployment]# kubectl create -f k8s_deployment1.yaml\n&#91;root@k8s-node-2 ~]# docker container stats --no-stream\n\u53ef\u4ee5\u5f88\u660e\u663e\u7684\u770b\u5230\u65b0\u521b\u5efa\u7684pod\u8d44\u6e90\u88ab\u9650\u5236\u4e86\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"187\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-36.png\" alt=\"\" class=\"wp-image-1253\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-36.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-36-300x65.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-36-768x166.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>3.\u57fa\u4e8e\u547d\u4ee4\u884c\u7684\u65b9\u5f0f\u5bf9deplpyment\u8d44\u6e90\u8fdb\u884c\u6eda\u52a8\u5347\u7ea7\u548c\u56de\u6eda<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u547d\u4ee4\u884c\u5347\u7ea7\u7248\u672c\n&#91;root@k8s-master svc]# kubectl set image deploy nginx nginx=k8s-master:5000\/sunfuyang\/nginx:1.13\n###nginx=xxx \u8fd9\u4e2anginx\u662f\u5bb9\u5668\u7684\u540d\u5b57\n\u67e5\u770bdeployment\u6240\u6709\u5386\u53f2\u7248\u672c\nkubectl rollout history deployment nginx\n\u56de\u6eda\u5230\u4e0a\u4e00\u4e2a\u7248\u672c\nkubectl rollout undo deployment nginx\n\u56de\u6eda\u5230\u6307\u5b9a\u7248\u672c\nkubectl rollout undo deployment nginx --to-revision=2\n<\/code><\/pre>\n\n\n\n<p><strong><em>4.deplpyment\u8d44\u6e90yaml\u6587\u4ef6\u6307\u5b9a\u5347\u7ea7\u7b56\u7565<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master deployment]# cat k8s_deployment2.yaml\napiVersion: extensions\/v1beta1  # \u6ce8\u610f\u89c2\u5bdf\u8fd9\u4e2aAPI\u7684\u7248\u672c\u7f16\u53f7\u54df~\u5728\u540e\u671f\u7684\u7248\u672c\u4e2d\u5176\u662f\u6709\u53d8\u5316\u7684!\nkind: Deployment\nmetadata:\n  name: nginx\nspec:\n  replicas: 5  # \u6307\u5b9a\u542f\u52a8Pod\u7684\u526f\u672c\u6570\u3002\n  strategy:  # \u6307\u5b9a\u6eda\u52a8\u5347\u7ea7\u7b56\u7565\n    rollingUpdate:\n      maxSurge: 2  # \u5728\u539f\u6709\u7684Pod\u57fa\u7840\u4e0a\uff0c\u591a\u542f\u52a8Pod\u7684\u6570\u91cf\uff0c\u5047\u8bbe\u539f\u6765\u5f85\u5347\u7ea7\u7684Pod\u6570\u91cf\u4e3a5\uff0c\u5982\u679c\u6211\u4eec\u8be5\u503c\u8bbe\u7f6e\u4e3a2\uff0c\u8868\u793a\u540c\u65f6\u5141\u8bb8\u542f\u52a85 + 2\u4e2a\u5bb9\u5668\u6570\u91cf\u3002 \u6ce8\u610f\u54c8\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u6307\u5b9a\u767e\u5206\u6bd4\u54df~\n      maxUnavailable: 1   # \u6307\u5b9a\u6700\u5927\u4e0d\u53ef\u7528\u7684Pod\u6570\u91cf\uff0c\u5982\u679c\u6211\u4eec\u8bbe\u7f6e\u8be5\u503c\u4e3a1\uff0c\u5f88\u660e\u663e\uff0c\u526f\u672c\u6570\u4e3a5\uff0c\u8868\u793a\u6700\u5c11\u8981\u67094\u4e2aPod\u662f\u53ef\u7528\u7684\u3002\n    type: RollingUpdate  # \u6eda\u52a8\u5347\u7ea7\n  minReadySeconds: 30  # \u6307\u5b9aPod\u5347\u7ea7\u7684\u95f4\u9694\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002\n  template:\n    metadata:\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: k8s-master:5000\/sunfuyang\/nginx:1.15\n        ports:\n        - containerPort: 80\n        resources:  \n          limits:\n            cpu: 100m\n            memory: 10M\n          requests:\n            cpu: 100m\n            memory: 10M\n&#91;root@k8s-master deployment]# kubectl apply -f k8s_deployment2.yaml\n<\/code><\/pre>\n\n\n\n<p><strong><em>5.deplpyment\u8d44\u6e90\u548crc\u8d44\u6e90\u7684\u533a\u522b<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5171\u540c\u70b9:\n(1)\u53ef\u4ee5\u63a7\u5236Pod\u6570\u91cf;\n(2)\u90fd\u53ef\u4ee5\u6eda\u52a8\u5347\u7ea7;\n(3)\u901a\u8fc7\u6807\u7b7e\u9009\u62e9\u5668\u5173\u8054Pod;\n\u4e0d\u540c\u70b9:\n(1)rc\u5347\u7ea7\u9700\u8981yaml\u6587\u4ef6(\u5982\u679c\u5728\u4f7f\u7528\u8005\u4fee\u6539\u4e86\u6587\u4ef6\u5185\u5bb9\u4f1a\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6)\uff0cdeployment\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u5b9e\u65f6\u751f\u6548(\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u4f7f\u7528\"kubectl edit deployment nginx\"\u6848\u4f8b);\n(2)rc\u5347\u7ea7\u4f1a\u5bfc\u81f4\u670d\u52a1\u4e2d\u65ad\uff08\u9700\u8981\u624b\u52a8\u4fee\u6539service\u7684\u6807\u7b7e\uff09\uff0c\u800cdeployment\u5347\u7ea7\u5e76\u4e0d\u4f1a\u4e2d\u65ad\u670d\u52a1\u8bbf\u95ee;\n(3)rc\u76f4\u63a5\u63a7\u5236Pod\uff0c\u800cdeployment\u57fa\u4e8ers\u6765\u63a7\u5236Pod;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">5.daemonset\u8d44\u6e90<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fdaemonset<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DaemonSet\u529f\u80fd\u6982\u8ff0:\r\n(1)\u5728\u6bcf\u4e00\u4e2aNode\u4e0a\u8fd0\u884c\u4e00\u4e2apod;\r\n(2)\u65b0\u52a0\u5165\u7684Node\u4e5f\u540c\u6837\u4f1a\u81ea\u52a8\u8fd0\u884c\u4e00\u4e2aPod;\r\n\u5e94\u7528\u573a\u666f:\r\n(1)\u7f51\u7edc\u63d2\u4ef6(\u4f8b\u5982kube-proxy\uff0ccolico);\r\n(2)zabbix agent;\r\n(3)node_export;\r\n(4)\u65e5\u5fd7\u6536\u96c6\u7aef\uff0c\u4f8b\u5982filebeat;\r\n\u6e29\u99a8\u63d0\u793a:\r\n(1)DaemonSet\u4e0d\u652f\u6301\u526f\u672c\u8bbe\u7f6e\u54df\uff0c\u5176\u7279\u70b9\u662f\u5728\u6240\u6709\u4e0d\u542b\u6c61\u70b9\u7684\u5de5\u4f5c\u8282\u70b9\u4e0a\u53ea\u8fd0\u884c\u4e00\u4e2aPod\uff0c\u5982\u679c\u914d\u7f6e\u4e86\u6c61\u70b9\u5bb9\u5fcd\u4e5f\u53ef\u4ee5\u5728\u88ab\u6253\u6c61\u70b9\u7684\u5de5\u4f5c\u8282\u70b9\u4e0a\u8fd0\u884c\u54df;\r\n(2)DaemonSet\u4e5f\u652f\u6301\u6eda\u52a8\u66f4\u65b0\uff0c\u4f46\u662f\u6ca1\u5fc5\u8981\u8bbe\u7f6e\u66f4\u65b0\u7b56\u7565\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u521b\u5efa\u4e00\u4e2adaemonset\u8d44\u6e90<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master k8s_yaml]# mkdir daemonset\r\n&#91;root@k8s-master k8s_yaml]# cd daemonset\/\r\n&#91;root@k8s-master daemonset]# cat k8s_DaemonSet.yaml \r\napiVersion: extensions\/v1beta1\r\nkind: DaemonSet\r\nmetadata:\r\n  name: nginx-ds\r\nspec:\r\n  template:\r\n    metadata:\r\n      labels:\r\n        app: nginx-ds\r\n    spec:\r\n      containers:\r\n      - name: nginx-ds\r\n        image: k8s-master:5000\/sunfuyang\/nginx:1.13\r\n        ports:\r\n        - containerPort: 80\r\n        resources:  \r\n          limits:\r\n            cpu: 100m\r\n            memory: 10M\r\n          requests:\r\n            cpu: 100m\r\n            memory: 10M\r\n&#91;root@k8s-master daemonset]# kubectl apply -f k8s_DaemonSet.yaml\r\n\u4e0b\u56fe\u53ef\u4ee5\u770b\u5230\u867d\u7136\u6ca1\u6709\u5b9a\u4e49\u526f\u672c\u6570\uff0c\u4f46\u662f\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709pod\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"110\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-37.png\" alt=\"\" class=\"wp-image-1260\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-37.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-37-300x38.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-37-768x98.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1205"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1205"}],"version-history":[{"count":21,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1205\/revisions"}],"predecessor-version":[{"id":1261,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1205\/revisions\/1261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/media\/246"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}