Sign In

Curriculum 32: Capstone Project

Deploy a Multi-Service App

30 min · 50 XP

Deploy a Multi-Service Application

This lesson walks through deploying a microservices application using kubectl, covering service dependencies, configuration management, and inter-service communication.

Application Architecture

A typical microservices app includes a frontend, API backend, and database. Deploy them in order of dependencies, starting with the database.

Deploy the Database

# Create a namespace for the application
kubectl create namespace myapp

# Deploy PostgreSQL with persistent storage
kubectl apply -n myapp -f - <<'DB'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:16
          ports:
            - containerPort: 5432
          envFrom:
            - secretRef:
                name: db-credentials
DB

# Expose the database internally
kubectl expose deployment postgres -n myapp --port=5432 --target-port=5432

Deploy the API Backend

# Deploy the API service
kubectl create deployment api-server -n myapp \
  --image=myregistry/api:v1.0.0 --replicas=3

# Configure environment variables
kubectl set env deployment/api-server -n myapp \
  DATABASE_URL=postgres://postgres:5432/mydb

# Expose the API internally
kubectl expose deployment api-server -n myapp \
  --port=8080 --target-port=8080

Deploy the Frontend

# Deploy the frontend
kubectl create deployment frontend -n myapp \
  --image=myregistry/frontend:v1.0.0 --replicas=2

# Point frontend to the API
kubectl set env deployment/frontend -n myapp \
  API_URL=http://api-server:8080

# Expose frontend externally
kubectl expose deployment frontend -n myapp \
  --port=80 --target-port=3000 --type=LoadBalancer

Verify the Deployment

# Check all pods are running
kubectl get pods -n myapp

# Verify services and endpoints
kubectl get svc -n myapp
kubectl get endpoints -n myapp

# Test inter-service connectivity
kubectl run curl-test --rm -it -n myapp --image=curlimages/curl -- \
  curl http://api-server:8080/health

# Watch rollout status for all deployments
kubectl rollout status deployment --all -n myapp

Deploy dependencies first, use internal service DNS for communication, and verify connectivity between services before exposing to external traffic.