[英]Not able to curl an http rest api through a k8s service
我有以下部署和服務,但仍然無法在安裝了minikube
的Windows
機器上訪問該服務。
# 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)
嘗試了 minikube ip、clusterip 和 node ip,但都沒有用!
# 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
不確定從哪里開始卷曲,但如果在 Kubernetes 集群內部進行調整,您將只能卷曲這些IP 。
集群 IP 是內部的,您將能夠在內部訪問它,或者內部服務可以使用它來訪問它。
你可以額外運行一個容器來測試這個
kubectl run -it --rm --image=curlimages/curl curly -- sh
命令后嘗試curl <clusterIP>
或 curl helloworld-service
如果你想從主機外部嘗試,你可以檢查 URL
minikube service helloworld-service --url
嘗試一次curl localhost:30008/actuator
對於節點端口,您可以使用命令獲取 minikube IP
minikube ip
curl MinikubeIP:30008
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.