πŸš€ Kubernetes Cluster Setup Guide

Complete step-by-step setup of Kubernetes cluster with ArgoCD, Helm, Traefik Ingress Controller, and Cert-Manager

πŸ“‹ Table of Contents

  1. Cluster Creation
  2. Metrics Server Deployment
  3. ArgoCD Installation & Configuration
  4. Traefik Ingress Controller
  5. Cert-Manager Setup
  6. ECR Access Configuration
  7. Learning Hub Application Deployment
  8. Current Cluster State

1Cluster Creation

The first step was creating a Kubernetes cluster. This cluster serves as the foundation for all subsequent deployments.

What is a Kubernetes Cluster?

A Kubernetes cluster is a set of nodes (machines) that run containerized applications. It consists of a control plane (manages the cluster) and worker nodes (run the applications).

Current Namespaces:

2Metrics Server Deployment

The Kubernetes Metrics Server was deployed to collect resource metrics from kubelets and expose them via the Kubernetes API.

Installation Command:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Why Metrics Server?

Verification Commands:

# Check metrics server deployment
kubectl get deployment metrics-server -n kube-system

# View node resource usage
kubectl top nodes

# View pod resource usage across all namespaces
kubectl top pods -A

# View pod resource usage in dev namespace
kubectl top pods -n dev

# View container-level metrics in dev namespace
kubectl top pods -n dev --containers
βœ“ Current Status: Metrics Server is running in kube-system namespace

3ArgoCD Installation & Configuration

ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It automates the deployment of applications by syncing them with Git repositories.

3.1 Installation

helm upgrade --install argocd ./argocd -n argocd --create-namespace
Note: This command uses Helm to install ArgoCD. It creates the argocd namespace if it doesn't exist and upgrades if already installed.

3.2 ArgoCD Components Deployed:

Component Ready Description
argocd-server 1/1 API server and UI
argocd-repo-server 1/1 Repository server (clones Git repos)
argocd-redis 1/1 Redis cache
argocd-applicationset-controller 1/1 Manages ApplicationSets
argocd-notifications-controller 1/1 Handles notifications

3.3 Access ArgoCD UI

# Port forward to access ArgoCD UI locally
kubectl port-forward svc/argocd-server -n argocd 8081:80
Access URL: http://localhost:8081
Username: admin

3.4 Retrieve Admin Password

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

3.5 ArgoCD CLI Login

# Login to ArgoCD via CLI
argocd login localhost:8081 --insecure --username admin --password $(kubectl get secret \
argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d)

3.6 Create ArgoCD Project

A project provides logical grouping of applications with access controls.

# Create a project named 'learning-hub'
argocd proj create learning-hub \
    --dest https://kubernetes.default.svc,dev \
    --dest https://kubernetes.default.svc,prod \
    --src '*'
Project Configuration:

4Traefik Ingress Controller

Traefik is a modern HTTP reverse proxy and load balancer. It automatically discovers services and routes traffic to them.

Check Traefik Service

kubectl get svc -n kube-system | grep traefik
traefik LoadBalancer 172.20.55.96 a8cb8b6a751594cf8aa8402bd51364bb-1548067253.us-east-1.elb.amazonaws.com 80:32045/TCP,443:30624/TCP
βœ“ Traefik Status:

Next Steps for Traefik:

  1. Add Traefik IngressRoute configuration to Helm deployment
  2. Configure DNS to point to the AWS Load Balancer
  3. Apply HTTPS redirect middleware

HTTPS Redirect Middleware

kubectl apply -f traefik/https-redirect-middleware.yaml

This middleware automatically redirects HTTP traffic to HTTPS.

5Cert-Manager Setup

Cert-Manager automates the management and issuance of TLS certificates from Let's Encrypt and other certificate authorities.

5.1 Install Cert-Manager

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yaml

5.2 Wait for Cert-Manager to be Ready

kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=cert-manager -n cert-manager --timeout=300s

5.3 Cert-Manager Components:

Component Status Purpose
cert-manager Running Main controller
cert-manager-webhook Running Webhook for validating and mutating requests
cert-manager-cainjector Running Injects CA bundles into webhooks and APIServices

5.4 Configure Let's Encrypt Issuers

kubectl apply -f cert-manager/letsencrypt-issuer.yaml
βœ“ Configured Issuers:

5.5 Current Certificates:

Namespace Certificate Status Secret
dev learning-hub-tls Ready βœ“ learning-hub-tls-cert
prod learning-hub-tls Ready βœ“ learning-hub-tls-cert
Certificate Management:

Cert-Manager automatically renews certificates before they expire. The certificates are stored as Kubernetes secrets and can be referenced in Ingress/IngressRoute resources.

6ECR Access Configuration

Amazon Elastic Container Registry (ECR) access was configured to allow pulling private Docker images.

Create Docker Registry Secret

kubectl create secret docker-registry ecr-secret \
    --docker-server=541770108352.dkr.ecr.us-east-1.amazonaws.com \
    --docker-username=AWS \
    --docker-password=$(aws ecr get-login-password --region us-east-1) \
    -n dev
Purpose:
Important: ECR tokens expire after 12 hours. For production, consider using IAM roles for service accounts (IRSA) or automated secret refresh mechanisms.

7Learning Hub Application Deployment

The Learning Hub application is deployed to both dev and prod environments using ArgoCD with GitOps workflow.

7.1 Create Dev Application

argocd app create learning-hub-dev \
    --repo https://github.com/hanov/helm.git \
    --path learning-hub \
    --dest-server https://kubernetes.default.svc \
    --dest-namespace dev \
    --values values-dev.yaml \
    --project learning-hub \
    --sync-policy automated \
    --auto-prune \
    --self-heal

7.2 Create Prod Application

argocd app create learning-hub-prod \
    --repo https://github.com/hanov/helm.git \
    --path learning-hub \
    --dest-server https://kubernetes.default.svc \
    --dest-namespace prod \
    --values values-prod.yaml \
    --project learning-hub \
    --sync-policy automated \
    --auto-prune \
    --self-heal

ArgoCD Configuration Explained:

Parameter Value Purpose
--repo GitHub URL Source Git repository
--path learning-hub Path to Helm chart in repo
--values values-dev.yaml / values-prod.yaml Environment-specific values
--sync-policy automated Auto-sync on Git changes
--auto-prune enabled Delete resources removed from Git
--self-heal enabled Revert manual cluster changes
βœ“ Current Deployments:

Application Management Commands:

# Delete applications (if needed)
argocd app delete learning-hub-dev
argocd app delete learning-hub-prod

# List all ArgoCD applications
argocd app list

# View application details
argocd app get learning-hub-dev
argocd app get learning-hub-prod

# Sync application manually
argocd app sync learning-hub-dev

8Current Cluster State Overview

Namespaces (8 total):

Key Services:

Service Namespace Type Status
traefik kube-system LoadBalancer βœ“ Running with AWS ELB
metrics-server kube-system ClusterIP βœ“ Running
argocd-server argocd NodePort βœ“ Running (ports 30080/30443)
cert-manager cert-manager Multiple pods βœ“ All components running

Application Deployments:

Environment Deployment Replicas Status
dev learning-hub 1/1 βœ“ Available
prod learning-hub 3/3 βœ“ Available

TLS Certificates:

External Access:

Load Balancer: a8cb8b6a751594cf8aa8402bd51364bb-1548067253.us-east-1.elb.amazonaws.com
Ports: 80 (HTTP) β†’ 443 (HTTPS with redirect)

πŸ“Š Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Internet                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   AWS Load Balancer   β”‚
              β”‚  (Traefik External)   β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                             β”‚
          β–Ό                             β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  HTTP   │──[redirect]──────▢│  HTTPS  β”‚
    β”‚  :80    β”‚                   β”‚  :443   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                       β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚   Traefik Ingress   β”‚
                            β”‚   (kube-system)     β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚                     β”‚                     β”‚
                 β–Ό                     β–Ό                     β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚   Dev Env   β”‚      β”‚  Prod Env   β”‚      β”‚   ArgoCD    β”‚
          β”‚             β”‚      β”‚             β”‚      β”‚     UI      β”‚
          β”‚ learning-hubβ”‚      β”‚ learning-hubβ”‚      β”‚             β”‚
          β”‚   (1 pod)   β”‚      β”‚   (3 pods)  β”‚      β”‚ :8081 (fwd) β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚                     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚   Cert-Manager      β”‚
                 β”‚  (TLS Certificates) β”‚
                 β”‚                     β”‚
                 β”‚ β€’ letsencrypt-prod  β”‚
                 β”‚ β€’ letsencrypt-stage β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Support Services                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Metrics Server (resource monitoring)                     β”‚
β”‚  β€’ ArgoCD (GitOps CD)                                       β”‚
β”‚  β€’ ECR Secret (container registry access)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    

πŸ› οΈ Useful Commands Reference

Cluster Monitoring:

# View all namespaces
kubectl get namespaces

# View all pods across namespaces
kubectl get pods -A

# Check resource usage
kubectl top nodes
kubectl top pods -A

ArgoCD Management:

# Port forward to access UI
kubectl port-forward svc/argocd-server -n argocd 8081:80

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

# List applications
argocd app list

# Sync application
argocd app sync learning-hub-dev

Certificate Management:

# Check certificates
kubectl get certificate -A

# Check certificate issuers
kubectl get clusterissuer

# Describe certificate (for troubleshooting)
kubectl describe certificate learning-hub-tls -n dev

Deployment Monitoring:

# Watch deployments in dev
kubectl get deployments -n dev -w

# View deployment details
kubectl describe deployment learning-hub -n dev

# Check pod logs
kubectl logs -n dev -l app=learning-hub

# Get pod details
kubectl get pods -n dev -o wide

Traefik:

# Check Traefik service
kubectl get svc traefik -n kube-system

# View Traefik logs
kubectl logs -n kube-system -l app.kubernetes.io/name=traefik

# Check IngressRoutes
kubectl get ingressroute -A

βœ… Summary

The Kubernetes cluster is fully operational with the following capabilities:

Cluster Health: βœ“ All Systems Operational