【问题标题】:Kubernetes get endpointsKubernetes 获取端点
【发布时间】:2016-08-29 16:56:52
【问题描述】:

我有一组提供 nsqlookupd 服务的 pod。 现在我需要每个 nsqd 容器同时拥有一个要连接的 nsqlookupd 服务器列表(而服务每次都会指向不同的服务器)。我得到了类似的东西

kubectl describe service nsqlookupd
...
Endpoints: ....

但我想将它放在我的部署定义中的变量中或以某种方式从 nsqd 容器中

【问题讨论】:

    标签: kubernetes nsq


    【解决方案1】:

    听起来您需要在 nsqd 容器中或在同一 pod 中的单独容器中运行额外的服务。该服务的作用是定期获取 API 以获取端点列表。

    假设您启用了Service Accounts(默认启用),下面是一个使用 pod 内部的 curljq 在 shell 上的概念证明:

    # Read token and CA cert from Service Account
    CACERT="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
    TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
    
    # Replace the namespace ("kube-system") and service name ("kube-dns")
    ENDPOINTS=$(curl -s --cacert "$CACERT" -H "Authorization: Bearer $TOKEN" \
        https://kubernetes.default.svc/api/v1/namespaces/kube-system/endpoints/kube-dns \
    )
    
    # Filter the JSON output
    echo "$ENDPOINTS" | jq -r .subsets[].addresses[].ip
    # output:
    #   10.100.42.3
    #   10.100.67.3
    

    查看 Kube2sky 的源代码,了解在 Go 中这种服务的良好实现。

    【讨论】:

      【解决方案2】:

      可以使用 StatefuSet 来完成。稳定的名字+稳定的存储

      【讨论】:

        猜你喜欢
        • 2021-05-13
        • 2018-09-25
        • 1970-01-01
        • 1970-01-01
        • 2019-05-29
        • 1970-01-01
        • 1970-01-01
        • 2021-07-22
        • 2020-11-18
        相关资源
        最近更新 更多