简体   繁体   English

无法在外部 ip Kube.netes 访问服务

[英]Cannot access service at external ip Kubernetes

I have a problem that I cannot access service with curl althought I have external IP.I meet a timeout request.我有一个问题,虽然我有外部 IP,但我无法使用 curl 访问服务。我遇到超时请求。 Here is my services这是我的服务

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE crawler-manager-1 NodePort 10.103.18.210 192.168.0.10 3001:30029/TCP 2h redis NodePort 10.100.67.138 192.168.0.11 6379:30877/TCP 5h and here my yaml service file: NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE crawler-manager-1 NodePort 10.103.18.210 192.168.0.10 3001:30029/TCP 2h redis NodePort 10.100.67.138 192.168.0.11 6379:30877/TCP 5h TPER文件:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
      convert -f docker-compose.yml
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: crawler-manager-1
  name: crawler-manager-1
  namespace: cbpo-example
spec:
  type: NodePort
  externalIPs:
    - 192.168.0.10
  ports:
  - name: "3001"
    port: 3001
    targetPort: 3001
  selector:
    io.kompose.service: crawler-manager-1
    run: redis
status:
  loadBalancer: {}

Here my deployment yml file这是我的部署 yml 文件

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
      convert -f docker-compose.yml
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: crawler-manager-1
  name: crawler-manager-1
  namespace: cbpo-example
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: crawler-manager-1
    spec:
      hostNetwork: true
      containers:
      - args:
        - npm
        - start
        env:
        - name: DB_HOST
          value: mysql
        - name: DB_NAME
        - name: DB_PASSWORD
        - name: DB_USER
        - name: REDIS_URL
          value: redis://cbpo-redis
        image: localhost:5000/manager
        name: crawler-manager-1
        ports:
        - containerPort: 3001
        resources: {}
      restartPolicy: Always
status: {}

Anyone have a problem like me when work with kube.netes?在使用 kube.netes 时,有人遇到过像我这样的问题吗? I need to access to check if 2 service in my namespace can connect each other, Thanks so much.我需要访问以检查我的命名空间中的 2 个服务是否可以相互连接,非常感谢。

Instead of communication through ip addresses for your services you can communicate with their DNS names. 与其通过IP地址进行服务通信,不如使用其DNS名称进行通信。

“Normal” (not headless) Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. 为“普通”(非无头)服务分配了DNS A记录,该记录的格式为my-svc.my-namespace.svc.cluster.local。 This resolves to the cluster IP of the Service. 这解析为服务的群集IP。

“Headless” (without a cluster IP) Services are also assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. 还为“无头”(无群集IP)服务分配了DNS A记录,该记录的格式为my-svc.my-namespace.svc.cluster.local。 Unlike normal Services, this resolves to the set of IPs of the pods selected by the Service. 与普通服务不同,这解析为该服务选择的Pod的IP集。 Clients are expected to consume the set or else use standard round-robin selection from the set. 希望客户使用该集合,或者使用该集合中的标准循环选择。

For more info, please check Kubernetes DNS for Services 有关更多信息,请检查Kubernetes DNS for Services

Make sure you see end points for the app.确保您看到应用程序的端点。 One reason this can happen is becuase of pod name mismatch.. if i remember, it's selector.name发生这种情况的原因之一是 pod 名称不匹配。如果我记得的话,它是selector.name

 kubectl get endpoints
 NAME         ENDPOINTS            AGE
 kubernetes   192.168.63.13:8080   1d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM