How I Deployed this Website to Kubernetes

Introduction

Hi! I deployed my personal website safademirdag.com to production using modern DevOps practices. In this post, I'll share which technologies I used and how I set up the deployment process without diving too deep into technical details.


Technologies Used

Application

  • Next.js 14 + TypeScript
  • Docker

Infrastructure

  • 3 Servers (Master, Worker, Runner)
  • Kubernetes (RKE2)
  • GitLab CI/CD
  • NGINX Ingress + Let's Encrypt

Architecture

I used three servers:

  • Master Node: Kubernetes brain, all decisions made here
  • Worker Node: My application runs here
  • Runner Node: GitLab CI/CD pipelines run here

Deployment Process

1. Preparing Dockerfile

I converted Next.js into a small Docker image using multi-stage build. With output: 'standalone' setting in next.config.js, only necessary files go to production.

2. Kubernetes Manifests

I created three YAML files:

  • Deployment: Runs 2 copies of the application
  • Service: Provides internal network access to pods
  • Ingress: Routes safademirdag.com domain to the application

3. GitLab CI/CD Pipeline

Two stages that run automatically on every git push:

  1. Build: Create Docker image and upload to Registry
  2. Deploy: Deploy new image to Kubernetes

4. DNS and SSL

  • DNS A record: safademirdag.com → Master Node IP
  • cert-manager + Let's Encrypt: Automatic SSL certificate

Flow

When I make a code change:

  1. Git push
  2. GitLab Runner builds Docker image (~5 minutes)
  3. Image uploaded to Registry
  4. Kubernetes starts new pods
  5. Old pods shut down (zero-downtime)
  6. Site live with new version!

Entire process takes 7-10 minutes and is fully automated.


Lessons Learned

Best Practices

  • Small images with multi-stage Docker build
  • Isolation with Kubernetes namespaces
  • Auto-restart with health checks
  • Uninterrupted deployment with rolling updates

Problems I Encountered

  • Need to use node server.js instead of npm start in Dockerfile
  • Need to create imagePullSecret for GitLab Registry
  • Kubeconfig IP settings for runner to access master node

Conclusion

Now I can deploy to production with a single push. Thanks to Kubernetes, CI/CD, and containerization:

  • Automatic deployment
  • Zero-downtime updates
  • Easily scalable
  • Infrastructure as Code

I can easily focus on writing my code without worrying deployment issues!


DevOps