Essential Adjustments for Developers Transitioning from VM, EC2 to Containerization and Deploying on Kubernetes (EKS, AKS, GKE, OCP, etc)

Changes Developers Need to Make When Migrating from EC2 to Containerization and Deploying on Kubernetes(EKS)

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.

--

--

๐’๐š๐ค๐ž๐ญ ๐‰๐š๐ข๐ง

๐ƒ๐ž๐ฏ๐Ž๐ฉ๐ฌ/๐’๐‘๐„/๐‚๐ฅ๐จ๐ฎ๐ /๐ˆ๐ง๐Ÿ๐ซ๐š๐ฌ๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐ž /๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ