Lecture Notes on Microservices and Kubernetes
Introduction to Microservices
- Microservices: Architectural style to develop a single application as a suite of small services
- Each service runs its own process and communicates via HTTP or messaging
- Developed and deployed independently
Advantages of Microservices
- Scalability: Services can be scaled independently
- Resilience: Failure of one service doesn't affect others
- Flexibility: Different technologies can be used for different services
- Faster Deployment: Smaller codebase to manage and deploy
Disadvantages of Microservices
- Complexity: Difficult to manage due to decentralization
- Network Latency: Communication over the network can cause delays
- Data Management: Ensuring consistency across services is a challenge
Docker Overview
- Docker: Platform to develop, ship, and run applications in containers
- Containers: Lightweight, portable, and self-sufficient units of software
- Dockerfile: Script containing instructions to build Docker images
- Docker Hub: Cloud-based registry service for sharing Docker images
Kubernetes Overview
- Kubernetes (k8s): System for automating deployment, scaling, and management of containerized applications
- Cluster: Group of nodes where Kubernetes manages containers
- Pods: Smallest deployable units in Kubernetes, which can contain one or more containers
- Services: Abstractions to expose an application running on a set of Pods
- Ingress: Manages external access to services, typically HTTP
Developing a Microservices Application
- Platform Service: REST-based API to manage platforms
- Uses SQL Server for database
- Deployed as a Docker container
- Command Service: REST-based API to manage commands
- Uses in-memory database
- Deployed as a Docker container
- RabbitMQ: Message broker for asynchronous communication
- API Gateway: Manages external access to services
Implementing Synchronous and Asynchronous Communication
- Synchronous Messaging: Direct request/response communication (e.g., HTTP, gRPC)
- Asynchronous Messaging: Event-driven communication using message brokers (e.g., RabbitMQ)
gRPC
- gRPC: High-performance RPC framework using HTTP/2
- Uses Protocol Buffers to define service contracts
- Ideal for service-to-service communication
Kubernetes Deployment
- Deployment Files: YAML files defining desired state of Pods, Services, etc.
- kubectl: Command-line tool to interact with Kubernetes cluster
- Persistent Volume Claims: Request storage resources in Kubernetes
Final Thoughts
- HTTPS/TLS within Kubernetes clusters needs further exploration
- Event processing could be more elegantly designed
- Service discovery could simplify service intercommunication
This course covered the fundamentals of setting up a microservices architecture using Docker and Kubernetes and implementing both synchronous and asynchronous communication between services. The complexity and considerations involved in deploying microservices at scale were emphasized.