Full Stack Deployment in Kubernetes
This document is a guide for my learning to deploy an angular app connecting to a set of dotnet core microservice for authentication and other services.
Prologue: If knowledge = money, I belong to the middle class, this guide is to be a mirror for my own progress toward digital transformation and sharing it, so others can become my friends.
Flashback: I ended up using k8s after trying different platforms and tried to build a local environment for delivering my ideas in no time. While attempting it on my laptop with win.10 having 8GB RAM and reasonable HDD space I installed VirtaulBox and Vagrant following Just me and Opensource channel.
Present: I was so excited to learn all the tools that could be tried out in K8s like Istio, Traefik etc. All of a sudden the system started to slow down and came to know about k3s, k3d from the video here. Civo service with k3s is mind blowing to me, I don’t have to take care of the infrastructure complexity anymore. Following the learn guide here, I did some of the experiments in CIVO, is to install a docker dotnet core web api using faas cli docker image, also trying to push a full stack app using Angular+ .net core + mongodb. I am a web application developer trying to be a data scientist by 2025. I don’t know whether its ambitious but I want to try. On its way, trying to experiment and create an eco system in CIVO with all the tools for my ideas having microservices, web apps, machine learning models. I hope one day I will be proud to run a production ready idea, that has revolutionized the world :-). I will create a series of blog post having most of the commands and whether its failure or success.
-
DotCore
-
Angular
-
MongoDB
-
Python
-
Java Spring Boot
Design:
Prerequisites:
-
Use WSL in windows
-
Install Docker, Windows Terminal
-
Use VS Code with Dotnet Core and Angular framework essentials
-
Remove <TAG> with you Docker ID
-
Remove <PROJECT> with your Project Name
I followed the instructions here, following are the commands used:
NOTE: Don’t forget to change the local path “K:\Kubernetes\ubuntu-wsl\Docker\wsl\data” which refers to my local path
[WSL2 install & update]
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
[Install docker desktop and enable WSL]
wsl –list -v
wsl –export docker-desktop-data ”K:\Kubernetes\ubuntu-wsl\Docker\wsl\docker-desktop-data.tar”
wsl –unregister docker-desktop-data
wsl –import docker-desktop-data ”K:\Kubernetes\ubuntu-wsl\Docker\wsl\data” ”K:\Kubernetes\ubuntu-wsl\Docker\wsl\docker-desktop-data.tar” –version 2
Docker Setting > Enable “use the WSL 2 based engine”
Civo Setup
-
Get the command line for Civo cluster, you can create a civo cluster, follow the instructions here.
-
Get Kubectl installed and working
civo kubernetes ls
civo kubernetes config <PROJECT> -infra –save –merge
kubectl config get-contexts
kubectl config set-context <PROJECT> -infra
kubectl config use-context <PROJECT> -infra
Development:
-
VS Code
-
Dotnet Core
[Setup identity server]
>npm i oidc-client
>ng new angular-client
>dotnet new webapi
>dotnet new -i IdentityServer4.Templates
>mkdir PROJECT-idserver
>cd .\ PROJECT-idserver\
>dotnet new is4ef
>dotnet new is4inmem
- Dockerization
docker run –rm -d -p 27017:27017 -v /civolab/lab/kitchen:/data/db mongo
- Managing Secrets
kubectl delete secret secret-idserver-appsettings -n openfaas-fn
kubectl create secret generic secret-idserver-appsettings –from-file=secret-appsettings=appsettings.secrets.json -n openfaas-fn
Deployment:
- Docker Build:
docker build . -f Dockerfile -t PROJECT-web:local
docker tag kitchen-web:local <tag>/ <PROJECT>-web:v.0.2
docker push <TAG>/ PROJECT-web:v.0.2
- Open Faas Setup & Deploy
# Setup OpenFaas
curl -sLSf https://cli.openfaas.com | sudo sh |
export OPENFAAS_PREFIX=”<tag>/”
export DNS=”<YOUR_CIVO_CLUSTER_ID>.k8s.civo.com” # As per dashboard
export OPENFAAS_URL=http://$DNS:31112
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath=”{.data.basic-auth-password}” | base64 –decode; echo) |
echo -n $PASSWORD | faas-cli login –username admin –password-stdin |
faas-cli new –lang dockerfile api
faas-cli build
faas-cli push -f stack.yml # Contains all the image deployment
faas-cli deploy -f stack.idserver.yml # individual deployment
faas-cli deploy -f stack.web.yml
helm upgrade –install <PROJECT>-frontend /<PROJECT>-web/conf/charts/<PROJECT>-ui –namespace PROJECT –set app.image=<TAG>/<PROJECT>-web:latest
helm uninstall <PROJECT>-frontend -n <PROJECT>
Testing & Monitoring:
https://www.civo.com/learn/monitoring-k3s-with-the-prometheus-operator-and-custom-email-alerts
docker run –rm -p 5000:8080 -ti -e ASPNETCORE_ENVIRONMENT=Development kitchen-idserver:local
kubectl get all -o wide -n kitchen
kubectl get all -o wide -n openfaas-fn
kubectl port-forward svc/prometheus-operator-grafana 8080:80 -n monitoring
kubectl port-forward svc/prometheus-operator-operator 8082:8080 -n monitoring
kubectl port-forward svc/prometheus-operator-alertmanager 9093 -n monitoring
Get into the pod running in the cluster and verify the files.
kubectl exec –stdin –tty <podname> -n openfaas-fn – sh
Challenges & Solutions:
-
Setting up local system – ( 8GB RAM)
-
Dotnet Core
-
Angular
-
IdentityServer setup
- I am trying to deploy a dotnet core identityserver4 into my cluster using openfaas. When my angular client hit the pod for authentication the url resolves to mysever.openfass-fn.svc.cluster.local:8080 instead of the external url. Any idea?
-
Microservice Architecture
-
Ployglot implementation