2.8 KiB
2.8 KiB
Create two namespaces and name them ns1 and ns2
k create ns ns1
k create ns ns2
Create a deployment with a single replica in each of these namespaces with the image as nginx and name as deploy-ns1 and deploy-ns2, respectively
k create deployment deploy-ns1 --image=nginx --replicas=1 -n ns1
k create deployment deploy-ns2 --image=nginx --replicas=1 -n ns2
Get the IP address of each of the pods (Remember the kubectl command for that?)
k get po -n ns1 -o wide
k get po -n ns2 -o wide
Exec into the pod of deploy-ns1 and try to curl the IP address of the pod running on deploy-ns2
k exec -it -n ns1 deploy-ns1-56c4d4b7-xzvl2 -- sh
curl 10.244.2.4
Your pod-to-pod connection should work, and you should be able to get a successful response back.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Now scale both of your deployments from 1 to 3 replicas.
k scale --replicas=3 -n ns1 deploy/deploy-ns1
k scale --replicas=3 -n ns2 deploy/deploy-ns2
deploy-ns1-56c4d4b7-xzvl2 10.244.2.3 kind-worker2
deploy-ns2-846f6b4c9b-r85f7 10.244.2.4 kind-worker2
Create two services to expose both of your deployments and name them svc-ns1 and svc-ns2
k expose deployment deploy-ns1 -n ns1 --port=80 --target-port=80
k expose deployment deploy-ns2 -n ns2 --port=80 --target-port=80
exec into each pod and try to curl the IP address of the service running on the other namespace.
k exec -it deploy-ns1-56c4d4b7-4tptj -n ns1 -- sh
curl 10.244.1.6
k exec -it deploy-ns2-846f6b4c9b-7dqwf -n ns2 -- sh
curl 10.244.1.4
This curl should work.
Yes
Now try curling the service name instead of IP. You will notice that you are getting an error and cannot resolve the host.
in deploy-ns2-846f6b4c9b-7dqwf:
curl deploy-ns1-56c4d4b7-4tptj not work
curl deploy-ns2-846f6b4c9b-7dqwf works
Now use the FQDN of the service and try to curl again, this should work.
curl deploy-ns1.ns1.svc.cluster.local
works
In the end, delete both the namespaces, which should delete the services and deployments underneath them.
k delete svc deploy-ns1 -n ns1
k delete svc deploy-ns2 -n ns2
k delete deployment deploy-ns1 -n ns1
k delete deployment deploy-ns2 -n ns2
k delete ns ns1 ns2