Skip to content
Alok Singh edited this page Apr 7, 2023 · 1 revision

Welcome to the home-stack wiki!

Home Stack

Home Project Stack

The stack is deployed using Kubernetes cluster enabled using microk8s. microk8s is installed using snap package manger. Package is provided by Canonical (publisher of Ubuntu).
- Resources: quad-core ARMx64 processor with 8GB RAM
- Kernel: GNU/Linux 5.4.0-1058-raspi aarch64
- OS: Ubuntu 20.04.4

As of now it is deployed on single node cluster.

- Alok Singh

Table of contents

Deployment of home-stack Kubernetes Stack

Create Namespaces

kubectl apply -f yaml/namespace.yaml

Create ConfigMap

kubectl apply -f yaml/config-map.yaml

Create Secrets

kubectl apply -f yaml/secrets.yaml

Create Network policy

kubectl apply -f yaml/networkpolicy.yaml

MySQL Service - Pod/Deployment/Service

kubectl apply --validate=true --dry-run=client -f yaml/mysql-service.yaml 
kubectl apply -f yaml/mysql-service.yaml  --namespace=home-stack
kubectl delete -f yaml/mysql-service.yaml  --namespace=home-stack
kubectl exec -it pod/mysql-0 --namespace home-stack -- mysql -u root -p home-stack
kubectl logs pod/mysql-0 --namespace home-stack
mysql -u root -p home-stack --host 127.0.0.1 --port 32306

Note:

Follow the link to configure sqldeveloper on Mac to connect to MySQL server remotely


Home API Service - Pod/Deployment/Service

kubectl apply --validate=true --dry-run=client -f yaml/home-api-service.yaml 
kubectl apply -f yaml/home-api-service.yaml  --namespace=home-stack
kubectl delete -f yaml/home-api-service.yaml  --namespace=home-stack
kubectl exec -it pod/home-api-deployment-0 --namespace home-stack -- bash
kubectl exec -it pod/home-api-deployment-0 --namespace home-stack -- tail -f /opt/logs/application.log
kubectl logs pod/home-api-deployment-0 --namespace home-stack
kubectl rollout restart statefulset.apps/home-api-deployment -n home-stack

Home Auth Service - Pod/Deployment/Service

kubectl apply --validate=true --dry-run=client -f yaml/home-auth-service.yaml 
kubectl apply -f yaml/home-auth-service.yaml  --namespace=home-stack
kubectl delete -f yaml/home-auth-service.yaml  --namespace=home-stack
kubectl exec -it pod/home-auth-deployment-0 --namespace home-stack -- bash
kubectl exec -it pod/home-auth-deployment-0 --namespace home-stack -- tail -f /opt/logs/application.log
kubectl logs pod/home-auth-deployment-0 --namespace home-stack
kubectl rollout restart statefulset.apps/home-api-deployment -n home-stack

Home ETL Service - Pod/Statefulset/Service

kubectl apply --validate=true --dry-run=client -f yaml/home-etl-service.yaml 
kubectl apply -f yaml/home-etl-service.yaml  --namespace=home-stack
kubectl delete -f yaml/home-etl-service.yaml  --namespace=home-stack
kubectl exec -it pod/home-etl-deployment-0 --namespace home-stack -- bash
kubectl exec -it pod/home-etl-deployment-0 --namespace home-stack -- tail -f /opt/logs/application.log
kubectl logs pod/home-etl-deployment-0 --namespace home-stack
kubectl rollout restart statefulset.apps/home-api-deployment -n home-stack

Home GIT Commit CronJob

kubectl apply --validate=true --dry-run=client -f yaml/git-commit-cronjob.yaml 
kubectl apply -f yaml/git-commit-cronjob.yaml  --namespace=home-stack
kubectl delete -f yaml/git-commit-cronjob.yaml  --namespace=home-stack

Statement Parser Service - Pod/Deployment/Service

kubectl apply --validate=true --dry-run=client -f yaml/stmt-parser-service.yaml 
kubectl apply -f yaml/stmt-parser-service.yaml  --namespace=home-stack
kubectl delete -f yaml/stmt-parser-service.yaml  --namespace=home-stack
kubectl exec -it pod/stmtparser-deployment-0 --namespace home-stack -- bash
kubectl exec -it pod/stmtparser-deployment-0 --namespace home-stack -- tail -f /opt/logs/spring-batch.log
kubectl logs pod/stmtparser-deployment-0 --namespace home-stack
kubectl rollout restart statefulset.apps/stmtparser-deployment -n home-stack

Dashboard Service - Pod/Deployment/Service

kubectl apply --validate=true --dry-run=client -f yaml/dashboard-service.yaml 
kubectl apply -f yaml/dashboard-service.yaml  --namespace=home-stack
kubectl delete -f yaml/dashboard-service.yaml  --namespace=home-stack
kubectl exec -it deployment.apps/dashboard-deployment --namespace home-stack -- /bin/sh
kubectl logs deployment.apps/dashboard-deployment --namespace home-stack

Jaeger Service

kubectl apply --validate=true --dry-run=client -f yaml/jaeger-all-in-one-template.yml 
kubectl apply -f yaml/jaeger-all-in-one-template.yml  --namespace=home-stack
kubectl delete -f yaml/jaeger-all-in-one-template.yml  --namespace=home-stack

Delete Stack

kubectl delete namespace home-stack 

Kubernetes Dashboard

Pod/Deployment/Service

kubectl apply -f yaml/kubernetes-dashboard.yaml
kubectl delete -f yaml/kubernetes-dashboard.yaml
kubectl get all --namespace kubernetes-dashboard
kubectl apply -f yaml/kubernetes-dashboard-rback-cluster-admin-user.yaml
kubectl create token k8s-dashboard-cluster-admin-user --duration=999999h -n kubernetes-dashboard

Note: use this token for Kubernetes Dashboard login

Kubernetes Metrics Server

kubectl apply -f yaml/metrix-server.yaml
kubectl delete -f yaml/metrix-server.yaml
kubectl get deployment metrics-server -n kube-system
kubectl top nodes

Ingress

Ingress Controller - Enable Nginx Ingress Controller

This will deploy a daemonset nginx-ingress-microk8s-controller

microk8s enable ingress

Ingress

kubectl apply -f yaml/ingress.yaml --namespace=home-stack

RBAC

Enable RBAC

microk8s enable rbac

Create roll binding for cluster admin user: alok

So that remotely cluster opertaion can be performed

kubectl apply -f yaml/home-user-rback-cluster-admin-user.yaml

Create user alok

Create CSR for user alok

cd ~/cert/k8s
openssl genrsa -out alok.key 2048
openssl req -new -key alok.key -out alok-csr.pem -subj "/CN=alok/O=home-stack/O=ingress"
scp alok-csr.pem alok@jgte:cert/

Sign User CSR on master node

openssl x509 -req -in ~/cert/alok-csr.pem -CA /var/snap/microk8s/current/certs/ca.crt -CAkey /var/snap/microk8s/current/certs/ca.key -CAcreateserial -out ~/cert/alok-crt.pem -days 365

Copy User Cert and CA cert

scp alok@jgte:cert/alok-crt.pem ~/cert/k8s
scp alok@jgte:/var/snap/microk8s/current/certs/ca.crt ~/cert/k8s

Note: add below entry in /etc/hosts

192.168.1.200   jgte kubernetes

Create Cluster

kubectl config set-cluster home-cluster --server=https://kubernetes:16443 --certificate-authority=/Users/aloksingh/cert/k8s/ca.crt --embed-certs=true
cat ~/.kube/config

Create User Credentials

kubectl config set-credentials alok --client-certificate=/Users/aloksingh/cert/k8s/alok-crt.pem --client-key=/Users/aloksingh/cert/k8s/alok.key --embed-certs=true

Create User Context

kubectl config set-context alok-home --cluster=home-cluster --namespace=home-stack --user alok

Use the context

kubectl config use-context alok-home

Horizon Autoscaling

Create HorizonTalPodAutoscaler

kubectl autoscale deployment dashboard-deployment --min=2 --max=3 -n home-stack
kubectl get hpa --namespace home-stack

Update Scale to 1

kubectl edit hpa dashboard-deployment --namespace home-stack
kubectl scale -n home-stack deployment dashboard-deployment --replicas=1

Miscellaneous commands

Get all

kubectl get all --all-namespaces

Get Pod Log

kubectl logs pod/dashboard-deployment-65cf5b8858-7x8z8 --namespace home-stack

Describe a Pod

kubectl describe pod/dashboard-deployment-65cf5b8858-7x8z8  --namespace=home-stack

Get All Pods under All Namespaces

kubectl get -A pods

Describe a spec

kubectl explain --api-version="batch/v1beta1" cronjobs.spec

Service Mesh - Istio

Install


To be explored - seems microk8s isteo addon not supported for ARMx64 architecture. Where the same is supported for minikube.


Deployment Architecture

alt text

Services

Application Description Service Type Deployment/StatefulSet/CronJob/DaemonSet URL Comments
Home ETL Service ETL for bank statement and other sources ClusterIP (Headless) StatefulSet /home/etl NA
Home API Service API for Bank/Expense/Tax/Investment/etc... ClusterIP Deployment /home/api GraalVM based native Image
Home Dashboard ReactJS App on Nginx NodePort Deployment http://jgte:30080 or https://jgte - For multinode deployment Interface has to be changed to ClusterIP and put behind Ingress - externalTrafficPolicy: Local to disable SNATing
Home GIT Cronjob Cronjob to update GIT with uploaded statement None CronJob NA NA
Database MySQL NodePort StatefulSet jdbc:mysql://mysql:3306/home-stack - NodePort because I want to access SQL from outside of the cluster
Kubernetes Dashboard LoadBalancer (static IP) Deployment https://jgte:8443/
Kubernetes Matrix Generating resource utilization matrix ClusterIP Deployment NA
Kubernetes Matrix Scraper Matrix scrapper from pods ClusterIP Deployment NA
Jaeger Dashboard NodePort Deployment http://jgte:31686/
Ingress Controller Nginx Ingress Controller NodePort DaemonSet Port: 443 API/ETL/Dashboard are behind Nginx but still we have Dashboard accessible directly (from mobile cant access host name - require local DNS server)
graph LR
    A[Write Code] --> B{Does it work?}
    B -- Yes --> C[Great!]
    B -- No --> D[Google]
    D --> A
Loading