Kubernetes入门到精通-k8s 机器节点上怎么测试POD SVC之间网络

在 Kubernetes 节点上直接请求集群内的 Service HTTPS 端点,有几种方法可以实现。以下是详细的解决方案:
1. 使用 kubectl port-forward(推荐)
这是最简单的方法,将 Service 端口转发到本地:
# 将服务端口转发到本地
kubectl -n elasticweb-system port-forward svc/elasticweb-webhook-service 8443:443 &# 然后在节点上访问本地端口
curl -k https://localhost:8443/mutate-elasticweb-smartagent-online-v1-elasticweb?timeout=10s# 或者使用 wget
wget --no-check-certificate -O- "https://localhost:8443/mutate-elasticweb-smartagent-online-v1-elasticweb?timeout=10s"# 完成后杀掉端口转发进程
kill %1
