Search⌘ K

Communicating between Namespaces

Explore how to establish communication between Kubernetes namespaces by creating pods and using DNS naming conventions. Understand how services can be accessed across namespaces with the proper DNS format to ensure effective cluster segmentation and isolation.

Creating a Pod

We’ll create an alpine-based Pod that we can use to demonstrate communication between namespaces.

Run the following commands in the widget:

Shell
kubectl config use-context k3d-mycluster
kubectl run test \
--image=alpine \
sleep 10000

We switch to the mycluster context (default namespace) and create a Pod with a container based on the alpine image. We let it sleep for a long time. Otherwise, the container would be without a process and stop almost immediately.

Before we proceed, we should confirm if the Pod is running:

Shell
kubectl get pod test

The output is as follows:

Shell
NAME READY STATUS RESTARTS AGE
test 1/1 Running 0 10m

Please wait a few moments if the Pod is not yet ready. ...