Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ruby Blog - Complete DevOps Pipeline

A comprehensive Ruby on Rails blog application with full DevOps pipeline including Docker containerization, Kubernetes deployment, GitOps with ArgoCD, and CI/CD with Tekton Pipelines.

πŸ“‹ Table of Contents

πŸ—οΈ Overview

This project demonstrates a complete DevOps workflow for a Ruby on Rails blog application:

  • Application: Ruby on Rails blog with PostgreSQL database
  • Containerization: Docker multi-stage builds
  • Orchestration: Kubernetes deployment on Minikube
  • GitOps: ArgoCD for continuous deployment
  • CI/CD: Tekton Pipelines for automated builds
  • Monitoring: Kubernetes Dashboard and ArgoCD UI

πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Source Repo   │───▢│  Tekton Pipeline │───▢│   Docker Hub    β”‚
β”‚  (ruby_blog)    β”‚    β”‚  (builds image)  β”‚    β”‚ (stores image)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚
                                                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GitOps Repo    │◀───│     ArgoCD       │───▢│   Kubernetes    β”‚
β”‚ (k8s manifests) β”‚    β”‚ (syncs changes)  β”‚    β”‚   (runs app)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Prerequisites

  • Docker Desktop (for building images)
  • Minikube (local Kubernetes cluster)
  • kubectl (Kubernetes CLI)
  • Git (version control)
  • Docker Hub Account (for image registry)

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/bankolejohn/ruby_blog.git
cd ruby_blog

2. Start Minikube

# Start Minikube with sufficient resources
minikube start --cpus=4 --memory=8192

# Enable required addons
minikube addons enable ingress
minikube addons enable metrics-server

🐳 Docker Setup

1. Create Dockerfile

The application uses a multi-stage Dockerfile for optimized builds:

# Build stage
FROM ruby:3.1-alpine AS builder
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install --without development test

# Production stage
FROM ruby:3.1-alpine
WORKDIR /app
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY . .
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

2. Build and Test Locally

# Build the Docker image
docker build -t ruby-blog:local .

# Test locally
docker run -p 3000:3000 ruby-blog:local

☸️ Kubernetes Deployment

1. Create Namespace

kubectl create namespace ruby-blog

2. Deploy PostgreSQL Database

kubectl apply -f k8s/postgres-pvc.yaml
kubectl apply -f k8s/postgres-secret.yaml
kubectl apply -f k8s/postgres-deployment.yaml
kubectl apply -f k8s/postgres-service.yaml

3. Deploy Rails Application

kubectl apply -f k8s/rails-deployment.yaml
kubectl apply -f k8s/rails-service.yaml
kubectl apply -f k8s/rails-ingress.yaml

4. Access the Application

# Get Minikube IP
minikube ip

# Add to /etc/hosts
echo "$(minikube ip) ruby-blog.local" | sudo tee -a /etc/hosts

# Access at: http://ruby-blog.local

πŸ”„ ArgoCD GitOps

1. Install ArgoCD

# Create namespace
kubectl create namespace argocd

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

# Wait for pods to be ready
kubectl wait --for=condition=available --timeout=300s deployment/argocd-server -n argocd

2. Access ArgoCD UI

# Port forward to access UI
kubectl port-forward svc/argocd-server -n argocd 8080:443

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

# Access at: https://localhost:8080
# Username: admin
# Password: (from above command)

3. Create ArgoCD Application

kubectl apply -f argocd/ruby-blog-app.yaml

πŸ”§ Tekton CI/CD Pipeline

1. Install Tekton Pipelines

# Install Tekton Pipelines
kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml

# Install Tekton Dashboard
kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/release.yaml

# Wait for installation
kubectl wait --for=condition=available --timeout=300s deployment/tekton-pipelines-controller -n tekton-pipelines

2. Configure Docker Hub Authentication

Create Docker Hub Access Token:

  1. Go to https://hub.docker.com/settings/security
  2. Create new access token with Read/Write/Delete permissions
  3. Copy the token (starts with dckr_pat_)
# Create Docker registry secret
kubectl create secret docker-registry docker-registry-secret \
  --docker-server=https://index.docker.io/v1/ \
  --docker-username=YOUR_DOCKERHUB_USERNAME \
  --docker-password=YOUR_ACCESS_TOKEN \
  --namespace=tekton-pipelines

3. Deploy Tekton Resources

# Apply tasks and pipeline
kubectl apply -f tekton/tasks/
kubectl apply -f tekton/pipelines/
kubectl apply -f tekton/updated-service-account.yaml

4. Access Tekton Dashboard

# Port forward to access dashboard
kubectl port-forward -n tekton-pipelines service/tekton-dashboard 9097:9097

# Access at: http://localhost:9097

5. Run Pipeline

# Create pipeline run
kubectl apply -f tekton/final-auth-test.yaml

# Monitor progress in dashboard or CLI
kubectl get pipelinerun -n tekton-pipelines

πŸ“Š Monitoring & Access

Application URLs

Useful Commands

# Check application status
kubectl get pods -n ruby-blog

# View application logs
kubectl logs -f deployment/rails-app -n ruby-blog

# Check ArgoCD applications
kubectl get applications -n argocd

# Monitor pipeline runs
kubectl get pipelinerun -n tekton-pipelines

# Access application shell
kubectl exec -it deployment/rails-app -n ruby-blog -- /bin/sh

πŸ”§ Troubleshooting

Common Issues and Solutions

1. Minikube Resource Issues

Problem: Pods stuck in Pending state due to insufficient resources

Solution:

# Restart Minikube with more resources
minikube stop
minikube start --cpus=4 --memory=8192

# Check resource usage
kubectl top nodes
kubectl top pods --all-namespaces

2. Docker Build Authentication Errors

Problem: UNAUTHORIZED: authentication required when pushing to Docker Hub

Solutions:

  • Use Docker Hub Access Token instead of password
  • Ensure proper secret configuration:
# Verify secret exists
kubectl get secret docker-registry-secret -n tekton-pipelines

# Recreate secret if needed
kubectl delete secret docker-registry-secret -n tekton-pipelines
kubectl create secret docker-registry docker-registry-secret \
  --docker-server=https://index.docker.io/v1/ \
  --docker-username=YOUR_USERNAME \
  --docker-password=YOUR_ACCESS_TOKEN \
  --namespace=tekton-pipelines

3. Tekton PodSecurity Policy Violations

Problem: PodAdmissionFailed due to security policy restrictions

Solution:

# Set privileged security policy for tekton-pipelines namespace
kubectl label namespace tekton-pipelines \
  pod-security.kubernetes.io/enforce=privileged \
  pod-security.kubernetes.io/audit=privileged \
  pod-security.kubernetes.io/warn=privileged --overwrite

4. Tekton Webhook Not Ready

Problem: Tekton webhook pod stuck in ContainerCreating or Pending

Solutions:

# Check webhook pod status
kubectl get pods -n tekton-pipelines | grep webhook

# Delete and recreate webhook pod
kubectl delete pod -n tekton-pipelines -l app.kubernetes.io/name=webhook

# Wait for new pod to start
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=webhook -n tekton-pipelines

5. Dockerfile Path Issues in Tekton

Problem: error resolving dockerfile path in kaniko build

Solution: Ensure correct path structure in kaniko task:

# Correct paths for git-clone + kaniko
workingDir: $(workspaces.source.path)/source
args:
  - --dockerfile=./Dockerfile
  - --context=dir://$(workspaces.source.path)/source

6. ArgoCD Application Sync Issues

Problem: ArgoCD application stuck in "OutOfSync" state

Solutions:

# Force refresh application
kubectl patch app ruby-blog-app -n argocd --type merge -p='{"operation":{"initiatedBy":{"username":"admin"},"sync":{"revision":"HEAD"}}}'

# Check application status
kubectl get app ruby-blog-app -n argocd -o yaml

7. Ingress Not Working

Problem: Cannot access application via ingress

Solutions:

# Ensure ingress addon is enabled
minikube addons enable ingress

# Check ingress controller
kubectl get pods -n ingress-nginx

# Verify ingress resource
kubectl get ingress -n ruby-blog

# Update /etc/hosts with correct Minikube IP
echo "$(minikube ip) ruby-blog.local" | sudo tee -a /etc/hosts

8. Database Connection Issues

Problem: Rails app cannot connect to PostgreSQL

Solutions:

# Check PostgreSQL pod status
kubectl get pods -n ruby-blog | grep postgres

# Verify database secret
kubectl get secret postgres-secret -n ruby-blog -o yaml

# Check service connectivity
kubectl exec -it deployment/rails-app -n ruby-blog -- nc -zv postgres-service 5432

9. Port Forward Issues

Problem: Port forwarding fails or stops working

Solutions:

# Kill existing port forwards
pkill -f "kubectl port-forward"

# Restart port forward with different port
kubectl port-forward -n argocd svc/argocd-server 8081:443
kubectl port-forward -n tekton-pipelines service/tekton-dashboard 9098:9097

10. Pipeline Timeout Issues

Problem: PipelineRun failed to finish within "1h0m0s"

Solutions:

# Create PipelineRun with extended timeout
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
spec:
  timeouts:
    pipeline: "2h0m0s"  # Extend to 2 hours
    tasks: "1h30m0s"    # Per-task timeout

# Check if image was actually built despite timeout
curl -s "https://hub.docker.com/v2/repositories/YOUR_USERNAME/YOUR_REPO/tags/"

# Monitor build progress in real-time
kubectl logs -f -n tekton-pipelines -l tekton.dev/pipelineRun=YOUR_PIPELINE_RUN

11. Docker Build Stream Errors

Problem: stream error: stream ID 3; INTERNAL_ERROR during Docker build

Solutions:

# Check Minikube resource usage
kubectl top nodes

# Clean up resources if memory/CPU > 80%
kubectl delete pipelinerun --all -n tekton-pipelines
kubectl delete pods --field-selector=status.phase=Failed --all-namespaces

# Optimize kaniko for low resources
args:
  - --cache=false
  - --single-snapshot
  - --cleanup

# Restart Minikube if needed
minikube stop && minikube start --cpus=4 --memory=8192

11. Resource Cleanup

Problem: Need to clean up resources for fresh start

Solution:

# Delete all pipeline runs
kubectl delete pipelinerun --all -n tekton-pipelines

# Clean up failed pods
kubectl delete pods --field-selector=status.phase=Failed --all-namespaces

# Restart Minikube if needed
minikube stop && minikube start --cpus=4 --memory=8192

πŸ“ Repository Structure

ruby_blog/
β”œβ”€β”€ README.md                 # This comprehensive guide
β”œβ”€β”€ Dockerfile               # Multi-stage Docker build
β”œβ”€β”€ Gemfile                  # Ruby dependencies
β”œβ”€β”€ app/                     # Rails application code
β”œβ”€β”€ k8s/                     # Kubernetes manifests
β”‚   β”œβ”€β”€ postgres-*.yaml      # PostgreSQL database
β”‚   β”œβ”€β”€ rails-*.yaml         # Rails application
β”‚   └── ingress.yaml         # Ingress configuration
β”œβ”€β”€ argocd/                  # ArgoCD configurations
β”‚   └── ruby-blog-app.yaml   # ArgoCD application
└── tekton/                  # Tekton CI/CD pipeline
    β”œβ”€β”€ tasks/               # Tekton tasks
    β”œβ”€β”€ pipelines/           # Tekton pipelines
    └── *.yaml              # Pipeline runs and configs

🎯 Next Steps

  1. Production Deployment: Adapt configurations for production Kubernetes cluster
  2. Monitoring: Add Prometheus and Grafana for metrics
  3. Security: Implement RBAC and security policies
  4. Backup: Set up database backup strategies
  5. Scaling: Configure horizontal pod autoscaling
  6. SSL/TLS: Add certificate management with cert-manager

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages