<p>More often than not you should not be using NodePort.</p>

<p>You're in AWS so you can consume the <a href="https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/#aws" rel="nofollow noreferrer">AWS Cloud Provider</a>. Try using <code>ingress</code> resources or <code>LoadBalancer</code> service types. NLBs can do TCP/UDP port passthrough if that's what you need.</p>

<p><strong>Edit:</strong> After further review, it looks like your just exposing a web server (I noted port <code>8080</code>). <code>NodePort</code> is 100% not what you want. Look at <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress</a></p>

CC BY-SA 4.0
2020-03-22T16:52:42.080Z
2020-03-22T16:52:42.080Z
thisguy123
<p>I have created a cluster on AWS EC2 using <code>kops</code> consisting of a master node and two worker nodes, all with public IPv4 assigned.</p>

<p>Now, I want to create a deployment with a service using NodePort to expose the application to the public.</p>

<p>After having created the service, I retrieve the following information, showing that it correctly identified my three pods:</p>

<pre><code>nlykkei:~/projects/k8s-examples$ kubectl describe svc hello-svc
Name:                     hello-svc
Namespace:                default
Labels:                   app=hello
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hello"},"name":"hello-svc","namespace":"default"},"spec"...
Selector:                 app=hello-world
Type:                     NodePort
IP:                       100.69.62.27
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  30001/TCP
Endpoints:                100.96.1.5:8080,100.96.2.3:8080,100.96.2.4:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>However, when I try to visit any of my public IPv4's on port 30001, I get no response from the server. I have already created a Security Group allowing all ingress traffic to port 30001 for all of the instances.</p>

<p>Everything works with Docker Desktop for Mac, and here I notice the following service field not present in the output above:</p>

<pre><code>LoadBalancer Ingress:     localhost
</code></pre>

<p>I've already studied <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a>, and think that NodePort should serve my needs?</p>

<p>Any help is appreciated!</p>

CC BY-SA 4.0
2020-03-21T14:47:28.493Z
Can you ssh to your ec2 and do curl on port 30001 from there, does it work?
taleodor
<docker><amazon-web-services><kubernetes>
How to deploy a Kubernetes service using NodePort on AWS?
Shuzheng
# How to deploy a Kubernetes service using NodePort on AWS?

(Asked by: username_0 on 2020-03-19)

I have created a cluster on AWS EC2 using kops consisting of a master node and two worker nodes, all with public IPv4 assigned.
Now, I want to create a deployment with a service using NodePort to expose the application to the public.
After having created the service, I retrieve the following information, showing that it correctly identified my three pods:
nlykkei:~/projects/k8s-examples$ kubectl describe svc hello-svc
Name:                     hello-svc
Namespace:                default
Labels:                   app=hello
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hello"},"name":"hello-svc","namespace":"default"},"spec"...
Selector:                 app=hello-world
Type:                     NodePort
IP:                       100.69.62.27
Port:                       8080/TCP
TargetPort:               8080/TCP
NodePort:                   30001/TCP
Endpoints:                100.96.1.5:8080,100.96.2.3:8080,100.96.2.4:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   

However, when I try to visit any of my public IPv4's on port 30001, I get no response from the server. I have already created a Security Group allowing all ingress traffic to port 30001 for all of the instances.
Everything works with Docker Desktop for Mac, and here I notice the following service field not present in the output above:
LoadBalancer Ingress:     localhost

I've already studied https://kubernetes.io/docs/concepts/services-networking/service/, and think that NodePort should serve my needs?
Any help is appreciated!

**Tags:** docker, amazon-web-services, kubernetes

> **Comments:**
> **username_1**: Can you ssh to your ec2 and do curl on port 30001 from there, does it work?  

---

## 1 answers

### Answer by username_2 on 2020-03-22. Score: 1

More often than not you should not be using NodePort.

You're in AWS so you can consume the [AWS Cloud Provider](https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/#aws). Try using `ingress` resources or `LoadBalancer` service types. NLBs can do TCP/UDP port passthrough if that's what you need.

**Edit:** After further review, it looks like your just exposing a web server (I noted port `8080`). `NodePort` is 100% not what you want. Look at [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/)


---

