如何使用kubernetes NodePort从外部访问服务? [英] How do I externally access a service with kubernetes NodePort?
问题描述
我已经使用以下配置设置了NodePort服务:
I've setup a NodePort service using the following config:
wordpress-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: wordpress
name: wordpress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: wordpress
这足以从外部访问该服务,如果可以的话,现在如何访问该服务?我需要什么细节-以及如何确定它们-例如节点IP.
Is this sufficient to access the service externally, if so how can I now access the service? What details do I need - and how do I determine them - for example node IP.
推荐答案
在将服务定义为类型NodeIP
时,群集中的每个节点会将该端口代理到您的服务.如果您可以从Kubernetes集群外部访问节点,则应该可以通过nodeIP:nodePort
访问该服务.
When you define a service as type NodeIP
, every node in your cluster will proxy that port to your service. If you nodes are reachable from outside the Kubernetes cluster, you should be able to access the service at nodeIP:nodePort
.
要确定特定节点的nodeIP
,可以使用kubectl get no <node> -o yaml
或kubectl describe no <node>
. status.Addresses
字段将引起关注.通常,您会在其中看到HostName
,ExternalIP
和InternalIP
之类的字段.
To determine nodeIP
of a particular node, you can use either kubectl get no <node> -o yaml
or kubectl describe no <node>
. The status.Addresses
field will be of interest. Generally, you will see fields like HostName
, ExternalIP
and InternalIP
there.
要确定服务的nodePort
,可以使用kubectl get svc wordpress -o yaml
或kubectl describe svc wordpress
. spec.ports.nodePort
是您需要的端口.
To determine nodePort
of your service, you can use either kubectl get svc wordpress -o yaml
or kubectl describe svc wordpress
. The spec.ports.nodePort
is the port you need.
这篇关于如何使用kubernetes NodePort从外部访问服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!