无法使用服务名称

时间:2020-09-04 07:21:32

标签: kubernetes istio

我有本地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时,地址会显示。 (从我的主节点运行)

卷曲:(7)无法连接到myapp端口8088:连接被拒绝

我使用istio服务网格。我在这里想念什么?

我尝试了以下线程:

unable to access services

can not access to exposed services

2 个答案:

答案 0 :(得分:2)

这是正常现象。我可以通过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类型的服务。

PS。我不确定100%。将再次检查是否还有其他选项,并更新此评论。

PS2您可以执行以下操作:

k port-forward svc/dev-my-nginx :80

然后您可以从端口转发的节点中卷曲

答案 1 :(得分:0)

您是否尝试过使用namespace参数?

您可以使用-n参数尝试获取特定名称空间的get services / deployment:

kubectl get svc,deploy -n default

或获取所有名称空间的服务和部署:

kubectl get svc,deploy -A

让我们知道这是否适合您。您也可以在https://console.cloud.google.com/kubernetes/discovery

下在线登录Google控制台