โ† Back to Projects
๐ŸŽต

MoodTunes React App on Google Kubernetes Engine

GKE ยท NGINX Ingress Controller ยท Let's Encrypt HTTPS ยท Google Container Registry ยท Cloud Build

PlatformGoogle Cloud Platform (GCP)
ToolsGKE ยท GCR ยท Cloud Build ยท NGINX Ingress ยท cert-manager
StackReact ยท Kubernetes ยท Docker ยท Let's Encrypt
InternshipThe CloudAdvisory Oy โ€” Cohort 2

Architecture

How It Works

User Browser (HTTPS) โ†“ DNS resolves domain โ†’ GCP External IP NGINX Ingress Controller โ€” Handles TLS termination (Let's Encrypt certificate) โ€” Enforces HTTP โ†’ HTTPS redirect โ€” Routes traffic to backend Kubernetes Service โ†“ Kubernetes Service (ClusterIP โ€” internal only) โ†“ MoodTunes React Pods (Deployment โ€” 2+ replicas) โ€” Containerized React build served via Nginx inside pod โ€” Image pulled from Google Container Registry (GCR) Automated Build Pipeline: Developer pushes code to GitHub โ†’ Cloud Build trigger fires โ†’ Docker image built โ†’ Image tagged and pushed to GCR โ†’ kubectl rolling update applied to Deployment โ†’ New pods replace old pods with zero downtime cert-manager: automatically provisions and renews TLS certificates GKE: Google-managed control plane (no etcd to maintain)
HTTPS
Auto-renewed TLS
GCR
Private Container Registry
Auto
Cloud Build CI Pipeline
0
Downtime on Update

Complete Build Process

1

Set Up GCP Project and Enable APIs

Created a new GCP project and enabled the required APIs: Kubernetes Engine API, Container Registry API, and Cloud Build API. Configured the gcloud CLI locally and authenticated with the project.

gcloud config set project YOUR_PROJECT_ID gcloud services enable container.googleapis.com gcloud services enable containerregistry.googleapis.com gcloud services enable cloudbuild.googleapis.com
2

Create the GKE Cluster

Provisioned a GKE cluster with a managed node pool. Used a standard cluster with autoscaling enabled so nodes scale based on workload demand.

gcloud container clusters create moodtunes-cluster \ --region us-central1 \ --num-nodes 2 \ --enable-autoscaling \ --min-nodes 1 \ --max-nodes 4 # Connect kubectl to the cluster gcloud container clusters get-credentials moodtunes-cluster \ --region us-central1
3

Containerize the React App with Docker

Wrote a multi-stage Dockerfile โ€” Stage 1 uses Node.js to build the React app, Stage 2 uses lightweight Nginx Alpine to serve only the compiled output. This reduced the image from ~1.2GB to under 100MB.

# Stage 1: Build FROM node:18-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build # Stage 2: Serve FROM nginx:alpine COPY --from=builder /app/build /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80
4

Build and Push Image to Google Container Registry

Built the Docker image and pushed it to GCR โ€” Google's private container registry. Using GCR means GKE can pull images without any external authentication setup.

export PROJECT_ID=$(gcloud config get-value project) docker build -t gcr.io/$PROJECT_ID/moodtunes:v1 . docker push gcr.io/$PROJECT_ID/moodtunes:v1
5

Deploy to GKE with Kubernetes Manifests

Created a Kubernetes Deployment manifest declaring 2 replicas, resource limits, and the GCR image. Applied it with kubectl. The cluster immediately pulled the image and started running pods.

apiVersion: apps/v1 kind: Deployment metadata: name: moodtunes spec: replicas: 2 selector: matchLabels: app: moodtunes template: metadata: labels: app: moodtunes spec: containers: - name: moodtunes image: gcr.io/PROJECT_ID/moodtunes:v1 ports: - containerPort: 80 resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "250m" memory: "256Mi" --- kubectl apply -f deployment.yaml kubectl rollout status deployment/moodtunes
6

Install NGINX Ingress Controller

Installed the NGINX Ingress Controller using Helm. This creates a GCP Load Balancer automatically and provisions an external IP address that becomes the public entry point for all traffic.

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm install ingress-nginx ingress-nginx/ingress-nginx \ --namespace ingress-nginx \ --create-namespace # Wait for external IP to be assigned kubectl get svc -n ingress-nginx # NAME TYPE EXTERNAL-IP # ingress-nginx-controller LoadBalancer 34.XX.XX.XX
7

Install cert-manager for Automatic TLS

Installed cert-manager โ€” a Kubernetes operator that automatically requests, installs, and renews TLS certificates from Let's Encrypt. Created a ClusterIssuer resource pointing to Let's Encrypt's ACME endpoint.

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml # Create ClusterIssuer apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata: name: letsencrypt-prod spec: acme: server: https://acme-v02.api.letsencrypt.org/directory email: ugochukwuafokwalam@gmail.com privateKeySecretRef: name: letsencrypt-prod solvers: - http01: ingress: class: nginx
8

Create Ingress Resource with TLS

Created the Ingress manifest that routes traffic from the external IP to the MoodTunes service, and instructs cert-manager to issue a Let's Encrypt certificate for the domain. HTTP automatically redirects to HTTPS.

apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: moodtunes-ingress annotations: kubernetes.io/ingress.class: nginx cert-manager.io/cluster-issuer: letsencrypt-prod nginx.ingress.kubernetes.io/ssl-redirect: "true" spec: tls: - hosts: - moodtunes.yourdomain.com secretName: moodtunes-tls rules: - host: moodtunes.yourdomain.com http: paths: - path: / pathType: Prefix backend: service: name: moodtunes-service port: number: 80 kubectl apply -f ingress.yaml # cert-manager automatically provisions certificate within ~2 minutes
9

Set Up Cloud Build Trigger for CI/CD

Connected the GitHub repository to Cloud Build. Created a cloudbuild.yaml file that builds the Docker image, pushes to GCR, and triggers a Kubernetes rolling update โ€” automatically on every push to main.

steps: - name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/$PROJECT_ID/moodtunes:$COMMIT_SHA', '.'] - name: 'gcr.io/cloud-builders/docker' args: ['push', 'gcr.io/$PROJECT_ID/moodtunes:$COMMIT_SHA'] - name: 'gcr.io/cloud-builders/kubectl' args: - set - image - deployment/moodtunes - moodtunes=gcr.io/$PROJECT_ID/moodtunes:$COMMIT_SHA env: - 'CLOUDSDK_COMPUTE_REGION=us-central1' - 'CLOUDSDK_CONTAINER_CLUSTER=moodtunes-cluster'
10

Verify the Full Stack is Running

Final verification โ€” checked that all pods are running healthy, the certificate is issued, and the app loads over HTTPS in a browser.

kubectl get pods # NAME READY STATUS RESTARTS # moodtunes-xxxxx-yyy 1/1 Running 0 # moodtunes-xxxxx-zzz 1/1 Running 0 kubectl get certificate # NAME READY SECRET AGE # moodtunes-tls True moodtunes-tls 3m # Open browser โ†’ https://moodtunes.yourdomain.com # โœ… Padlock icon visible โ€” TLS working # โœ… App loads โ€” React app served from GKE

Lessons Learned

What I Took Away

Multi-Stage Builds Are Non-Negotiable for Production

A single-stage Node.js build produces an image over 1GB. A multi-stage build with Nginx Alpine produces under 100MB. Smaller images mean faster pulls, smaller attack surface, and lower storage costs โ€” all for the same running application.

NGINX Ingress Is the Right Pattern at Scale

Creating a LoadBalancer service for every Kubernetes deployment creates one GCP load balancer per service โ€” expensive and unmanageable. One NGINX Ingress controller handles all external traffic and routes by hostname or path. One load balancer for everything.

cert-manager Makes HTTPS Maintenance-Free

Manual TLS certificate management is a reliability risk โ€” expired certs silently kill HTTPS. cert-manager renews Let's Encrypt certificates automatically 30 days before expiry. Once configured, you never think about certificates again.

Cloud Build Closes the Loop

Without CI/CD, deploying an update means manually building, tagging, pushing, and rolling out. With Cloud Build, every git push does all of that automatically in under 3 minutes. The pipeline is the deployment.

GKEKubernetesReactDockerNGINX IngressLet's EncryptGCRCloud Buildcert-managerMulti-Stage Build
โœฆ Spiritual Reflection: Kubernetes orchestrates containers the way the Lord orchestrates our experiences โ€” each pod assigned a purpose, each service connected to a greater whole. The system breathes without you forcing it to.
Read Full Article on Medium โ†’