Created a kubernetes
cluster with private topology on aws
using kops
My application exposes several services. As expected, services communicate among each other using their names, i.e. the name
field below:
kind: Service
metadata:
name: myservice
namespace: staging_namespace
Here is the question:
Assuming that I will deploy 2 version of my application (e.g. testing
and staging
) in different namespaces, will this prevent service name collision?
Will namespace separation allow
service1
reach the correct myservice
in staging_namespace
in my staging
deployment
service1
reach the correct myservice
in testing_namespace
in my testing
deployment
?
Using
kops version
Version 1.8.0 (git-5099bc5)
and
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-11T23:27:35Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.4", GitCommit:"9befc2b8928a9426501d3bf62f72849d5cbcd5a3", GitTreeState:"clean", BuildDate:"2017-11-20T05:17:43Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
The simple answer is yes, you can put resources with the same name into separate namespaces and there will be no collision.
As I understand, Namespace is a virtual cluster in k8s cluster, therefore it provides isolation and separation of concern. It does not conflict If you have same services or pods in different namespaces.
All service are assigned a DNS Record which is unique therefore there is no conflict. for instance,
my-svc.my-namespace.svc.cluster.local.
In your case, it would be like this
my-svc.staging_namespace.svc.cluster.local.
my-svc.testing_namespace.svc.cluster.local.
I have attached a link for further research. services-networking
Edit:1
Purpose and Motivation of Namespaces
The functionality of namespace is to provide the logical separation of environments which is providing a uniqueness to k8s resources even being a same pod or service.
Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.