Kubernetes with Monitoring Project

Kubernetes with Monitoring Project

K8s Kind Voting App

A comprehensive guide for setting up a Kubernetes cluster using Kind on an AWS EC2 instance, installing and configuring Argo CD, and deploying applications using Argo CD.

Overview

This guide covers the steps to:

  • Launch an AWS EC2 instance.

  • Install Docker and Kind.

  • Create a Kubernetes cluster using Kind.

  • Install and access Kubectl.

  • Set up the Kubernetes Dashboard.

  • Install and configure Argo CD.

  • Connect and manage your Kubernetes cluster with Argo CD.

  • Set Up Prometheus & Grafana

Architecture

Observability

  • A front-end web app in Python which lets you vote between two options

  • A Redis which collects new votes

  • A .NET worker which consumes votes and stores them in…

  • A Postgres database backed by a Docker volume

  • A Node.js web app which shows the results of the voting in real

Create Instance

Update system

sudo apt update

Install Docker

sudo apt-get install docker.io

Creating and Managing Kubernetes Clusters with Kind

Clear terminal:

clear

Create a 3-node Kubernetes cluster using Kind:

kind create cluster --config=config.yml

Check cluster information:

kubectl cluster-info --context kind-kind
kubectl get nodes
kind get clusters

Installing kubectl

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version --short --client

Managing Docker and Kubernetes Pods

Check Docker containers running:

docker ps

List all Kubernetes pods in all namespaces:

kubectl get pods -A

Cloning and Running the Example Voting App

Clone the voting app repository:

git clone https://github.com/dockersamples/example-voting-app.git
cd example-voting-app/

Apply Kubernetes YAML specifications for the voting app:

kubectl apply -f k8s-specifications/

List all Kubernetes resources:

kubectl get all

Forward local ports for accessing the voting and result apps:

kubectl port-forward service/vote 5000:5000 --address=0.0.0.0 &
kubectl port-forward service/result 5001:5001 --address=0.0.0.0 &

Managing Files in Example Voting App

Navigate and view files:

cd ..
cd seed-data/
ls
cat Dockerfile
cat generate-votes.sh

Installing Argo CD

Create a namespace for Argo CD:

kubectl create namespace argocd

Apply the Argo CD manifest:

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Check services in Argo CD namespace:

kubectl get svc -n argocd

Expose Argo CD server using NodePort:

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'

Forward ports to access Argo CD server:

kubectl port-forward -n argocd service/argocd-server 8443:443 &

Installing Kubernetes Dashboard

Deploy Kubernetes dashboard:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

Create a token for dashboard access:

kubectl -n kubernetes-dashboard create token admin-user

Argo CD Initial Admin Password

Retrieve Argo CD admin password:

kubectl get secret -n argocd argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo

Install HELM

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Install Kube Prometheus Stack

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo update
kubectl create namespace monitoring
helm install kind-prometheus prometheus-community/kube-prometheus-stack --namespace monitoring --set prometheus.service.nodePort=30000 --set prometheus.service.type=NodePort --set grafana.service.nodePort=31000 --set grafana.service.type=NodePort --set alertmanager.service.nodePort=32000 --set alertmanager.service.type=NodePort --set prometheus-node-exporter.service.nodePort=32001 --set prometheus-node-exporter.service.type=NodePort
kubectl get svc -n monitoring
kubectl get namespace
kubectl port-forward svc/kind-prometheus-kube-prome-prometheus -n monitoring 9090:9090 --address=0.0.0.0 &
kubectl port-forward svc/kind-prometheus-grafana -n monitoring 31000:80 --address=0.0.0.0 &

Prometheus Queries

kubectl port-forward svc/kind-prometheus-kube-prome-prometheus -n monitoring 9090:9090 --address=0.0.0.0 &
kubectl port-forward svc/kind-prometheus-grafana -n monitoring 31000:80 --address=0.0.0.0 &

Grafana Dashboard

Grafana Monitoring

Deleting Kubernetes Cluster

kind delete cluster --name=kind

Happy Learning 😊

GitHub-Repo

Portfolio

Linkdin