I have following service configuration:
kind: Service
apiVersion: v1
metadata:
name: web-srv
spec:
type: NodePort
selector:
app: userapp
tier: web
ports:
- protocol: TCP
port: 8090
targetPort: 80
nodePort: 31000
and an nginx container is behind this service. Although I can access to the service via nodePort
, service is not accessible via port
field. I'm able to see the configs with kubectl
and Kubernetes dashboard but curl
ing to that port (e.g. curl http://192.168.0.100:8090
) raises a Connection Refused error.
I'm not sure what is the problem here. Do I need to make sure any proxy services is running inside the Node or Container?
If you nodes are reachable from outside the Kubernetes cluster, you should be able to access the service at nodeIP:nodePort . To determine nodeIP of a particular node, you can use either kubectl get no <node> -o yaml or kubectl describe no <node> . The status.
NodePorts and external IPs are independent and both can be used concurrently.
To use a NodePort, In the configuration file for your app, define a service section. For the Guestbook example, a front-end service section exists in the configuration file. To make the Guestbook app available externally, add the NodePort type and a NodePort in the range 30000 - 32767 to the front-end service section.
Get the IP of the kubernetes service and then hit 8090; it will work. nodePort implies that the service is bound to the node at port 31000.
These are the 3 things that will work:
curl <node-ip>:<node-port> # curl <node-ip>:31000
curl <service-ip>:<service-port> # curl <svc-ip>:8090
curl <pod-ip>:<target-port> # curl <pod-ip>:80
So now, let's look at 3 situations:
1. You are inside the kubernetes cluster (you are a pod)
<service-ip>
and <pod-ip>
and <node-ip>
will work.
2. You are on the node
<service-ip>
and <pod-ip>
and <node-ip>
will work.
3. You are outside the node
Only <node-ip>
will work assuming that <node-ip>
is reachable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With