代码之家  ›  专栏  ›  技术社区  ›  Some Guy Trying To Do Math

这个Kubernetes服务/pod/docker的URL是什么

  •  0
  • Some Guy Trying To Do Math  · 技术社区  · 5 年前

    我需要将couchDB实例的地址硬编码到kubernetes集群中的另一台服务器。我对kubernetes不太熟悉,但我知道每次重建集群或pod时,IP都会发生变化。所以我不能用它。

    这个kubernetes服务的URL是什么?我应该在服务器Docker镜像中硬编码什么,这样它就可以在系统中始终找到CouchDB服务器。我认为它将采用这种格式

    <service-name>.<namespace>.svc.cluster.local:<service-port>
    

    Picture of the interface

    # YAML for launching the server
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: kino-couch
      labels:
        app: kino-couch
    spec:
      serviceName: orderer
      # Single instance of the Orderer Pod is needed
      replicas: 1
      selector:
        matchLabels:
          app: kino-couch
      template:
        metadata:
          labels:
            app: kino-couch
        spec:
          containers:
          - name: kino-couch
            ports:
            - containerPort: 5984
            # Image used
            image: dpacchain/development:dpaccouch
    

    enter image description here

    如果“wget 172.17.0.2:5984”有效,那么“172.17.0.2”应该替换为什么

    以下内容不正确

    wget kino-couch-0.沙发服务。默认。svc.集群。本地:5984

    wget kino-couch-0.沙发服务。默认。svc.集群。本地:5984

    wget基诺沙发-0基诺沙发。默认。svc。集群。本地:5984

    wget-kino-couch-0.kinocouchdb.default.svc.cluster.local:5984

    wget kino-couch-0 kino-couchdb.svc集群本地:5984

    0 回复  |  直到 5 年前
        1
  •  2
  •   Arghya Sadhu Dharmesh    5 年前

    对于StatefulSet,您需要创建一个 Headless service 负责验证稳定DNS条目的Pod的网络身份。注意事项 clusterIP: None 在下面的示例中。

    apiVersion: v1
    kind: Service
    metadata:
      name: couch-service
      labels:
        app: kino-couch
    spec:
      ports:
      - port: 5984
      clusterIP: None
      selector:
        app: kino-couch
    

    国家需要参考上述服务 serviceName 因此,这位有着坚定立场的yaml应该如下所示

    # YAML for launching the server
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: kino-couch
      labels:
        app: kino-couch
    spec:
      serviceName: couch-service
      # Single instance of the Orderer Pod is needed
      replicas: 1
      selector:
        matchLabels:
          app: kino-couch
      template:
        metadata:
          labels:
            app: kino-couch
        spec:
          containers:
          - name: kino-couch
            ports:
            - containerPort: 5984
            # Image used
            image: dpacchain/development:dpaccouch
    

    然后,作为客户端,您可以使用 couch-service.<namespace>.svc.cluster.local:5984 连接到任何CouchDB Pod。

    如果你想连接到特定的pod,那么使用 kino-couch-0.couch-service.<namespace>.svc.cluster.local:5984 这通常是在couchDB Pod之间连接couchDB pod以创建集群所必需的。

    推荐文章