- Docker
- Docker Compose
# Clone the repository
git clone https://github.com/CosmeValera/devopslab
cd devopslab
# Start all services
docker-compose up -d
## You should be able to access:
##
## Frontend: localhost:3000
## Backend: localhost:3001
## Jenkins: localhost:8080
# Stop services
docker-compose down
# Check service status
docker-compose ps
# View logs
docker-compose logs -f# Build images
docker build -t devopslab-frontend ./frontend
docker build -t devopslab-backend ./backend
docker build --build-arg DOCKER_GID=$(getent group docker | cut -d: -f3) -t devopslab-jenkins ./jenkins
# Run containers
docker run -d --name backend -p 3001:3001 devopslab-backend
docker run -d --name frontend -p 3000:3000 devopslab-frontend
docker run -d --name jenkins --network host -e JENKINS_OPTS=--httpPort=8080 --restart=on-failure -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock devopslab-jenkins
# Delete images
docker rmi -f devopslab-frontend devopslab-backend devopslab-jenkins
docker image prune -f- kubectl
- Kubernetes cluster (minikube, kind, or cloud provider)
# Load images
docker build -t devopslab-frontend ./frontend
docker build -t devopslab-backend ./backend
# Start minikube (if using local cluster)
minikube start
# Load the images inside Minikube
minikube image load devopslab-frontend
minikube image load devopslab-backend
minikube ssh -- docker images # Check# Create namespace.yaml
kubectl apply -f deployments/k8s/namespace.yaml# Apply all Kubernetes manifests
kubectl apply -f deployments/k8s/backend/ -f deployments/k8s/frontend/
# Check deployment status
kubectl get all -n devopslab
# Delete deployment
kubectl delete all --all -n devopslab
# Access the application
kubectl port-forward svc/frontend-service 3000:80 -n devopslab
kubectl port-forward svc/backend-service 3001:80 -n devopslab
# View logs
kubectl logs -f deployment/frontend -n devopslab
kubectl logs -f deployment/backend -n devopslab- kubectl
- Kustomize (optional, kubectl has built-in support)
Remember to start Miniikube and load the images into Minikube in case you haven't yet (you can find how in the
☸️ Kubernetes Deploymentsection).
# Create namespace.yaml
kubectl apply -f deployments/k8s/namespace.yaml# Deploy to development environment
kubectl apply -k deployments/kustomize/overlays/dev
# Deploy to production environment
kubectl apply -k deployments/kustomize/overlays/prod
# Build manifests without applying
kubectl kustomize deployments/kustomize/overlays/dev
# Delete deployment
kubectl delete -k deployments/kustomize/overlays/dev
kubectl delete -k deployments/kustomize/overlays/prod
# Check k8s manifests
kubectl get all,configmap -n devopslab
# Access the application
kubectl port-forward svc/frontend-service 3000:80 -n devopslab
kubectl port-forward svc/backend-service 3001:80 -n devopslab
- Helm 3.x
- Kubernetes cluster
Remember to start Miniikube and load the images into Minikube in case you haven't yet (you can find how in the
☸️ Kubernetes Deploymentsection).
# Create namespace.yaml
kubectl apply -f deployments/k8s/namespace.yaml# Install the application
helm install devopslab ./deployments/helm/devopslab -f ./deployments/helm/devopslab/values-dev.yaml
helm install devopslab ./deployments/helm/devopslab -f ./deployments/helm/devopslab/values-prod.yaml
# Upgrade deployment
helm upgrade devopslab ./deployments/helm/devopslab -f ./deployments/helm/devopslab/values-prod.yaml
# Uninstall
helm uninstall devopslab
# Check deployment status
helm list
kubectl get all -n devopslab
# Check k8s manifests
kubectl get all,configmap -n devopslab# Use a values file
helm install devopslab ./deployments/helm/devopslab -f custom-values.yaml
# Or install with custom values
helm install devopslab ./deployments/helm/devopslab \
--set replicaCount=3Method 1: Access with minikube tunnel
# Enable the ingress addon and start the tunnel
minikube addons enable ingress
minikube tunnel
# Note: Keep this terminal running throughout your session
# The tunnel may prompt for your WSL password
# Deploy your application after starting the tunnel
# Once running, you can access:
# - Frontend: http://localhost
# - Backend API: http://localhost/apiMethod 2: Use port-forward
kubectl port-forward svc/frontend-service 3000:80 -n devopslab
kubectl port-forward svc/backend-service 3001:80 -n devopslab
# Once running, you can access:
# - Frontend: http://localhost:3000
# - Backend API: http://localhost:3001- Docker
# Start Build and start Jenkins container
docker build --build-arg DOCKER_GID=$(getent group docker | cut -d: -f3) -t devopslab-jenkins ./jenkins
docker run -d --name jenkins --network host -e JENKINS_OPTS=--httpPort=8080 --restart=on-failure -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock devopslab-jenkins
# Get initial admin password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
# Create the .env file for the backend, so that the pipeline status page in the frontend can work
echo -e "JENKINS_HOST=http://localhost:8080\nJENKINS_USER=admin\nJENKINS_TOKEN=$(docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword)\nPORT=3001\nNODE_ENV=development" > backend/.env- Open
http://localhost:8080in your browser - Install suggested plugins
- Create admin user
- Create a new Pipeline job
- Configure the pipeline to use the Jenkinsfile from the repository
The Jenkins pipeline includes:
- Build Stage: Install dependencies and run tests
- Test Stage: Execute unit and integration tests
- Build Images Stage: Build Docker images
- Deploy Stage: Deploy to local Docker environment
- Cleanup Stage: Clean up old images