3

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

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

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

4

2 回答 2

7

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

假设您启用了服务帐户(默认情况下启用),以下是使用curljq来自 pod 内部的 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 中很好地实现这种服务。

于 2016-05-05T11:11:28.040 回答
0

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

于 2016-11-15T07:06:40.783 回答