Nital
Nital

Reputation: 6114

Not able to curl an http rest api through a k8s service

I have following deployments and service but still not able to access the service on my Windows machine with minikube installed on it.

# kubectl get deployment
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
helloworld-dep   3/3     3            3           9h


# kubectl get pods -o wide
NAME                             READY   STATUS    RESTARTS      AGE    IP           NODE       NOMINATED NODE   READINESS GATES
greet-api-demo                   1/1     Running   2 (23m ago)   6d9h   172.17.0.5   minikube   <none>           <none>
helloworld-dep-f8586dd84-28dxg   1/1     Running   1 (23m ago)   9h     172.17.0.6   minikube   <none>           <none>
helloworld-dep-f8586dd84-p4pg9   1/1     Running   1 (23m ago)   9h     172.17.0.7   minikube   <none>           <none>
helloworld-dep-f8586dd84-tgmcj   1/1     Running   1 (23m ago)   9h     172.17.0.8   minikube   <none>           <none>


# kubectl get services
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
helloworld-service   NodePort    10.96.44.199   <none>        80:30008/TCP   4m1s
kubernetes           ClusterIP   10.96.0.1      <none>        443/TCP        191d


# kubectl logs helloworld-dep-f8586dd84-28dxg
Setting Active Processor Count to 8
Calculating JVM memory based on 11276448K available memory
For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx10889346K -XX:MaxMetaspaceSize=79901K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 11276448K, Thread Count: 50, Loaded Class Count: 11693, Headroom: 0%)
Enabling Java Native Memory Tracking
Adding 124 container CA certificates to JVM truststore
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx10889346K -XX:MaxMetaspaceSize=79901K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.0)

2022-12-23T03:38:53.397Z  INFO 1 --- [           main] com.playground.k8s.K8sDemoApplication    : Starting K8sDemoApplication using Java 17.0.5 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2022-12-23T03:38:53.403Z  INFO 1 --- [           main] com.playground.k8s.K8sDemoApplication    : No active profile set, falling back to 1 default profile: "default"
2022-12-23T03:39:14.389Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-23T03:39:14.648Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-23T03:39:14.650Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-23T03:39:15.883Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-23T03:39:15.888Z  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 21396 ms
2022-12-23T03:39:19.693Z  INFO 1 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2022-12-23T03:39:23.699Z  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-12-23T03:39:25.262Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-23T03:39:25.397Z  INFO 1 --- [           main] com.playground.k8s.K8sDemoApplication    : Started K8sDemoApplication in 35.178 seconds (process running for 38.144)

Tried minikube ip, clusterip and node ip but none of them worked !

# curl http://192.168.49.2:30008/actuator
curl: (28) Failed to connect to 192.168.49.2 port 30008 after 21061 ms: Timed out

# curl http://10.96.44.199:30008/actuator
curl: (28) Failed to connect to 10.96.44.199 port 30008 after 21034 ms: Timed out

# curl http://172.17.0.6:30008/actuator
curl: (28) Failed to connect to 172.17.0.6 port 30008 after 21052 ms: Timed out

Upvotes: 0

Views: 996

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30178

Not sure from where you are truing to hit the curl but you will be only able to curl those IP if truing inside of Kubernetes cluster.

Cluster IP is internal, you will be able to access it internal or internal services can use it to access it.

You can run one container extra to test this

kubectl run -it --rm --image=curlimages/curl curly -- sh

after command try curl <clusterIP> or curl helloworld-service

If you want to try from outside from Host machine you can check URL with

minikube service helloworld-service --url

try once curl localhost:30008/actuator

For node port you can get minikube IP with command

minikube ip


curl MinikubeIP:30008

Upvotes: 1

Related Questions