使用 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,单节点设置。但是如何访问我的 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
我没有看到外部 IP。
例如,如果我将 NodePort
更改为 LoadBalancer
,我将获得一个外部 IP,并且可以访问我的网站,但是如何使用 NodePort 执行此操作?
您可以通过从 kubernetes 查询节点来获取您节点的 IP api:
kubectl get nodes -o wide
它将打印每个节点的IP。
由于一个NodePort是暴露在所有节点上的,所以你可以使用任何节点来访问该服务。
据我所知,AKS 是一项托管服务,它只公开同样由 Azure 管理的 master 来控制所有操作。从节点不暴露,默认没有外网IP
在 AKS 集群中,您只能通过带有负载均衡器的服务或入口(其服务也使用负载均衡器)访问应用程序。
如果你真的想为你的服务使用节点类型,也有办法解决。您可以手动创建 public 个 IP,并将它们关联到您要创建节点类型服务的节点。然后节点具有外部 IP。但不建议对 AKS Iaas 进行所有操作。因此,如果您想从 Internet 访问服务,负载均衡器类型是最合适的方式。
我是 运行 一个 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,单节点设置。但是如何访问我的 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
我没有看到外部 IP。
例如,如果我将 NodePort
更改为 LoadBalancer
,我将获得一个外部 IP,并且可以访问我的网站,但是如何使用 NodePort 执行此操作?
您可以通过从 kubernetes 查询节点来获取您节点的 IP api:
kubectl get nodes -o wide
它将打印每个节点的IP。 由于一个NodePort是暴露在所有节点上的,所以你可以使用任何节点来访问该服务。
据我所知,AKS 是一项托管服务,它只公开同样由 Azure 管理的 master 来控制所有操作。从节点不暴露,默认没有外网IP
在 AKS 集群中,您只能通过带有负载均衡器的服务或入口(其服务也使用负载均衡器)访问应用程序。
如果你真的想为你的服务使用节点类型,也有办法解决。您可以手动创建 public 个 IP,并将它们关联到您要创建节点类型服务的节点。然后节点具有外部 IP。但不建议对 AKS Iaas 进行所有操作。因此,如果您想从 Internet 访问服务,负载均衡器类型是最合适的方式。