Zero-Downtime Migration of Kubernetes Deployments: The ExternalName Approach
In production environments, downtime can lead to significant losses. Migrating a critical deployment from the default namespace to a new one without any downtime is essential for maintaining service reliability. The ExternalName service in Kubernetes provides a clean solution to this problem, allowing you to redirect traffic to a new location while keeping existing consumers intact.
The process is straightforward. First, deploy your service in the new namespace. Then, convert the old Service object into an ExternalName service. This service will point to the new deployment's DNS name. For example, you can define the service like this:
1apiVersion: v1
2kind: Service
3metadata:
4 name: auth-svc
5 namespace: default
6spec:
7 type: ExternalName
8 externalName: auth-svc.authentication.svc.cluster.localWith this setup, any consumer still calling auth-svc.default.svc.cluster.local will be silently redirected to the new service in the authentication namespace. Additionally, you may need to annotate the new namespace to bypass duplicate ingress checks during the migration:
1apiVersion: v1
2kind: Namespace
3metadata:
4 name: authentication
5 annotations:
6 policy.example.com/allow-duplicate-ingress: "true"In practice, this method works best when all components interact with services through their DNS names rather than hardcoded IPs or ClusterIPs. Be aware that if any part of your application relies on static IPs, this approach will not be effective. Always test thoroughly in a staging environment before proceeding with production migrations.
Key takeaways
- →Leverage ExternalName services to redirect traffic without downtime.
- →Deploy the new service in a separate namespace before migration.
- →Annotate the new namespace to allow duplicate ingress during migration.
Why it matters
In production, maintaining uptime during migrations is critical for user satisfaction and operational stability. This approach minimizes risk and ensures continuity of service.
Code examples
1apiVersion: v1
2kind: Service
3metadata:
4 name: auth-svc
5 namespace: default
6spec:
7 type: ExternalName
8 externalName: auth-svc.authentication.svc.cluster.local1apiVersion: v1
2kind: Namespace
3metadata:
4 name: authentication
5 annotations:
6 policy.example.com/allow-duplicate-ingress: "true"When NOT to use this
This only works cleanly because everything here talked to auth-svc through its DNS name rather than a hardcoded IP or ClusterIP. If your architecture relies on static IPs, consider alternative migration strategies.
Want the complete reference?
Read official docsIndustry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.
Get CKA certified →Making Platform Engineering More Human with Kubernetes
Platform engineering often feels robotic, but it doesn't have to be. By leveraging Kubernetes for declarative deployments, you can create a more intuitive workflow that aligns with human needs. Discover how a merge to main can streamline your build and deployment process.
Streamline Your EKS Migration with Amazon Bedrock AgentCore
Migrating to Amazon EKS can be daunting, but Amazon Bedrock AgentCore simplifies the process. It evaluates your application’s readiness by analyzing source code and container artifacts, providing a clear migration plan.
Kubernetes v1.37: Embrace Storage Version Migration by Default
Kubernetes v1.37 introduces Storage Version Migration (SVM) enabled by default, simplifying the upgrade path for your custom resources. With a simple declarative object, you can migrate existing resources to the latest API version effortlessly.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.