Тёмный

Flask Load Balancing Using Nginx and Docker 

DevGuyAhnaf
Подписаться 2,9 тыс.
Просмотров 33 тыс.
50% 1

In this video, I show you how you can scale your Flask applications with multiple application servers, and use Nginx to load balance it and distribute it's traffic. I will be using Docker for all of this as it is very easy to manage as well as scale.
😀SUBSCRIBE for more videos! / ahnafzamil
➤ My website: ahnafzamil.com
➤ My other YT: bit.ly/2RbkEBX
➤ My Discord Server: / discord
➤ My Twitter: / @ahnaf_zamil
➤ Support me on Patreon: / ahnafzamil
Links
=====
Flask Documentation: github.com/pallets/flask
Docker: www.docker.com/
Nginx: www.nginx.com/
Software Used
============
Recording: OBS Studio
Thumbnail: Adobe Photoshop CC
Editing: Adobe Premiere Pro CC
I Hope you enjoy this video, I am open to feedback. Please subscribe and like, it helps me out a lot!
Anyways, have a good day ^-^

Наука

Опубликовано:

 

9 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 71   
@jaeeboom
@jaeeboom Год назад
This is amazing! Loving all of your content!
@kingleo188
@kingleo188 Год назад
Yo man...This is like the best explanation I have seen in a while.....Great video...
@192255100
@192255100 4 месяца назад
So far the best explanation I have ever seen, thank you!
@amanand727
@amanand727 Год назад
Thanks for the tutorial, incredible content packed in such a short video.
@7franciscoramirez
@7franciscoramirez 7 месяцев назад
it's a really easy understand why need the nginx on multiplies contents, thanks a lot.
@mizzlehd8742
@mizzlehd8742 Год назад
First video that explained it well enough to actually make it work, thanks for the video!
@RomaniaPortamiVia
@RomaniaPortamiVia Год назад
Thank you , after two years since you made this tutorial it's stille correctly working .
@gray6275
@gray6275 9 месяцев назад
It's really easy to understand and it goes straight to the issue I'm researching Thanks for the tutorial!!!
@user-bp4lv6jx7b
@user-bp4lv6jx7b Год назад
Great vid, good content, clear and easy to understand !!
@ericdwkim
@ericdwkim 2 года назад
super helpful and learned a lot, thank you!
@mayconalvesdealmeida3747
@mayconalvesdealmeida3747 Год назад
Nice tutorial, very clearly and direct the point. Thanks for share
@nithinsamuel9995
@nithinsamuel9995 5 месяцев назад
very nice video clear and informative thanks for sharing
@sergey5561
@sergey5561 2 месяца назад
Incredible! Thank you so much!
@nathanlebgimstepf2907
@nathanlebgimstepf2907 5 месяцев назад
that was an incredible load of knowleadge thank you!
@KevinKoech357
@KevinKoech357 4 месяца назад
Nice tutorial. Lots of content. Appreciate your work.
@elad3958
@elad3958 Год назад
The best tutorial on this subject
@horacio_llegolamiel3758
@horacio_llegolamiel3758 10 месяцев назад
excellent video man, thanks!
@juanpedrososa1118
@juanpedrososa1118 2 года назад
Great tutorial, thanks for sharing
@selvakannan2548
@selvakannan2548 Год назад
Amazing content. Precise explanation. subbed
@devguyahnaf
@devguyahnaf Год назад
Thank you very much :D
@muchirajunior9751
@muchirajunior9751 2 года назад
a very great skill learn on load balancing. thanks
@fauzan.developer
@fauzan.developer 2 года назад
So Helpfull, thanks a lot. Pls create more devops things. :D
@HONjramiroz98
@HONjramiroz98 Год назад
Amazing video! subscribed
@devguyahnaf
@devguyahnaf Год назад
Thank you :)
@alaminbijoy1027
@alaminbijoy1027 Год назад
thank you man 😊
@walkdead94
@walkdead94 9 месяцев назад
Thanks!
@alimustafa2682
@alimustafa2682 2 года назад
Very Under-rated Video
@ultrakill5712
@ultrakill5712 2 года назад
Ty mate. Sadly i cant give you more likes. Cool explanation with nice english so i got ya even with my worst eng skill :D
@devguyahnaf
@devguyahnaf 2 года назад
Thanks a lot :D
@CASnumber
@CASnumber 9 месяцев назад
Very very good video
@Mostaqmahmud
@Mostaqmahmud Год назад
Super..!!!!
@krishnachaitanya4822
@krishnachaitanya4822 6 месяцев назад
Nice one, didn't know "scale" existed.
@clearthinking5441
@clearthinking5441 Год назад
Great video! Quick question, in this example the compute is distributed across three containers. However, in practice these containers will all be calling to a single database. How would load balancing help in that case since the compute would now be forwarded to the single DB instance? Would you also have to increase the number of DB instances?
@devguyahnaf
@devguyahnaf Год назад
Most DB instances can take up a lot of load since they were designed that way. But when you seriously need to scale up DB instances, I recommend you take a look at horizontal DB scaling patterns. The most common ones are data replication (for read-heavy use cases) with a DB load balancer, or cluster-based sharding.
@TheCodeHunter
@TheCodeHunter 3 года назад
nice
@Kennethlumor
@Kennethlumor 2 месяца назад
Thank you for sharing this knowledge with us. Please I want to ask the way you demonstrate this using this few example can you advance this tutorial by hosting this on pythonanywere where you can also set the load balancing over there.
@doronazulay903
@doronazulay903 Год назад
the nginx container dont show up on "docker ps" , you have any idea why?
@saketvempaty4312
@saketvempaty4312 Год назад
I've Done the exact same thing but I'm getting only a Welcome to Nginx page when i access localhost. Any ideas on resolving this?
@AishwariyaGupta
@AishwariyaGupta 5 месяцев назад
Hi, I am in Windows 10, I re-created all the steps, although I get this error: Error response from daemon: CreateFile mypath ginx.conf: Access is denied. Can you help me with this?
@kingleo188
@kingleo188 Год назад
please help @7:20, I get an error of unable to prepare context: path "context:app" not found.
@sahilgarg94
@sahilgarg94 2 месяца назад
Can we add different database as well with the application server for read write Operations.?
@SHAILESHBABU
@SHAILESHBABU 2 года назад
"(root) Additional property nginx is not allowed " can anyone help me resolve this error?
@ryanenoch4279
@ryanenoch4279 Год назад
Hi Ahnaf. I have a noob level question (Sorry in advance). You mentioned that Docker is LInux based. Is it basically some kind of an emulator to imitate a linux environment or is it something else??? Thanks in advance
@devguyahnaf
@devguyahnaf Год назад
No question is noob level, and you are always welcome to ask! Docker itself is just a software that allows you to containerize and isolate applications. That itself isn't a Linux emulator, but it USES a Linux emulator/system to function. Docker is Linux based, that means that on any other OS that's not Linux (for example Windows), you need something to emulate a Linux system in order for Docker to run. So on Windows, you can try using WSL as it will emulate a Linux system. On Linux, you don't need to emulate anything as Docker will use the system's kernel and stuff to function.
@elad3958
@elad3958 Год назад
what font are you using in this video
@thelinkguys2925
@thelinkguys2925 2 года назад
How would you do this without docker? Like multiple gunicorn running on diff ports. How would you configure that in nginx? Really good tutorial btw. First time i actually understand docker compose😂
@devguyahnaf
@devguyahnaf 2 года назад
Yes, run multiple unicorn instances on different ports, and then add each one's IP and port to upstream. For example, upstream gunicorn-servers { server 127.0.0.1:5000; server 127.0.0.1:5001; server 127.0.0.1:5002; } Now use that as your upstream for proxy-pass
@Mar-kb8yq
@Mar-kb8yq Год назад
Hi awesome video congratulation. Just a question, in this case you have created three container instance oon the same docker computer.. what about creating instance in differents computers ( servers ) and load balancing through them?
@devguyahnaf
@devguyahnaf Год назад
In that case, I would use a service registry since the containers would have dynamic port allocation. Reverse proxy can look up the IPs and ports of the container instances through the service registry and forward the request to those
@Mar-kb8yq
@Mar-kb8yq Год назад
@@devguyahnaf thank you, I just thought to create a nginx load balancer on another server and upstream connection to the server instances domains. What about that?
@devguyahnaf
@devguyahnaf Год назад
@@Mar-kb8yq If you can hardcode the upstream connection with domains and they are connectable through VPC, then yeah go ahead. I was just talking about autoscaling and why I would use a service registry
@Mar-kb8yq
@Mar-kb8yq Год назад
@@devguyahnaf Ah ok, I like autoscaling, but for now I never did it, or course in future I want to learn it 😅. Thank you very much again. I will subscribe to your channel.
@venkatasai8752
@venkatasai8752 Год назад
github link to this project?
@anjanikant4804
@anjanikant4804 2 года назад
Localhost showing the site can't be reached. Can you help with this issue ?
@devguyahnaf
@devguyahnaf 2 года назад
I have corrected a mistake in the flask part. Use `app.run(host="0.0.0.0", debug=True)`. The host="0.0.0.0" is important
@PeterStankiewicz
@PeterStankiewicz Год назад
@@devguyahnaf Thanks a lot for that correction, Ahnaf! It finally works!
@PHOENIX-he9fl
@PHOENIX-he9fl 2 года назад
Bro can u help me: Either does not exit,is not accessible,or is not a valid URL This is my problem for running "docker-compose up"
@kingleo188
@kingleo188 Год назад
same here, "unable to prepare context: path "context:app" not found.
@kingleo188
@kingleo188 Год назад
Hi Phoenix, Seems I have figured out the issue, basically this means it cant find the Dockerfile....So I just replaced the word app with a period(.) . Essentially it just needs to be told where to find the Dockerfile, So with the (.) added, It looks in the CWD and then it runs successfully. So it should read context: .
@AishwariyaGupta
@AishwariyaGupta 5 месяцев назад
what did you do? I did not get you :( @@kingleo188
@KKOO8
@KKOO8 3 года назад
I see
@spiffjekey-green4034
@spiffjekey-green4034 2 года назад
I don’t see how you created multiple instances of the flask app
@devguyahnaf
@devguyahnaf 2 года назад
It's the docker compose up command docker-compose up -d --scale service_name=5
@calvinwong8569
@calvinwong8569 2 года назад
what do you mean by typo cccccc ?
@devguyahnaf
@devguyahnaf 2 года назад
Typo means typing mistake
@calvinwong8569
@calvinwong8569 2 года назад
@@devguyahnaf i got an issue regarding my nginx container wont build but the 3 app is builded any idea ?
@calvinwong8569
@calvinwong8569 2 года назад
i mean its created but keep exited
@rinket7779
@rinket7779 10 месяцев назад
Wait how does this load balancing even work? Why doesn’t it require an upstream group? How does nginx know to switch between each app ? What load balancing algorithm does it use? Round robin? Least connections? So many questions, I wish you had gone more into depth about wtf is actually going on here, is this some docker magic? Or it’s a feature of nginx itself? So confusing
@devguyahnaf
@devguyahnaf 10 месяцев назад
This deployment method isn't good for high scale production, something like a cloud container service with a managed load balancer or some kind of cluster L7 ingress would be better. This is just a way to quickly set up load balancing with docker compose for those who need it done fast and dirty. Primarily, the load balancing is round robin as far as I know. The upstream group has IP addresses which are provided by Docker compose during container build, as the containers' internal IPs are dynamic. And yes, there's some Docker magic going on here. It's also why I didn't go too deep into it, as a lot of stuff is managed by Docker's internal hostname providers and such. This isn't the optimised or recommended way of deploying it to prod, it's just a simple way for small setups with multiple containers. I don't really remember the specifics of this video at the moment, but do follow up with replies if you have any questions and my answer doesn't satisfy you.
@rinket7779
@rinket7779 10 месяцев назад
@devguyahnaf maybe it's using dns based load balancing? I notice you just put "app" and it's able to load balance with just that, probably cos "app" returns a different ip each time?
@devguyahnaf
@devguyahnaf 10 месяцев назад
@@rinket7779 You're probably right, I've just taken a look and Docker does some of that networking which includes hostname resolving, which implies that it's DNS based load balancing.
Далее
Deploy Flask Application on Ubuntu VPS using Nginx
16:19
How to Measure ANY Cliffs Height with a Rock
00:46
Просмотров 3,6 млн
FastAPI, Flask or Django - Which Should You Use?
9:49
Load Balancing with NGINX
30:03
Просмотров 62 тыс.
Здесь упор в процессор
18:02
Просмотров 362 тыс.
Aura 879dsp новинка и хит
0:48
Просмотров 79 тыс.
Собери ПК и Получи 10,000₽
1:00
Просмотров 2,7 млн