Kubernetes Deployment Configuration
What you'll build
A set of Kubernetes YAML manifests that deploy a web application with 3 replicas, expose it via a Service, and configure it with a ConfigMap.
Goals
- Write a Kubernetes Deployment manifest
- Create a Service to expose the application
- Use a ConfigMap for configuration
- Deploy and verify the application in a cluster
Prerequisites
- Basic understanding of containers and Docker
- kubectl installed and connected to a Kubernetes cluster (or minikube)
- A container image to deploy (e.g., nginx)
Steps
- 1
Create a ConfigMap
Create a ConfigMap YAML file that stores non-sensitive configuration for your application, like environment settings.
CodeapiVersion: v1 kind: ConfigMap metadata: name: app-config data: ENV: "production" LOG_LEVEL: "info"Expected result
A ConfigMap YAML file is created with configuration values.
- 2
Write the Deployment manifest
Create a Deployment that runs 3 replicas of nginx, injects the ConfigMap as environment variables, and sets resource limits.
CodeapiVersion: apps/v1 kind: Deployment metadata: name: web-app spec: replicas: 3 selector: matchLabels: app: web-app template: metadata: labels: app: web-app spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 envFrom: - configMapRef: name: app-config resources: requests: cpu: 100m memory: 128Mi limits: cpu: 200m memory: 256MiExpected result
A Deployment YAML file is created with 3 replicas and ConfigMap injection.
- 3
Write the Service manifest
Create a Service that exposes the Deployment on a stable internal IP, load-balancing across the 3 replicas.
CodeapiVersion: v1 kind: Service metadata: name: web-app-service spec: type: ClusterIP selector: app: web-app ports: - port: 80 targetPort: 80Expected result
A Service YAML file is created that routes traffic to the Deployment's Pods.
- 4
Deploy to the cluster
Use kubectl to apply all three manifests to your cluster. Then verify the Deployment, Pods, and Service are running correctly.
Codekubectl apply -f configmap.yaml kubectl apply -f deployment.yaml kubectl apply -f service.yaml kubectl get pods -l app=web-app kubectl get service web-app-serviceExpected result
Three Pods are running, and the Service is created with a cluster IP.
- 5
Add a health check endpoint
Add a /health endpoint returning 200 OK for orchestration systems (Kubernetes, load balancers) to probe liveness. Health checks are foundational for production deployment.
Code# app.py (Flask example) from flask import Flask, jsonify app = Flask(__name__) @app.route("/health") def health(): return jsonify({"status": "ok"}), 200 @app.route("/ready") def ready(): # Check DB connection etc. return jsonify({"ready": True}), 200Expected result
curl localhost:5000/health returns {"status":"ok"} with a 200 status code.
Try it yourself
What you learned
You wrote Kubernetes manifests for a Deployment, Service, and ConfigMap, and deployed them to a cluster. This is the core of Kubernetes application deployment.
Related Resources
Related Glossary
- Kubernetes
Container orchestration platform
- Deployment
Kubernetes Deployment resource
Related Glossary
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
- Kubernetes
Container orchestration platform
- Deployment
Kubernetes Deployment resource
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.