<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 使用 service 訪問群集中的應用程序 本文向您展示如何創建 Kubernetes Service 對象,外部客戶端可以使用它來訪問集群中運行的應用程序。該 Service 可以為具有兩個運行實例的應用程序提供負載均衡。 ## 目的 - 運行 Hello World 應用程序的兩個實例。 - 創建一個暴露 node 節點端口的 Service 對象。 - 使用 Service 對象訪問正在運行的應用程序。 ## 為在兩個 pod 中運行的應用程序創建 service 1. 在集群中運行 Hello World 應用程序: ```bash kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080 ``` 上述命令創建一個 [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment) 對象和一個相關聯的 [ReplicaSet](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset) 對象。該 ReplicaSet 有兩個 [Pod](https://kubernetes.io/docs/concepts/workloads/pods/pod),每個 Pod 中都運行一個 Hello World 應用程序。 2. 顯示關于該 Deployment 的信息: ```bash kubectl get deployments hello-world kubectl describe deployments hello-world ``` 3. 顯示 ReplicaSet 的信息: ``` kubectl get replicasets kubectl describe replicasets ``` 4. 創建一個暴露該 Deployment 的 Service 對象: ```Bash kubectl expose deployment hello-world --type=NodePort --name=example-service ``` 5. 顯示該 Service 的信息: ```bash kubectl describe services example-service ``` 輸出類似于: ``` Name: example-service Namespace: default Labels: run=load-balancer-example Selector: run=load-balancer-example Type: NodePort IP: 10.32.0.16 Port: <unset> 8080/TCP NodePort: <unset> 31496/TCP Endpoints: 10.200.1.4:8080,10.200.2.5:8080 Session Affinity: None No events. ``` 記下服務的 NodePort 值。例如,在前面的輸出中,NodePort 值為 31496。 6. 列出運行 Hello World 應用程序的 Pod: ```bash kubectl get pods --selector="run=load-balancer-example" --output=wide ``` 輸出類似于: ``` NAME READY STATUS ... IP NODE hello-world-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1 hello-world-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2 ``` 7. 獲取正在運行 Hello World 應用程序的 Pod 的其中一個節點的 public IP 地址。如何得到這個地址取決于您的集群設置。例如,如果您使用 Minikube,可以通過運行 `kubectl cluster-info` 查看節點地址。如果您是使用 Google Compute Engine 實例,可以使用 `gcloud compute instances list` 命令查看您的公共地址節點。 8. 在您選擇的節點上,在您的節點端口上例如創建允許 TCP 流量的防火墻規則,如果您的服務 NodePort 值為 31568,創建防火墻規則,允許端口 31568 上的TCP流量。 9. 使用節點地址和節點端口訪問 Hello World 應用程序: ```bash curl http://<public-node-ip>:<node-port> ``` 其中 `<public-node-ip>` 是您節點的 public IP地址,而 `<node-port>` 是您服務的 NodePort 值。 對成功請求的響應是一個 hello 消息: ``` Hello Kubernetes! ``` ## 使用 Service 配置文件 作為使用 `kubectl expose` 的替代方法,您可以使用 [service 配置文件](https://kubernetes.io/docs/user-guide/services/operations) 來創建 Service。 要刪除 Service,輸入以下命令: ``` kubectl delete services example-service ``` 刪除 Deployment、ReplicaSet 和正運行在 Pod 中的 Hello World 應用程序,輸入以下命令: ``` kubectl delete deployment hello-world ``` 了解更多關于 [使用 service 連接應用程序](https://kubernetes.io/docs/concepts/services-networking/connect-applications-service)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看