<p>I was going through Docker and Kubernetes . I want to create two Python web servers and need to access them using public URL and these requests should be balanced between two servers.</p>

<p>I created one Python server and initially deployed that with Docker containers and all this I'm doing using AWS ec2 instance so when I tried to send a request I used ec2publicip:port. This is working which means I created one web server and similarly I will do the same for the second server.</p>

<p>My question is If I deploy this with Kubernetes - Is there any way to do load balancing the Python web servers within the pod. If so, can someone tell me how to do this?</p>

HARINI NATHAN
<p>If you create two replicas of the pod via a kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">deployment</a> and create a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a> of type <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a> an ELB on AWS is automatically provisioned.Then whenever a request comes to the ELB on AWS it will distribute the traffic to the replicas of the pod. With a loadbalancer type service you get advanced load balancing capabilities at layer 7. Without a loadbalancer type service or an ingress you get round robin load balancing at layer 4 offered by kube proxy.</p>

<p>Problem with loadbalancer type service is that it will create new ELB for each service which is costly. So I recommend using ingress controller such as <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">Nginx</a> and expose the Nginx Ingress controller via a single <a href="https://github.com/kubernetes/ingress-nginx/tree/master/deploy/static/provider/cloud" rel="nofollow noreferrer">loadbalancer</a> on AWS. Then create <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#the-ingress-resource" rel="nofollow noreferrer">ingress resource</a> and use path or host based routing to send traffic to pods behind a clusterIP type service.</p>
