{"id":1443,"date":"2023-03-23T22:10:17","date_gmt":"2023-03-23T14:10:17","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1443"},"modified":"2023-04-28T20:51:28","modified_gmt":"2023-04-28T12:51:28","slug":"basic-operations-of-service-and-rc-for-kubernetes-api-microservice-development","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/23\/basic-operations-of-service-and-rc-for-kubernetes-api-microservice-development\/","title":{"rendered":"Kubernetes api\u5fae\u670d\u52a1\u5f00\u53d1\u4e4bservice\u4e0erc\u57fa\u672c\u64cd\u4f5c"},"content":{"rendered":"<p>\u76ee\u6807\uff1a\u5b8c\u6210<code>Service<\/code>\u4e0e<code>Replication Controller<\/code>\u670d\u52a1\u57fa\u672c\u529f\u80fd(CRUD)\u7684\u5f00\u53d1\uff0c\u5e76\u4e14\u57fa\u4e8efabric8\u7c7b\u65b9\u6cd5\u4f18\u5316pod\u670d\u52a1\u4ee3\u7801<\/p>\n<h2>\u57fa\u672c\u6982\u5ff5<\/h2>\n<p><!-- more --><\/p>\n<p><code>Replication Controller<\/code>\uff1a\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6a21\u677f\uff0c\u8bbe\u5b9apod\u526f\u672c\u6570\uff0c\u6301\u7eed\u76d1\u63a7\u4f7fpod\u6570\u59cb\u7ec8\u7ef4\u6301\u5728\u671f\u671b\u503c\u3002<br \/>\n<code>Service<\/code>\uff1a\u5b9a\u4e49\u4e86\u4e00\u79cd\u7279\u5b9a\u7684\u670d\u52a1\uff0c\u521b\u5efa\u540e\u5728Kubernetes\u4e2d\u62e5\u6709\u56fa\u5b9a\u7684\u901a\u4fe1\u5730\u5740\uff0c\u5728\u5176\u751f\u547d\u5468\u671f\u5185\u4e0d\u4f1a\u6539\u53d8\uff0c\u5e76\u4e14\u80fd\u591f\u5bf9\u5916\u670d\u52a1\uff0c\u8f6c\u53d1\u5916\u90e8\u8bf7\u6c42\u81f3pod\u3002<\/p>\n<h2>Pod\u4ee3\u7801\u4f18\u5316<\/h2>\n<p>\u4e0a\u4e00\u7bc7\u535a\u6587\u4e2d\u4f7f\u7528fabric8\u6846\u67b6\uff0c\u91c7\u53d6\u5206\u522b\u521b\u5efa\u5bf9\u8c61\u7684\u65b9\u5f0f\u4f20\u5165\u53c2\u6570\uff0c\u4e0d\u591f\u7b80\u6d01\uff0c\u672c\u6587\u4f7f\u7528\u5404\u8d44\u6e90\u5bf9\u8c61\u7c7b\u7684\u521b\u5efa\u65b9\u6cd5\u8fdb\u884c\u4ee3\u7801\u4f18\u5316\uff1a\u5728<code>DevK8sApiService.java<\/code>\u4e2d\u4f7f\u7528PodBuilder\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">\/\/\u521b\u5efaPod\npublic static Pod createPod(String nsName, String podName, String labelkey, String labelvalue, String containerName, String imageName, int cnPort) {\n    Pod pod = new PodBuilder()\n            .withApiVersion(&quot;v1&quot;)\n            .withKind(&quot;Pod&quot;)\n            .withNewMetadata()\n            .withName(podName)\n            .withNamespace(nsName)\n            .addToLabels(labelkey, labelvalue)\n            .endMetadata()\n            .withNewSpec()\n            .addNewContainer()\n            .withName(containerName)\n            .withImage(imageName)\n            .addNewPort()\n            .withContainerPort(cnPort)\n            .endPort()\n            .endContainer()\n            .endSpec()\n            .build();\n    try {\n        \/\/Pod \u521b\u5efa\n        kubernetesClient.pods().create(pod);\n        log.info(&quot;pod create success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;pod create failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return pod;\n}\n\n\/\/\u5220\u9664pod\npublic Pod deletePod(String namespaceName, String podName) {\n    Pod pod = new Pod();\n    try {\n        \/\/\u83b7\u53d6\u8981\u5220\u9664\u7684pod\n        pod = kubernetesClient.pods().inNamespace(namespaceName).withName(podName).get();\n        \/\/Pod \u5220\u9664\n        kubernetesClient.pods().inNamespace(namespaceName).withName(podName).delete();\n        log.info(&quot;pod delete success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;pod create failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return pod;\n}\n\n\/\/\u67e5\u8be2pod\npublic Pod readPod(String namespaceName, String podName) {\n    Pod pod = new Pod();\n    try {\n        \/\/\u83b7\u53d6\u8981\u67e5\u8be2\u7684pod\n        pod = kubernetesClient.pods().inNamespace(namespaceName).withName(podName).get();\n        log.info(&quot;pod read success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;pod read failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return pod;\n}<\/code><\/pre>\n<h2>Replication Controller\u670d\u52a1\u57fa\u672c\u529f\u80fd\u5f00\u53d1<\/h2>\n<p>\u4e0epod\u670d\u52a1\u5f00\u53d1\u7c7b\u4f3c\uff0c\u4f7f\u7528\u8d44\u6e90\u5bf9\u8c61\u7c7b\u7684\u57fa\u672c\u65b9\u6cd5\u5b9e\u73b0rc\u670d\u52a1\u7684CRUD\u529f\u80fd<\/p>\n<p>\uff081\uff09DevK8sApiService.java<\/p>\n<pre><code class=\"language-java\">\/\/\u521b\u5efaReplication Controller\npublic ReplicationController createRC(String rcName, String nsName, String lbkey, String lbvalue, int replicas, String ctName, String imName, int cnPort) {\n    ReplicationController rc = new ReplicationControllerBuilder()\n            .withApiVersion(&quot;v1&quot;)\n            .withKind(&quot;ReplicationController&quot;)\n            .withNewMetadata()\n            .withName(rcName)\n            .withNamespace(nsName)\n            .addToLabels(lbkey, lbvalue)\n            .endMetadata()\n            .withNewSpec()\n            .withReplicas(replicas)\n            .addToSelector(lbkey, lbvalue)\n            .withNewTemplate()\n            .withNewMetadata()\n            .addToLabels(lbkey, lbvalue)\n            .endMetadata()\n            .withNewSpec()\n            .addNewContainer()\n            .withName(ctName)\n            .withImage(imName)\n            .addNewPort()\n            .withContainerPort(cnPort)\n            .endPort()\n            .endContainer()\n            .endSpec()\n            .endTemplate()\n            .endSpec()\n            .build();\n    try {\n        kubernetesClient.replicationControllers().create(rc);\n        log.info(&quot;replication controller create success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;replication controller create failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return rc;\n}\n\n\/\/\u5220\u9664Replication Controller\npublic ReplicationController deleteRC(String nsName, String rcName) {\n    ReplicationController rc = new ReplicationController();\n    try {\n        rc = kubernetesClient.replicationControllers().inNamespace(nsName).withName(rcName).get();\n        kubernetesClient.replicationControllers().inNamespace(nsName).withName(rcName).delete();\n        log.info(&quot;replication controller delete success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;replication controller delete failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return rc;\n}\n\n\/\/\u67e5\u8be2Replication Controller\npublic ReplicationController readRC(String nsName, String rcName) {\n    ReplicationController rc = new ReplicationController();\n    try {\n        rc = kubernetesClient.replicationControllers().inNamespace(nsName).withName(rcName).get();\n        log.info(&quot;replication controller read success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;replication controller read failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return rc;\n}<\/code><\/pre>\n<p>\uff082\uff09DevK8sApiController.java<\/p>\n<pre><code class=\"language-java\">\/\/k8s rc create\n@RequestMapping(value = &quot;\/createRC&quot;, method = RequestMethod.POST)\npublic ReplicationController createK8sRC(@RequestParam(value = &quot;ReplicationControllerName&quot;) String rcName,\n                                         @RequestParam(value = &quot;NamespaceName&quot;) String nsName,\n                                         @RequestParam(value = &quot;LabelKey&quot;) String lbkey,\n                                         @RequestParam(value = &quot;LabelValue&quot;) String lbvalue,\n                                         @RequestParam(value = &quot;Replicas&quot;) int replicas,\n                                         @RequestParam(value = &quot;ContainerName&quot;) String ctName,\n                                         @RequestParam(value = &quot;ImageName&quot;) String imName,\n                                         @RequestParam(value = &quot;ContainerPort&quot;) int cnPort) {\n    return devK8sApiService.createRC(rcName, nsName, lbkey, lbvalue, replicas, ctName, imName, cnPort);\n}\n\n\/\/k8s rc delete\n@RequestMapping(value = &quot;\/deleteRC&quot;, method = RequestMethod.DELETE)\npublic ReplicationController deleteK8sRC(@RequestParam(value = &quot;NamespaceName&quot;) String nsName,\n                                         @RequestParam(value = &quot;ReplicationControllerName&quot;) String rcName) {\n    return devK8sApiService.deleteRC(nsName, rcName);\n}\n\n\/\/k8s rc read\n@RequestMapping(value = &quot;\/readRC&quot;, method = RequestMethod.GET)\npublic ReplicationController readK8sRC(@RequestParam(value = &quot;NamespaceName&quot;) String nsName,\n                                       @RequestParam(value = &quot;ReplicationControllerName&quot;) String rcName) {\n    return devK8sApiService.readRC(nsName, rcName);\n}<\/code><\/pre>\n<h2>Service\u670d\u52a1\u57fa\u672c\u529f\u80fd\u5f00\u53d1<\/h2>\n<p>\uff081\uff09DevK8sApiService.java<\/p>\n<pre><code class=\"language-java\">\/\/\u521b\u5efaService\npublic Service createService(String seriveName, String nsName, String labelkey, String labelvalue, int cnPort, int nodePort) {\n    Service service = new ServiceBuilder()\n            .withApiVersion(&quot;v1&quot;)\n            .withKind(&quot;Service&quot;)\n            .withNewMetadata()\n            .withName(seriveName)\n            .withNamespace(nsName)\n            .addToLabels(labelkey, labelvalue)\n            .endMetadata()\n            .withNewSpec()\n            .addNewPort()\n            .withPort(cnPort)\n            .withNodePort(nodePort)\n            .endPort()\n            .withType(&quot;NodePort&quot;)\n            .addToSelector(labelkey, labelvalue)\n            .endSpec()\n            .build();\n    try {\n        kubernetesClient.services().create(service);\n        log.info(&quot;service create success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;service create failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return service;\n}\n\n\/\/\u5220\u9664Service\npublic Service deleteService(String namespaceName, String serviceName) {\n    Service service = new Service();\n    try {\n        service = kubernetesClient.services().inNamespace(namespaceName).withName(serviceName).get();\n        kubernetesClient.services().inNamespace(namespaceName).withName(serviceName).delete();\n        log.info(&quot;service delete success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;service delete failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return service;\n}\n\n\/\/\u67e5\u8be2Service\npublic Service readService(String namespaceName, String serviceName) {\n    Service service = new Service();\n    try {\n        service = kubernetesClient.services().inNamespace(namespaceName).withName(serviceName).get();\n        log.info(&quot;service read success&quot;);\n    } catch (Exception e) {\n        log.error(&quot;service read failed&quot;);\n        log.error(&quot;&quot;, e);\n    }\n    return service;\n}<\/code><\/pre>\n<p>\uff082\uff09DevK8sApiController.java<\/p>\n<pre><code class=\"language-java\">\/\/k8s service create\n@RequestMapping(value = &quot;\/createService&quot;, method = RequestMethod.POST)\npublic Service createK8sService(@RequestParam(value = &quot;ServiceName&quot;) String srName,\n                                @RequestParam(value = &quot;NameSpaceName&quot;) String nsName,\n                                @RequestParam(value = &quot;LabelKey&quot;) String lbkey,\n                                @RequestParam(value = &quot;LabelValue&quot;) String lbvalue,\n                                @RequestParam(value = &quot;ContainerPort&quot;) int cnPort,\n                                @RequestParam(value = &quot;NodePort&quot;) int ndPort) {\n    return devK8sApiService.createService(srName, nsName, lbkey, lbvalue, cnPort, ndPort);\n}\n\n\/\/k8s service delete\n@RequestMapping(value = &quot;\/deleteService&quot;, method = RequestMethod.DELETE)\npublic Service deleteK8sService(@RequestParam(value = &quot;NamespaceName&quot;) String nsName,\n                                @RequestParam(value = &quot;ServiceName&quot;) String srName) {\n    return devK8sApiService.deleteService(nsName, srName);\n}\n\n\/\/k8s service read\n@RequestMapping(value = &quot;\/readService&quot;, method = RequestMethod.GET)\npublic Service readK8sService(@RequestParam(value = &quot;NamespaceName&quot;) String nsName,\n                              @RequestParam(value = &quot;ServiceName&quot;) String srName) {\n    return devK8sApiService.readService(nsName, srName);\n}<\/code><\/pre>\n<h2>\u8fd0\u884c\u6d4b\u8bd5<\/h2>\n<p>\u6d4b\u8bd5\uff1a\u4f7f\u7528nginx\u955c\u50cf\u5b9a\u4e49\u4e00\u4e2a3\u526f\u672cRC\uff0c\u5e76\u5b9a\u4e49\u4e00\u4e2aService\u4ee5NodePort\u65b9\u5f0f\u5bf9\u63a5pods<\/p>\n<h3>RC\u521b\u5efa<\/h3>\n<p><code>POST<\/code>: <code>http:\/\/127.0.0.1:8080\/k8s\/createRC<\/code><br \/>\n<code>Content-Type<\/code>: <code>application\/x-www-form-urlencoded<\/code><br \/>\n<code>Body<\/code>: {&quot;ReplicationControllerName&quot;:&quot;nginx-rc-1.17.0&quot;, &quot;NameSpaceName&quot;:&quot;appblog&quot;, &quot;LabelKey&quot;:&quot;name&quot;, &quot;LabelValue&quot;:&quot;nginx-1.17.0&quot;, &quot;Replicas&quot;:&quot;3&quot;, &quot;ContainerName&quot;:&quot;nginx-1170&quot;, &quot;ImageName&quot;:&quot;nginx&quot;, &quot;ContainerPort&quot;:&quot;80&quot;}<\/p>\n<pre><code class=\"language-json\">{\n    &quot;apiVersion&quot;: &quot;v1&quot;,\n    &quot;kind&quot;: &quot;ReplicationController&quot;,\n    &quot;metadata&quot;: {\n        &quot;annotations&quot;: {},\n        &quot;labels&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;name&quot;: &quot;nginx-rc-1.17.0&quot;,\n        &quot;namespace&quot;: &quot;appblog&quot;\n    },\n    &quot;spec&quot;: {\n        &quot;replicas&quot;: 3,\n        &quot;selector&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;template&quot;: {\n            &quot;metadata&quot;: {\n                &quot;annotations&quot;: {},\n                &quot;labels&quot;: {\n                    &quot;name&quot;: &quot;nginx-1.17.0&quot;\n                }\n            },\n            &quot;spec&quot;: {\n                &quot;containers&quot;: [\n                    {\n                        &quot;image&quot;: &quot;nginx&quot;,\n                        &quot;name&quot;: &quot;nginx-1170&quot;,\n                        &quot;ports&quot;: [\n                            {\n                                &quot;containerPort&quot;: 80\n                            }\n                        ]\n                    }\n                ],\n                &quot;nodeSelector&quot;: {}\n            }\n        }\n    }\n}<\/code><\/pre>\n<p>\u7ed3\u679c\u67e5\u8be2<\/p>\n<pre><code>[root@k8s-master ~]# kubectl get rc -n appblog\nNAME              DESIRED   CURRENT   READY   AGE\nnginx-rc-1.17.0   3         3         3       8m14s\n[root@k8s-master ~]# kubectl get pods -n appblog\nNAME                    READY   STATUS    RESTARTS   AGE\nnginx-rc-1.17.0-9fkq6   1\/1     Running   0          8m6s\nnginx-rc-1.17.0-dj2ft   1\/1     Running   0          8m6s\nnginx-rc-1.17.0-gwj7w   1\/1     Running   0          8m6s<\/code><\/pre>\n<h3>RC\u67e5\u8be2<\/h3>\n<p><code>URL<\/code>: <a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/127.0.0.1:8080\/k8s\/readRC?NamespaceName=appblog&amp;ReplicationControllerName=nginx-rc-1.17.0\">http:\/\/127.0.0.1:8080\/k8s\/readRC?NamespaceName=appblog&#038;ReplicationControllerName=nginx-rc-1.17.0<\/a><\/p>\n<pre><code class=\"language-json\">{\n    &quot;apiVersion&quot;: &quot;v1&quot;,\n    &quot;kind&quot;: &quot;ReplicationController&quot;,\n    &quot;metadata&quot;: {\n        &quot;creationTimestamp&quot;: &quot;2019-06-14T14:13:19Z&quot;,\n        &quot;generation&quot;: 1,\n        &quot;labels&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;name&quot;: &quot;nginx-rc-1.17.0&quot;,\n        &quot;namespace&quot;: &quot;appblog&quot;,\n        &quot;resourceVersion&quot;: &quot;355429&quot;,\n        &quot;selfLink&quot;: &quot;\/api\/v1\/namespaces\/appblog\/replicationcontrollers\/nginx-rc-1.17.0&quot;,\n        &quot;uid&quot;: &quot;8f4391ef-8eae-11e9-b4ff-525400a204f6&quot;\n    },\n    &quot;spec&quot;: {\n        &quot;replicas&quot;: 3,\n        &quot;selector&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;template&quot;: {\n            &quot;metadata&quot;: {\n                &quot;labels&quot;: {\n                    &quot;name&quot;: &quot;nginx-1.17.0&quot;\n                }\n            },\n            &quot;spec&quot;: {\n                &quot;containers&quot;: [\n                    {\n                        &quot;image&quot;: &quot;nginx&quot;,\n                        &quot;imagePullPolicy&quot;: &quot;Always&quot;,\n                        &quot;name&quot;: &quot;nginx-1170&quot;,\n                        &quot;ports&quot;: [\n                            {\n                                &quot;containerPort&quot;: 80,\n                                &quot;protocol&quot;: &quot;TCP&quot;\n                            }\n                        ],\n                        &quot;resources&quot;: {},\n                        &quot;terminationMessagePath&quot;: &quot;\/dev\/termination-log&quot;,\n                        &quot;terminationMessagePolicy&quot;: &quot;File&quot;\n                    }\n                ],\n                &quot;dnsPolicy&quot;: &quot;ClusterFirst&quot;,\n                &quot;restartPolicy&quot;: &quot;Always&quot;,\n                &quot;schedulerName&quot;: &quot;default-scheduler&quot;,\n                &quot;securityContext&quot;: {},\n                &quot;terminationGracePeriodSeconds&quot;: 30\n            }\n        }\n    },\n    &quot;status&quot;: {\n        &quot;availableReplicas&quot;: 3,\n        &quot;fullyLabeledReplicas&quot;: 3,\n        &quot;observedGeneration&quot;: 1,\n        &quot;readyReplicas&quot;: 3,\n        &quot;replicas&quot;: 3\n    }\n}<\/code><\/pre>\n<h3>Service\u521b\u5efa<\/h3>\n<p><code>POST<\/code>: <code>http:\/\/127.0.0.1:8080\/k8s\/createService<\/code><br \/>\n<code>Content-Type<\/code>: <code>application\/x-www-form-urlencoded<\/code><br \/>\n<code>Body<\/code>: {&quot;ServiceName&quot;:&quot;nginx-service-1170&quot;, &quot;NameSpaceName&quot;:&quot;appblog&quot;, &quot;LabelKey&quot;:&quot;name&quot;, &quot;LabelValue&quot;:&quot;nginx-1.17.0&quot;, &quot;ContainerPort&quot;:&quot;80&quot;, &quot;NodePort&quot;:&quot;30080&quot;}<\/p>\n<pre><code class=\"language-json\">{\n    &quot;apiVersion&quot;: &quot;v1&quot;,\n    &quot;kind&quot;: &quot;Service&quot;,\n    &quot;metadata&quot;: {\n        &quot;annotations&quot;: {},\n        &quot;labels&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;name&quot;: &quot;nginx-service-1170&quot;,\n        &quot;namespace&quot;: &quot;appblog&quot;\n    },\n    &quot;spec&quot;: {\n        &quot;ports&quot;: [\n            {\n                &quot;nodePort&quot;: 30080,\n                &quot;port&quot;: 80\n            }\n        ],\n        &quot;selector&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;type&quot;: &quot;NodePort&quot;\n    }\n}<\/code><\/pre>\n<p>\u67e5\u8be2\u7ed3\u679c<\/p>\n<pre><code>[root@k8s-master ~]# kubectl get service -n appblog\nNAME                 TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE\nnginx-service-1170   NodePort   10.97.37.57   &lt;none&gt;        80:30080\/TCP   29s<\/code><\/pre>\n<h3>\u670d\u52a1\u6d4b\u8bd5<\/h3>\n<p>\u8bbf\u95ee<code>http:\/\/NodeIP:30080<\/code>\uff0c\u5176\u4e2dNodeIP\u53ef\u4ee5\u662f\u4efb\u610f\u4e00\u4e2a\u96c6\u7fa4\u8282\u70b9\u7684IP<\/p>\n<h3>\u67e5\u8be2Service<\/h3>\n<p><code>URL<\/code>: <a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/127.0.0.1:8080\/k8s\/readService?NamespaceName=appblog&amp;ServiceName=nginx-service-1170\">http:\/\/127.0.0.1:8080\/k8s\/readService?NamespaceName=appblog&#038;ServiceName=nginx-service-1170<\/a><\/p>\n<pre><code class=\"language-json\">{\n    &quot;apiVersion&quot;: &quot;v1&quot;,\n    &quot;kind&quot;: &quot;Service&quot;,\n    &quot;metadata&quot;: {\n        &quot;creationTimestamp&quot;: &quot;2019-06-14T14:31:06Z&quot;,\n        &quot;labels&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;name&quot;: &quot;nginx-service-1170&quot;,\n        &quot;namespace&quot;: &quot;appblog&quot;,\n        &quot;resourceVersion&quot;: &quot;355029&quot;,\n        &quot;selfLink&quot;: &quot;\/api\/v1\/namespaces\/appblog\/services\/nginx-service-1170&quot;,\n        &quot;uid&quot;: &quot;0b7ad5bf-8eb1-11e9-b4ff-525400a204f6&quot;\n    },\n    &quot;spec&quot;: {\n        &quot;clusterIP&quot;: &quot;10.97.37.57&quot;,\n        &quot;externalTrafficPolicy&quot;: &quot;Cluster&quot;,\n        &quot;ports&quot;: [\n            {\n                &quot;nodePort&quot;: 30080,\n                &quot;port&quot;: 80,\n                &quot;protocol&quot;: &quot;TCP&quot;,\n                &quot;targetPort&quot;: 80\n            }\n        ],\n        &quot;selector&quot;: {\n            &quot;name&quot;: &quot;nginx-1.17.0&quot;\n        },\n        &quot;sessionAffinity&quot;: &quot;None&quot;,\n        &quot;type&quot;: &quot;NodePort&quot;\n    },\n    &quot;status&quot;: {\n        &quot;loadBalancer&quot;: {}\n    }\n}<\/code><\/pre>\n<h3>\u5220\u9664RC\u53caService<\/h3>\n<p>\uff081\uff09\u5220\u9664RC<\/p>\n<p><code>DELETE<\/code>: <code>http:\/\/127.0.0.1:8080\/k8s\/deleteRC<\/code><br \/>\n<code>Content-Type<\/code>: <code>application\/x-www-form-urlencoded<\/code><br \/>\n<code>Body<\/code>: {&quot;NameSpaceName&quot;:&quot;appblog&quot;, &quot;ReplicationControllerName&quot;:&quot;nginx-rc-1.17.0&quot;}<\/p>\n<p>\uff082\uff09\u5220\u9664Service<\/p>\n<p><code>DELETE<\/code>: <code>http:\/\/127.0.0.1:8080\/k8s\/deleteService<\/code><br \/>\n<code>Content-Type<\/code>: <code>application\/x-www-form-urlencoded<\/code><br \/>\n<code>Body<\/code>: {&quot;NameSpaceName&quot;:&quot;appblog&quot;, &quot;ServiceName&quot;:&quot;nginx-service-1170&quot;}<\/p>\n<p>\u7ed3\u679c\u67e5\u8be2<\/p>\n<pre><code>[root@k8s-master ~]# kubectl get rc -n appblog\nNo resources found.\n[root@k8s-master ~]# kubectl get service -n appblog\nNo resources found.<\/code><\/pre>\n<p>\u4ee5\u4e0a\uff0c\u529f\u80fd\u6d4b\u8bd5\u5b8c\u6210\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6807\uff1a\u5b8c\u6210Service\u4e0eReplication Controller\u670d\u52a1\u57fa\u672c\u529f\u80fd(CRUD)\u7684\u5f00\u53d1\uff0c\u5e76\u4e14\u57fa\u4e8e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[356],"class_list":["post-1443","post","type-post","status-publish","format-standard","hentry","category-k8s","tag-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1443"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1443\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}