From Zero to Hero: Infrastructure, Automation & Scalability
The Foundation of Every Production System
# 🔄 Full system update & upgrade
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
# 🧰 Install essential toolkit
sudo apt install -y git curl wget unzip htop net-tools vim tmux \
build-essential software-properties-common
# 🆕 Create deployment user
sudo adduser --gecos "" devops
sudo usermod -aG sudo devops
sudo usermod -aG adm devops
# 🔑 SSH key setup
sudo mkdir -p /home/devops/.ssh
sudo touch /home/devops/.ssh/authorized_keys
sudo chmod 700 /home/devops/.ssh
sudo chmod 600 /home/devops/.ssh/authorized_keys
sudo chown -R devops:devops /home/devops/.ssh
# /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
# Restart SSH
sudo systemctl restart sshd
Version Control Done Right
# 👤 Identity setup
git config --global user.name "Nov Hun"
git config --global user.email "dev@novhun.dev"
git config --global init.defaultBranch main
git config --global pull.rebase true
# 🌿 Feature branch workflow
git checkout -b feature/authentication
git add .
git commit -m "feat(auth): implement JWT authentication
- Add JWT token generation and validation
- Implement login/signup endpoints
- Resolves: #42"
git push -u origin feature/authentication
# 📦 Tagging releases
git tag -a v1.2.0 -m "Release v1.2.0"
git push origin v1.2.0
Build Once, Run Anywhere
# 📥 Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl enable docker
sudo usermod -aG docker $USER
newgrp docker
FROM node:18-alpine
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
WORKDIR /app
COPY --chown=nextjs:nodejs . .
USER nextjs
EXPOSE 3000
CMD ["npm", "start"]
docker ps -a
List containers
docker build -t myapp .
Build image
docker run -d -p 80:3000 myapp
Run container
docker logs -f myapp
View logs
Multi-Container Applications Made Simple
version: '3.8'
services:
frontend:
build: ./frontend
ports: ["3000:3000"]
backend:
build: ./backend
ports: ["8000:8000"]
postgres:
image: postgres:15-alpine
volumes: [postgres-data:/var/lib/postgresql/data]
volumes: postgres-data:
docker-compose up -d
Start services
docker-compose down -v
Stop & remove
The Ultimate Web Server & Gateway
upstream backend {
least_conn;
server backend1:3000 weight=3;
server backend2:3000 weight=2;
}
server {
listen 443 ssl http2;
server_name api.novhun.dev;
location /api/ {
proxy_pass http://backend/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Enterprise-Grade Container Orchestration
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 5
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: app
image: novhun/web-app:latest
ports:
- containerPort: 3000
resources:
limits:
memory: "512Mi"
cpu: "500m"
kubectl get pods
List pods
kubectl apply -f deploy.yaml
Deploy app
kubectl rollout status deploy/web-app
Check status
Infrastructure as Code at Scale
- name: Deploy Application
hosts: webservers
become: yes
tasks:
- name: Install Docker
apt:
name: docker.io
state: present
- name: Start Docker
systemd:
name: docker
state: started
- name: Run container
docker_container:
name: web-app
image: novhun/web-app:latest
ports: "3000:3000"
Automated Testing & Deployment
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
- run: docker build -t myapp .
- run: docker push myapp
pipeline {
agent any
stages {
stage('Build') {
steps { sh 'docker build -t myapp .' }
}
stage('Deploy') {
steps { sh 'kubectl apply -f deploy.yaml' }
}
}
}
AWS S3 & Cloudflare R2 Integration
# AWS CLI
aws s3 cp backup.sql s3://production-backups/ --sse AES256
aws s3 sync dist/ s3://myapp-static-bucket/ --delete
# Cloudflare R2
wrangler r2 bucket create production-assets
wrangler r2 object put production-assets/config.json --file ./config.json
Zero Trust Security Architecture
#!/bin/bash
sudo ufw default deny incoming
sudo ufw allow ssh
sudo ufw --force enable
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo apt install unattended-upgrades -y
echo "✅ System hardened!"
| Category | Command | Description |
|---|---|---|
| Ubuntu | sudo journalctl -u docker -f |
Docker logs |
| Docker | docker system df |
Disk usage |
| K8s | kubectl top pods |
Pod metrics |
| AWS | aws s3 ls --human-readable |
List buckets |