1. Home
  2. /
  3. Kubernetes
  4. /
  5. Deployment with Service

Deployment with Service - Kubernetes Typing CST Test

Loading…

Deployment with Service — Kubernetes Code

Demonstrates complete Kubernetes application deployment with configuration, secrets, services, and auto-scaling.

# Namespace
apiVersion: v1
kind: Namespace
metadata:
	name: my-app
	labels:
		name: my-app

---
# ConfigMap for application configuration
apiVersion: v1
kind: ConfigMap
metadata:
	name: app-config
	namespace: my-app
data:
	DATABASE_HOST: "postgres-service"
	DATABASE_PORT: "5432"
	REDIS_HOST: "redis-service"
	REDIS_PORT: "6379"

---
# Secret for sensitive data
apiVersion: v1
kind: Secret
metadata:
	name: app-secrets
	namespace: my-app
type: Opaque
data:
	DATABASE_PASSWORD: cGFzc3dvcmQxMjM=  # base64 encoded
	API_KEY: YWJjZGVmZ2hpams=

---
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
	name: my-app-deployment
	namespace: my-app
	labels:
		app: my-app
spec:
	replicas: 3
	selector:
		matchLabels:
		app: my-app
	template:
		metadata:
		labels:
		app: my-app
		spec:
		containers:
		- name: my-app
		image: my-app:latest
		ports:
		- containerPort: 3000
		env:
		- name: DATABASE_HOST
		valueFrom:
		configMapKeyRef:
		name: app-config
		key: DATABASE_HOST
		- name: DATABASE_PASSWORD
		valueFrom:
		secretKeyRef:
		name: app-secrets
		key: DATABASE_PASSWORD
		resources:
		requests:
		memory: "256Mi"
		cpu: "200m"
		limits:
		memory: "512Mi"
		cpu: "500m"
		livenessProbe:
		httpGet:
		path: /health
		port: 3000
		initialDelaySeconds: 30
		periodSeconds: 10
		readinessProbe:
		httpGet:
		path: /ready
		port: 3000
		initialDelaySeconds: 5
		periodSeconds: 5

---
# Service
apiVersion: v1
kind: Service
metadata:
	name: my-app-service
	namespace: my-app
spec:
	selector:
		app: my-app
	ports:
	- protocol: TCP
		port: 80
		targetPort: 3000
	type: LoadBalancer

---
# Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
	name: my-app-hpa
	namespace: my-app
spec:
	scaleTargetRef:
		apiVersion: apps/v1
		kind: Deployment
		name: my-app-deployment
	minReplicas: 2
	maxReplicas: 10
	metrics:
	- type: Resource
		resource:
		name: cpu
		target:
		type: Utilization
		averageUtilization: 70
	- type: Resource
		resource:
		name: memory
		target:
		type: Utilization
		averageUtilization: 80

Kubernetes Language Guide

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications across clusters of machines.

Primary Use Cases

  • ▸Orchestrating containerized applications
  • ▸Automating deployment, scaling, and rollback
  • ▸Managing microservices architectures
  • ▸Providing service discovery and load balancing
  • ▸Running hybrid or multi-cloud workloads

Notable Features

  • ▸Automated container scheduling and placement
  • ▸Self-healing via auto-restart, replication, and rescheduling
  • ▸Horizontal scaling of pods based on metrics
  • ▸Declarative configuration with YAML/JSON manifests
  • ▸Extensible API for custom controllers and operators

Origin & Creator

Created by Google in 2014, based on internal Borg system, and now maintained by the Cloud Native Computing Foundation (CNCF).

Industrial Note

Kubernetes is widely used in enterprises and cloud-native environments to manage large-scale microservices, CI/CD pipelines, and automated infrastructure with high availability.

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher