2

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:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  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:                   <none>

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!

  • Can you ssh to your ec2 and do curl on port 30001 from there, does it work? – taleodor Mar 21 at 14:47
1

More often than not you should not be using NodePort.

You're in AWS so you can consume the AWS Cloud Provider. 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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.