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.

Quick Explain

  • ▸Kubernetes provides automated container scheduling, scaling, and self-healing capabilities.
  • ▸Supports declarative configuration via YAML or JSON manifests.
  • ▸Manages container networking, storage, and service discovery automatically.
  • ▸Extensible through custom controllers, operators, and APIs.
  • ▸Facilitates hybrid and multi-cloud deployments for modern cloud-native applications.

Core Features

  • ▸Pods - smallest deployable units in Kubernetes
  • ▸Services - abstract network access to pods
  • ▸Deployments - declarative updates and scaling
  • ▸ConfigMaps and Secrets - configuration and sensitive data management
  • ▸Namespaces - multi-tenancy and resource isolation

Learning Path

  • ▸Learn Docker basics and container concepts
  • ▸Understand Kubernetes architecture and objects
  • ▸Deploy simple pods and services
  • ▸Use Helm and Kustomize for templated deployments
  • ▸Advance to multi-cluster, auto-scaling, and monitoring

Practical Examples

  • ▸Deploy a web application with multiple replicas
  • ▸Configure Ingress for HTTP routing
  • ▸Set up Secrets for database credentials
  • ▸Implement horizontal pod auto-scaling
  • ▸Use Helm charts to package applications

Comparisons

  • ▸Kubernetes vs Docker Swarm: more feature-rich, steeper learning curve
  • ▸Kubernetes vs Nomad: Kubernetes offers extensive ecosystem and flexibility
  • ▸Kubernetes vs OpenShift: OpenShift adds enterprise features and UI
  • ▸Kubernetes vs Rancher: Rancher is management layer for Kubernetes clusters
  • ▸Kubernetes vs ECS: ECS tightly integrated with AWS, Kubernetes is cloud-agnostic

Strengths

  • ▸Highly scalable and resilient
  • ▸Cloud-agnostic and portable
  • ▸Strong ecosystem with tooling and extensions
  • ▸Declarative and automated operations
  • ▸Active community and enterprise support

Limitations

  • ▸Steep learning curve for beginners
  • ▸Operational complexity at scale
  • ▸Debugging issues can be challenging
  • ▸Resource-intensive compared to lightweight orchestrators
  • ▸Requires good understanding of networking and storage concepts

When NOT to Use

  • ▸Small projects without multiple containers
  • ▸Single-node deployments where orchestration is unnecessary
  • ▸Projects without expertise in DevOps or containerization
  • ▸When lightweight container runtimes like Docker Compose suffice
  • ▸Short-lived or experimental deployments without scaling needs

Cheat Sheet

  • ▸kubectl get pods - list pods
  • ▸kubectl describe pod <name> - inspect pod details
  • ▸kubectl apply -f <manifest> - apply YAML configuration
  • ▸kubectl logs <pod> - view pod logs
  • ▸kubectl scale deployment <name> --replicas=3 - scale deployment

FAQ

  • ▸Is Kubernetes open-source? -> Yes, under Apache 2.0 license.
  • ▸Can it run on cloud and on-prem? -> Yes, fully hybrid and cloud-agnostic.
  • ▸Does Kubernetes handle scaling automatically? -> Yes, via HPA/VPA.
  • ▸Is it suitable for microservices? -> Yes, ideal for containerized microservices.
  • ▸How to monitor Kubernetes? -> Use Prometheus, Grafana, and logging stacks.

30-Day Skill Plan

  • ▸Week 1: Deploy simple pod and service on minikube
  • ▸Week 2: Create deployments and manage replicas
  • ▸Week 3: Configure ConfigMaps, Secrets, and volumes
  • ▸Week 4: Implement Ingress and network policies
  • ▸Week 5: Monitor and scale applications, integrate CI/CD

Final Summary

  • ▸Kubernetes is a powerful container orchestration platform for modern cloud-native applications.
  • ▸Automates deployment, scaling, networking, and storage management for containers.
  • ▸Extensible, declarative, and highly resilient.
  • ▸Supports hybrid and multi-cloud environments.
  • ▸Backed by a strong community and ecosystem for enterprise-grade workloads.

Project Structure

  • ▸manifests/ - Kubernetes YAML files
  • ▸charts/ - Helm charts for templated deployments
  • ▸src/ - application code
  • ▸Dockerfile - container build configuration
  • ▸k8s/ - scripts and utilities for cluster management

Monetization

  • ▸Kubernetes is open-source (Apache 2.0)
  • ▸Reduces operational costs via automation
  • ▸Supports cloud-native enterprise workloads
  • ▸Enables hybrid/multi-cloud deployments for business flexibility
  • ▸Ecosystem tools enhance observability and productivity

Productivity Tips

  • ▸Use Helm charts for repeatable deployments
  • ▸Leverage Kustomize for environment customization
  • ▸Apply RBAC and network policies early
  • ▸Automate monitoring and alerts
  • ▸Keep manifests version-controlled and modular

Basic Concepts

  • ▸Pod - group of containers deployed together
  • ▸Node - physical or virtual machine running pods
  • ▸Service - abstraction for exposing pods
  • ▸Deployment - manages pod replicas and updates
  • ▸ConfigMap/Secret - external configuration and sensitive data

Official Docs

  • ▸https://kubernetes.io/docs/
  • ▸Kubernetes GitHub repository
  • ▸CNCF community resources and tutorials

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher