In Kubernetes, services are usually isolated within namespaces. Which method allows a pod in one namespace to reach a service in another namespace?
Think about how Kubernetes DNS resolves service names across namespaces.
Kubernetes DNS allows cross-namespace communication by using the full DNS name including the namespace. This is service-name.namespace.svc.cluster.local. Using only the service name works only within the same namespace.
You run the following command inside a pod in namespace dev to check connectivity to a service api in namespace prod:
nslookup api.prod.svc.cluster.local
What output do you expect?
Remember how Kubernetes DNS resolves fully qualified service names.
The command queries the fully qualified domain name of the service api in the prod namespace. Kubernetes DNS resolves this correctly and returns the service IP.
You want to restrict network access so only pods in the frontend namespace can connect to pods in the backend namespace on TCP port 8080. Which NetworkPolicy YAML snippet correctly implements this?
NetworkPolicies are defined in the target namespace and use namespaceSelector to allow traffic from other namespaces.
The NetworkPolicy must be created in the backend namespace to control ingress to backend pods. It allows ingress from pods in namespaces labeled name: frontend on TCP port 8080.
A pod in the test namespace tries to connect to a service named db in the prod namespace by using the hostname db. The connection fails. What is the most likely reason?
Think about how DNS resolves service names inside pods.
Using only the service name db resolves to a service in the pod's own namespace (test). To reach a service in another namespace, the full DNS name including namespace must be used.
You manage multiple microservices deployed in different namespaces. You want to enable secure, controlled communication between them. Which approach is best practice?
Consider security, scalability, and maintainability in multi-namespace environments.
Combining NetworkPolicies for network-level restrictions, RBAC for access control, and mutual TLS via a service mesh provides a robust, secure, and manageable way to enable cross-namespace communication.