gpt4 book ai didi

kubernetes - 无法使用服务名称访问 kubernetes 服务

转载 作者:行者123 更新时间:2023-12-02 11:38:33 25 4
gpt4 key购买 nike

我有本地 kubernetes 集群。我已经部署了我的应用程序并公开为 ClusterIP服务。

apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
version: v1
spec:
containers:
- name: myapp
image: myrepo:5000/myapp
imagePullPolicy: Always
ports:
- containerPort: 8088
imagePullSecrets:
- name: regcred
我的服务
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: default
labels:
app: myapp
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 8088
targetPort: 8088
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: myapp
spec:
host: myapp
kubectl get svc给出:
myapp      ClusterIP      10.233.41.178   <none>     8088/TCP    13m
我可以 curl使用 ClusterIP 访问我的服务地址,但是当我尝试时 curl http://myapp:8088/api , 它给。 (从我的主节点运行)

curl: (7) Failed to connect to myapp port 8088: Connection refused


我用 istio服务网格。我在这里缺少什么?
我曾尝试以下线程:
unable to access services
can not access to exposed services

最佳答案

这是正常的。我可以通过 nginx 的种类和 1 部署和 clusterIP 类型的一项服务实现相同的状态。

➜  github_api k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dev-my-nginx ClusterIP 10.96.235.85 <none> 80/TCP 3d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d2h
mysql ClusterIP 10.97.143.150 <none> 3306/TCP 2d23h
prod-my-nginx ClusterIP 10.101.89.124 <none> 80/TCP 3d
➜ github_api docker exec -it 212f25f5f073 bash
root@kind-control-plane:/# curl 10.96.235.85
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@kind-control-plane:/# curl dev-my-nginx:80
curl: (6) Could not resolve host: dev-my-nginx
root@kind-control-plane:/#
服务名称仅在集群内部解析,因为 coreDNS(最有可能)只在那里工作。如果您想从每个工作节点访问该服务,请使用 NodePort 类型的服务。
附注。我不是 100% 确定。将仔细检查是否有其他选项并更新此评论。
PS2 您可以执行以下操作:
k port-forward svc/dev-my-nginx :80
然后您可以从端口转发的节点 curl

关于kubernetes - 无法使用服务名称访问 kubernetes 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63736606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com