How testing a pod located in different namespace
Problem: I want to test a pod located in one namespace — data — to do a curl on it.
Solution: Create a new pod based on image=tutum/curl. The container will complete and the pod will be die/exit
kubectl run curl -i — tty — rm — image=tutum/curl — sh -c “curl -v dummy-pod.data.svc.cluster.local; exit 1”
or
kubectl run curl -i — tty — rm — image=tutum/curl — sh -c “for i in {1..10}; do sleep 1;curl dummy-pod.data.svc.cluster.local; done; exit 1”
the ouput:
❯ kubectl run curl -i — tty — rm — image=tutum/curl — sh -c “curl -v auth-db.data.svc.cluster.local; exit 1”
If you don’t see a command prompt, try pressing enter.
Error attaching, falling back to logs:
* Rebuilt URL to: auth-db.data.svc.cluster.local/
* Hostname was NOT found in DNS cache
* Trying 10.111.136.120…
* Connected to auth-db.data.svc.cluster.local (10.111.136.120) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: auth-db.data.svc.cluster.local
> Accept: */*
>
< HTTP/1.1 200 OK
* Server nginx/1.19.1 is not blacklisted
< Server: nginx/1.19.1
< Date: Fri, 22 Jan 2021 09:41:48 GMT
< Content-Type: text/html
< Content-Length: 612
< Last-Modified: Tue, 07 Jul 2020 15:52:25 GMT
< Connection: keep-alive
< ETag: “5f049a39–264”
< Accept-Ranges: bytes
<
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>
* Connection #0 to host auth-db.data.svc.cluster.local left intact
pod “curl” deleted
To communicate from one pod to another pod, we need a service. When you create a service, an endpoint is created, and you communicate with the other pod using the endpoint and the services. In this case, as the pod is in another namespace, you need to specify the fully-qualified name of the service.
With this instructions, when the pod start execute the above curl commands.
<service-name>.<namespace>.svc.cluster.local
Happy coding!