Skip to content

Environment-separated namespace strategy

The Environment-separated namespace strategy is a deployment and management pattern in Kubernetes that utilizes distinct logical namespaces to isolate resources for different deployment stages, such as testing (Test) and production (Prod).^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]

Implementation Strategy

Under this strategy, resources are segregated into dedicated namespaces. For example, a test namespace may be created for the testing environment, and a prod namespace for the production environment^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. Separating environments in this manner prevents resource conflicts and configuration cross-contamination, such as inadvertently using production configurations in a testing environment^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

This approach supports the core DevOps principle of "packaging once, deploying anywhere" (一次打包,多处部署), as the same container image can be deployed across different namespaces while utilizing environment-specific configurations^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Networking and Service Resolution

Networking configuration plays a crucial role in this strategy. Services within a namespace can communicate with other services in the same namespace using direct DNS names (e.g., http://apollo-configservice:8080)^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. However, to provide a consistent entry point or facilitate cross-namespace communication, external domain names are typically mapped via Ingress resources.

For instance, distinct domains are mapped for different environments to ensure traffic is routed correctly: * Test Environment: config-test.od.com maps to the test configuration service^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. * Production Environment: config-prod.od.com maps to the production configuration service^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Similarly, application ingress rules are configured with specific hostnames like demo-test.od.com and demo-prod.od.com to direct users to the respective environment backends^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Configuration Management

When integrating with a configuration center like [[apollo|Apollo]], the namespace strategy dictates how configuration databases and meta-servers are structured. Each environment typically requires its own dedicated database instance (e.g., ApolloConfigTestDB vs. ApolloConfigProdDB) and specific meta-server URLs^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Applications deployed into these namespaces are configured with environment variables to point to the correct configuration backend. For example, a Pod in the test namespace might receive arguments like -Denv=fat -Dapollo.meta=http://config-test.od.com, while a production Pod would receive -Denv=pro -Dapollo.meta=http://config-prod.od.com^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Sources