/Workshops.Containers

Tutorial and samples for learning and teaching Docker and Kubernetes. Oh it's old now and from a beginners perspective.

Primary LanguageC#

About

Let's experiment with a multicontainer application for Docker, using Docker Compose. Or - use Kubernetes with Minikube. Guides provided for both.

First, follow this guide to set up docker & kubernetes locally with minikube.

Then go the next parts of the tutorial:

Building ASP.NET Core on Containers (Docker and Kubernetes)

Nginx is the chosen loadbalancer/proxy and it will proxy incoming user web requests to a web (or directly to the api). The web in turn, needs to talk to the api. It goes through Nginx to reach that Api. It looks for an environment variable to know wich one, but can respond anyway.

  • Frontend LB: Nginx. (image nginx which is based on busybox) for local dev, but for the real production cluster we're gonna use nginx ingress.

  • Frontend Web: aspnetcore mvc web app (talks to the backend thru the frontend lb)

  • Backend Api: aspnetcore api web app (we're not going to focus much on this)

  • The web and api docker builds:

    • Using a linux image (alpine) with .net core sdk to build the app
    • Using another linux image (alpine) with .net core runtime to run the app
  • The front load balancer

    • Using nginx (from image Busybox I think)

See the installation steps below, or jump into the startup sections below if you got that covered already.

Requirements

  • Windows 10 Professional
  • Virtualization=Enabled in your BIOS (UPDATE 2021: Use WSL2 for Docker Desktop instead!)
  • Hyper-V installed
  • Choco (go to chocolatey.org and download it)

Installation

Install Docker Desktop for Windows

  • I prefer not using choco for this
  • Go to https://hub.docker.com/editions/community/docker-ce-desktop-windows
  • Create an account and install docker desktop CE edition, for windows
  • Login both from the tray icon and in your shell environment
  • Try docker run hello-world and make sure you get some output
  • It should work, otherwise fix all problems

Startup

Startup - The .NET project locally

First, clone this repo. Then run the web and see that it starts up. Then, startup the api, see the api url and change the url in the web project to this. Refresh web and see that it works.

Startup - Docker build & run

  • Just go to the folder of the appl you want and call build.bat and run.bat
  • You can run the NginX container but it wont do anything since it has nothing to route the requests to

Startup - Docker compose

  • Since this is really a multicontainer setup, docker-compose is best.
    • docker-compose up --build
  • Then go to: http://localhost:8080 for the frontend lb routing to the web
  • Then go to: http://localhost:5000 for the backend api without going through frontend lb
  • Then go to: http://localhost:3000 for the front web without going through frontend lb, however it will fetch values thru front lb
  • You can also run the containers individually with their respective build.bat and run.bat files. Except nginx because it doesn't reach to outside it's container(s). Dunno how to fix.

Resources

Reading

TODO

  • Try NLog to get more meaningful logs to EFK-stack
  • With Docker: Make the API work with Redis and MySql
  • Then the same with k8s
  • Expose Grafana and Kibana somehow