简体   繁体   English

NodePort 是否适用于 Azure 容器服务 (Kubernetes)

[英]Does NodePort work on Azure Container Service (Kubernetes)

I have got the following service for Kubernetes dashboard我为 Kubernetes 仪表板提供了以下服务

Name:               kubernetes-dashboard
Namespace:          kube-system
Labels:             k8s-app=kubernetes-dashboard
                    kubernetes.io/cluster-service=true
Annotations:        kubectl.kubernetes.io/last-applied-configuration={"kind":"Service","apiVersion":"v1","metadata":{"name":"kubernetes-dashboard","namespace":"kube-system","creationTimestamp":null,"labels":{"k8s-app":"k...
Selector:           k8s-app=kubernetes-dashboard
Type:               NodePort
IP:                 10.0.106.144
Port:               <unset> 80/TCP
NodePort:           <unset> 30177/TCP
Endpoints:          10.244.0.11:9090
Session Affinity:   None
Events:             <none>

According to the documentation , I ran根据文档,我跑了

az acs kubernetes browse

and it works on http://localhost:8001/ui它适用于http://localhost:8001/ui

But I want to access it outside the cluster too.但我也想在集群外访问它。 The describe output says that it is exposed using NodePort on port 30177.描述输出表明它是在端口 30177 上使用 NodePort 公开的。

But I'm not able to access it on http://<any node IP>:30177但我无法在http://<any node IP>:30177上访问它

As we know, expose the service to internet, we can use nodeport and LoadBalancer .众所周知,将服务暴露给互联网,我们可以使用nodeportLoadBalancer

As far as I know, Azure does not support nodeport type now.据我所知,Azure 现在支持 nodeport 类型。

But I want to access it outside the cluster too.但我也想在集群外访问它。

we can use LoadBalancer to re-create the kubernetes dashboard, here are my steps:我们可以使用LoadBalancer重新创建 kubernetes 仪表板,这是我的步骤:

  1. Delete kubernetes-dashboard via kubernetes UI: select Namespace to kube-system , then select services , then delete it:通过 kubernetes UI删除kubernetes-dashboard:选择Namespace to kube-system ,然后选择services ,然后删除它: 在此处输入图片说明 在此处输入图片说明

  2. Modify Kubernetes-dashboard-service.yaml: SSH master VM, then change type from nodeport to LoadBalancer :修改 Kubernetes-dashboard-service.yaml: SSH master VM,然后type 从 nodeport更改LoadBalancer

    root@k8s-master-47CAB7F6-0:/etc/kubernetes/addons# vi kubernetes-dashboard-service.yaml root@k8s-master-47CAB7F6-0:/etc/kubernetes/addons# vi kubernetes-dashboard-service.yaml

     apiVersion: v1 kind: Service metadata: labels: kubernetes.io/cluster-service: "true" k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: ports: - port: 80 targetPort: 9090 selector: k8s-app: kubernetes-dashboard type: LoadBalancer
  3. start kubernetes browse from CLI 2.0:从 CLI 2.0启动kubernetes 浏览:

    C:\\Users> az acs kubernetes browse -g k8s -n containerservice-k8s C:\\Users> az acs kubernetes browse -g k8s -n containerservice-k8s

Then SSH to master VM to check the status :然后通过 SSH 连接到主 VM 以检查状态 在此处输入图片说明

Now, we can via the Public IP address to browse the UI:现在,我们可以通过公共 IP 地址来浏览 UI:

在此处输入图片说明 Update :更新
The following image shows the architecture of azure container service cluster(Kubernetes), we should use Load-Balancer to expose the service to internet.下图显示了 azure 容器服务集群(Kubernetes)的架构,我们应该使用 Load-Balancer 将服务暴露给互联网。

在此处输入图片说明

On second thought, this actually is expected to NOT work.再想一想,这实际上是行不通的。 The only public IP in the cluster, by default, is for the load balancer on the masters.默认情况下,集群中唯一的公共 IP 用于主服务器上的负载均衡器。 And that load balancer obviously is not configured to forward random ports (like 30000-32767 for example).并且该负载均衡器显然没有配置为转发随机端口(例如 30000-32767)。 Further, none of the nodes directly have a public IP, so by definition NodePort is not going to work external to the cluster.此外,没有一个节点直接拥有公共 IP,因此根据定义,NodePort 不会在集群外部工作。

The only way you're going to make this work is by giving the nodes public IP addresses directly.您要完成这项工作的唯一方法是直接为节点提供公共 IP 地址。 This is not encouraged for a variety of reasons.出于各种原因,不鼓励这样做。

If you merely want to avoid waiting... then I suggest:如果你只是想避免等待......那么我建议:

  1. Don't delete the Service.不要删除服务。 Most dev scenarios should just be kubectl apply -f <directory> in which case you don't really need to wait for the Service to re-provision大多数开发场景应该只是kubectl apply -f <directory>在这种情况下你真的不需要等待服务重新配置

  2. Use Ingress along with 'nginx-ingress-controller' so that you only need to wait for the full LB+NSG+PublicIP provisioning once, and then can just add/remove Ingress objects in your dev scenario.将 Ingress 与 'nginx-ingress-controller' 一起使用,这样您只需等待一次完整的 LB+NSG+PublicIP 配置,然后就可以在您的开发场景中添加/删除 Ingress 对象。

  3. Use minikube for development scenarios, or manually add public ips to the nodes to make the NodePort scenario work.开发场景使用minikube,或者手动给节点添加公网ip,让NodePort场景工作。

You can't expose the service via nodeport by running the kubectl expose command, you get a VIP address outside the range of the subnets your cluster sits on... Instead, deploy a service through a yaml file and you can specify an internal load balancer as a type..., which will give you a local IP on the Master subnet, which you can connect to via the internal network...您无法通过运行 kubectl Expose 命令通过 nodeport 公开服务,您会获得集群所在子网范围之外的 VIP 地址...相反,通过 yaml 文件部署服务,您可以指定内部负载平衡器作为一种类型...,它将为您提供主子网上的本地 IP,您可以通过内部网络连接到该 IP...

Or, you can just expose the service with an external load balancer and get a public ip.或者,您可以使用外部负载均衡器公开服务并获得公共 IP。 available on the www.可在 www.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM