【发布时间】:2019-07-25 12:12:27
【问题描述】:
我正在运行一个 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 来做到这一点?
【问题讨论】:
标签: azure kubernetes azure-aks