[K8S] 在 Kubernetes 裡跑 curl 來測試內部服務
有時會需要測試架在 Kubernetes service 裡的內部網站,
比如說像 https://eck-es-master.svc.cluster.local:9200 這種網址,
在叢集外面是不能存取的。
當然你可以選擇用 port-forward 的方式來存取,
另一種方法就是直接在 K8S 叢集裡跑 curl 囉~
執行下面的指令,來建立一個 curl 的 pod 並進入 shell:
kubectl run curl --image=curlimages/curl -it -- sh
接著就可以在裡面打 curl 指令測試囉:
$ curl -L -v https://eck-es-master.svc.cluster.local:9200 * Trying 10.1.9.70:9200... * Connected to eck-es-master.ssb-elasticsearch.svc.cluster.local (10.1.9.70) port 9200 (#0) * ALPN: offers h2 * ALPN: offers http/1.1 * CAfile: /cacert.pem * CApath: none * [CONN-0-0][CF-SSL] TLSv1.3 (OUT), TLS handshake, Client hello (1): * [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Server hello (2): * [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Certificate (11): * [CONN-0-0][CF-SSL] TLSv1.3 (OUT), TLS alert, unknown CA (560): * SSL certificate problem: unable to get local issuer certificate * Closing connection 0 curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.
如果已經退出了這個 pod,因為我沒有加 --rm
選項,
所以可以隨時 kubectl exec -it curl -- sh
進這個 pod 再來測試囉~
參考資料:How to run curl in Kubernetes (for troubleshooting)
(本頁面已被瀏覽過 580 次)