Deploy the sample resources, and then call the NGINX service by name from the terminal Pod to see how Pods use DNS names to reach a service.
- You have a project with a deployed Kubernetes cluster in the Ready status.
- You have a kubeconfig file for the cluster and a local terminal with kubectl. For more information, see Kubeconfig files in Overview.
- You saved the resources from Sample resources in bootstrap.yaml in a file named bootstrap.yaml.
- Apply the bootstrap.yaml file from your local terminal:
kubectl apply -f ~/path/to/bootstrap.yaml
Replace the path with the location of your file.
- Verify that the resources exist in the default namespace. LiveOps lists the same resources.
kubectl get pods,service
Two Pods are listed, the terminal Pod and an NGINX Pod, and both have the status Running. The test-nginx service of type ClusterIP exposes the NGINX Pod inside the cluster. The terminal Pod needs a short time to install curl before you can use it.
- Open a shell in the terminal Pod. In LiveOps, open the Pods page, open the actions menu of the terminal Pod, and select Open Containers Terminal. Alternatively, run the following command:
kubectl exec -it deploy/terminal -- /bin/sh
The shell runs inside the Pod, inside the cluster. Kubernetes creates DNS records inside Pods automatically to simplify networking between applications.
- In the shell of the terminal Pod, call the service by its name:
The NGINX Pod receives the request and responds with the NGINX welcome page. Inside a namespace, Pods reach a service by using only the name of the service. Pods can also reach services in other namespaces, as described in Communication inside the cluster.