[英]access azure kubernetes cluster using a NodePort
I'm running a pod (website) and a simple service 我正在运行一个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>
Because this service is of type NodePort
it opens a port on each cluster node. 由于此服务的类型为
NodePort
因此它将在每个群集节点上打开一个端口。 In my case I'm running kubernetes in Azure, single node setup. 就我而言,我正在Azure中运行kubernetes(单节点设置)。 But how do I access my service/website?
但是,如何访问我的服务/网站?
$> 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
I don't see an external IP. 我没有看到外部IP。
For example, if I change NodePort
to LoadBalancer
I get an external IP and I can access my website, but how can I do this with NodePort? 例如,如果我将
NodePort
更改为LoadBalancer
,则可以获得外部IP,并且可以访问我的网站,但是如何使用NodePort做到这一点?
As far as I know, the AKS is a managed service and it just exposes the master which is also managed by Azure to control all the actions. 据我所知,AKS是一项托管服务,它只公开由Azure管理的主服务器来控制所有操作。 The slave nodes do not expose and do not have the external IP in default.
从属节点不公开,默认情况下没有外部IP。
In the AKS cluster, you only can access the applications through the service with a load balancer or the ingress(which also uses the load balancer for its service). 在AKS群集中,您只能使用负载均衡器或入口(也将负载均衡器用于其服务)通过服务访问应用程序。
If you really want to use the node type for your service, there is also a way to solve it. 如果您确实想为服务使用节点类型,则还有一种解决方法。 You can create public IPs manually and associate them to the nodes that you want to create the services with node type.
您可以手动创建公共IP,并将其与要使用节点类型创建服务的节点相关联。 Then the nodes have the external IPs.
然后,节点具有外部IP。 But all operations for AKS Iaas are not recommended.
但是不建议对AKS Iaas进行所有操作。 So the load balancer type is the most appropriate way for the service if you want to access them from the Internet.
因此,如果您想从Internet访问负载平衡器类型,则是最适合该服务的方式。
You can get the IP of you nodes by querying the nodes from the kubernetes api: 您可以通过kubernetes api查询节点来获取节点的IP:
kubectl get nodes -o wide
It will print the IP of each node. 它将打印每个节点的IP。 Since a NodePort is exposed on all nodes, you can use any node to access the service.
由于NodePort在所有节点上均公开,因此您可以使用任何节点来访问服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.