简体   繁体   中英

How to expose a Kubernetes service on AWS using `service.spec.externalIPs` and not `--type=LoadBalancer`?

I've deployed a Kubernetes cluster on AWS using kops and I'm able to expose my pods using a service with --type=LoadBalancer :

kubectl run sample-nginx --image=nginx --replicas=2 --port=80
kubectl expose deployment sample-nginx --port=80 --type=LoadBalancer

However, I cannot get it to work by specifying service.spec.externalIPs with the public IP of my master node.

I've allowed ingress traffic the specified port and used https://kubernetes.io/docs/concepts/services-networking/service/#external-ips as documentation.

Can anyone clarify how to expose a service on AWS without using the cloud provider's native load balancer?

If you want to avoid using Loadbalancer then you case use NodePort type of service.

NodePort exposes service on each Node's IP at a static port (the NodePort ). ClusterIP service that NodePort service routes is created along. You will be able to reach the NodePort service, from outside by requesting:

<NodeIP>:<NodePort> 

That means that if you access any node with that port you will be able to reach your service. It worth to remember that NodePorts are high-numbered ports (30 000 - 32767)

Coming back specifically to AWS here is theirs official document how to expose a services along with NodePort explained.

Do note very important inforamation there about enabling the ports:

Note: Before you access NodeIP:NodePort from an outside cluster, you must enable the security group of the nodes to allow incoming traffic through your service port.

Let me know if this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM