Essential Adjustments for Developers Transitioning from VM, EC2 to Containerization and Deploying on Kubernetes (EKS, AKS, GKE, OCP, etc)
Table of Contents
1. Introduction
2. Probes
โข 2.1 Liveness Probe
โข 2.2 Readiness Probe
โข 2.3 Startup Probe
3. PreStop Hook
4. Graceful Shutdown
5. Application Exit Logic On Errors
6. Externalizing Variables for Better Operational Visibility
7. Communicating Priorities for Running Applications
8. Structured Logging
9. Conclusion
10. Official Documentation Link
1. Introduction
Migrating from EC2 instances to containerization involves adapting your applications to run efficiently in a Kubernetes environment. This transition requires specific adjustments to leverage Kubernetesโ features for managing containerized applications. Below, we explore essential modifications developers should implement during this migration.
2. Probes
Kubernetes uses probes to monitor the state of applications within containers. There are three types of probes:
โข 2.1 Liveness Probe
โข Check if the application is in a healthy state.
โข Kubernetes restarts the container if the application is unhealthy.
โข 2.2 Readiness Probe
โข Verifies if the application is ready to serve requests.
โข Prevents traffic to the application until it passes the readiness check, without restarting the container.
โข 2.3 Startup Probe
โข Monitors the completion of the applicationโs startup phase.
โข Delays liveness checks until the application has fully started, preventing premature restarts.
3. PreStop Hook
This hook allows for a graceful shutdown by processing all pending requests before the container is terminated. A synchronous HTTP call ensures all transactions are completed before Kubernetes sends a SIGTERM signal.
4. Graceful Shutdown
Upon deciding to evict a pod, Kubernetes sends a SIGTERM signal. Applications should gracefully handle this by closing network connections and freeing resources.
5. Application Exit Logic On Errors
Applications should promptly fail and exit on errors, allowing Kubernetes to restart them, rather than waiting for probes to detect an unresponsive state.
6. Externalizing Variables for Better Operational Visibility
Environment variables or config files should define external dependencies, enhancing visibility and control for operations teams. Utilizing ConfigMaps and Projected Volumes for runtime configuration avoids hardcoding and facilitates easier management.
7. Communicating Priorities for Running Applications
Setting priorities lets Kubernetes know which applications to prioritize for scheduling when resources are constrained, ensuring critical services remain available.
8. Structured Logging
Adopting a consistent, structured logging format like JSON with a standardized timestamp format improves log management and analysis, accommodating evolving log content without requiring parser adjustments.
9. Conclusion
Transitioning to Kubernetes from traditional EC2 deployments necessitates adjustments to application management practices. Implementing the described changes ensures applications are resilient, manageable, and scalable within Kubernetes environments.
10. Official Documentation Link
For further information, please refer to the Kubernetes official documentation on pod lifecycle and management practices: Kubernetes Documentation.