I am trying to send a curl request to a Kubernetes ClusterType service. Is there any way to perform curl requests to service?
I am deploying an application with Blue/Green deployment. So here need to verify the Blue version is properly working or not. So decide to send a curl request to the blue version. When I get 200 status, I will route all traffic to this version.
But now am facing that send curl request to the new version(Blue version) of the application.
You can't send a curl request to ClusterType Service, unless you are inside the cluster, you can run a pod to do that e.g
kubectl run --rm --image nginx -i -- curl 'http://clusterip/'
This will run a temp pod to run your command and die afterward.
ClusterIP makes the Service only reachable from within the cluster. This is the default ServiceType. You can read more information about services here.
As the command in the first answer doesn't work, I'm posting the working solution:
kubectl run tmp-name --rm --image nginx -i --restart=Never -- /bin/bash -c 'curl -s clusterip:port'
with the above command curl is working fine. You can use a service name instead of cluster IP address.
--restart=Never
is needed for using curl like this.
--rm
ensures the Pod is deleted when the shell exits.
kubectl port-forward service/yourClusterIpServiceName 28015:yourClusterIpPort
You will get output like this:
Forwarding from 127.0.0.1:28015 -> yourClusterIpPort
Forwarding from [::1]:28015 -> yourClusterIpPort
after that you will be able to reach your ClusterIP service using this command:
curl localhost:28015
More information about port forwarding is on the official documentation page.