kubernetes - 无法通过 kubectl 代理打开服务
问题描述
➜ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
airflow-flower-service ClusterIP 172.20.119.107 <none> 5555/TCP 54d
airflow-service ClusterIP 172.20.76.63 <none> 80/TCP 54d
backend-service ClusterIP 172.20.39.154 <none> 80/TCP 54d
➜ kubectl proxy
xdg-open http://127.0.0.1:8001/api/v1/namespaces/edna/services/http:airflow-service:/proxy/#q=ip-192-168-114-35
它失败了
Error trying to reach service: 'dial tcp 10.0.102.174:80: i/o timeout'
但是,如果我通过 kubectl port-forward 公开服务,我可以在浏览器中打开服务
kubectl port-forward service/backend-service 8080:80 -n edna
xdg-open HTTP://localhost:8080
那么如何通过那个长 URL 打开服务(类似于我们打开 kubernetes 仪表板的方式?
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/overview?namespace=default
如果我使用 CURL 查询 API,我会看到输出
➜ curl http://127.0.0.1:8001/api/v1/namespaces/edna/services/backend-service/
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "backend-service",
"namespace": "edna",
"selfLink": "/api/v1/namespaces/edna/services/backend-service",
"uid": "7163dd4e-e76d-4517-b0fe-d2d516b5dc16",
"resourceVersion": "6433582",
"creationTimestamp": "2020-08-14T05:58:45Z",
"labels": {
"app.kubernetes.io/instance": "backend-etl"
},
"annotations": {
"argocd.argoproj.io/sync-wave": "10",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{\"argocd.argoproj.io/sync-wave\":\"10\"},\"labels\":{\"app.kubernetes.io/instance\":\"backend-etl\"},\"name\":\"backend-service\",\"namespace\":\"edna\"},\"spec\":{\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":80}],\"selector\":{\"app\":\"edna-backend\"},\"type\":\"ClusterIP\"}}\n"
}
},
"spec": {
"ports": [
{
"protocol": "TCP",
"port": 80,
"targetPort": 80
}
],
"selector": {
"app": "edna-backend"
},
"clusterIP": "172.20.39.154",
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {
}
}
}
解决方案
推荐阅读
- ios - 如何阻止 SwiftUI 应用程序重置表单数据?
- mongodb - 如何使用 ISODate 在 Rust / Mongodb 中进行查询?
- r - 如何让“while”代码块在达到阈值结束后自行停止终止?
- sql - 查询返回 count(*) 为零的行
- python - 在 python 解释器中使用 for 循环
- java - 处理后如何移动成功/失败的 Azure Blob?
- flutter - 调用 showSlideDialog 时上下文和提供程序出错
- python - 为什么在某行末尾加上逗号时,下一个编码行会出现新错误?
- autosar - 自适应 AUTOSAR 的安全 ASIL 目标?
- c++ - 在 C++ 中运行时加载 QML 字节码