簡體   English   中英

使用NodePort訪問Azure Kubernetes集群

[英]access azure kubernetes cluster using a NodePort

我正在運行一個pod(網站)和一個簡單的服務

apiVersion: v1
kind: Service
metadata:
  name: ui
spec:
  type: NodePort
  selector:
    app: ui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 3000

$> kubectl get services
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE   SELECTOR   LABELS
kubernetes   ClusterIP   10.0.0.1      <none>        443/TCP        83m   <none>     component=apiserver,provider=kubernetes
ui           NodePort    10.0.25.205   <none>        80:30180/TCP   53m   app=ui     <none>

由於此服務的類型為NodePort因此它將在每個群集節點上打開一個端口。 就我而言,我正在Azure中運行kubernetes(單節點設置)。 但是,如何訪問我的服務/網站?

$> kubectl describe service ui
Name:                     ui
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata": {"annotations":{},"name":"ui","namespace":"default"},"spec":{"ports":[{"port":80,"protocol"...
Selector:                 app=ui
Type:                     NodePort
IP:                       10.0.25.205
Port:                     <unset>  80/TCP
TargetPort:               3000/TCP
NodePort:                 <unset>  30180/TCP
Endpoints:                10.244.0.14:3000,10.244.0.15:3000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  Type                  29m   service-controller  NodePort -> LoadBalancer
  Normal  EnsuringLoadBalancer  29m   service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   27m   service-controller  Ensured load balancer
  Normal  Type                  10m   service-controller  LoadBalancer -> NodePort
  Normal  DeletingLoadBalancer  10m   service-controller  Deleting load balancer
  Normal  DeletedLoadBalancer   9m5s  service-controller  Deleted load balancer

我沒有看到外部IP。

例如,如果我將NodePort更改為LoadBalancer ,則可以獲得外部IP,並且可以訪問我的網站,但是如何使用NodePort做到這一點?

據我所知,AKS是一項托管服務,它只公開由Azure管理的主服務器來控制所有操作。 從屬節點不公開,默認情況下沒有外部IP。

在AKS群集中,您只能使用負載均衡器或入口(也將負載均衡器用於其服務)通過服務訪問應用程序。

如果您確實想為服務使用節點類型,則還有一種解決方法。 您可以手動創建公共IP,並將其與要使用節點類型創建服務的節點相關聯。 然后,節點具有外部IP。 但是不建議對AKS Iaas進行所有操作。 因此,如果您想從Internet訪問負載平衡器類型,則是最適合該服務的方式。

您可以通過kubernetes api查詢節點來獲取節點的IP:

kubectl get nodes -o wide

它將打印每個節點的IP。 由於NodePort在所有節點上均公開,因此您可以使用任何節點來訪問服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM