Bak*_*vic 2 peer kubernetes stellar
我正在尝试在kubernetes上运行私有恒星区块链基础设施(不加入现有的公共或测试恒星网络),但我的问题可以概括为在kubernetes上运行任何对等服务的场景。因此,我将尝试以一种概括的方式来解释我的问题(希望它可以产生适用于kubernetes上运行的任何类似拓扑的答案)。
这是场景:
我想运行3个对等点(以kube术语表示:pod),它们能够以分散的方式相互通信,但是问题在于每个对等点的配置都略有不同。通常,配置如下所示(这是pod0的示例):
NETWORK_PASSPHRASE="my private network"
NODE_SEED=<pod0_private_key>
KNOWN_PEERS=[
"stellar-0",
"stellar-1",
"stellar-2"]
[QUORUM_SET]
VALIDATORS=[ <pod1_pub_key>, <pod2_pub_key> ]
Run Code Online (Sandbox Code Playgroud)
问题在于每个吊舱都有不同的事实:
我的第一个想法(在意识到这个问题之前)是:
另一个想法(在意识到此问题之后)将是:
我想知道是否有更好的解决方案/模式可用于此目的,而不是运行配置完全相同的服务,而配置与作为单独实体(statefulset,deploy ..)的单独实体略有不同,它们可以通过这些对等实体使用(但是这种破坏了使用kubernetes高级资源来实现复制的目的)?
谢谢
因此,您可以拥有一个ConfigMap
带有多个密钥的单个密钥,每个密钥唯一地代表一个副本。您还可以使用StatefulSet
带有的部署Pod initContainer
来设置配置。这只是一个示例(您必须根据需要对其进行调整):
ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: stellar
labels:
app: stellar
data:
stellar0.cnf: |
NETWORK_PASSPHRASE="my private network"
NODE_SEED=<stellar0_private_key>
KNOWN_PEERS=[
"stellar-0",
"stellar-1",
"stellar-2"]
[QUORUM_SET]
VALIDATORS=[ <stellar1_pub_key>, <stellar2_pub_key> ]
stellar1.cnf: |
NETWORK_PASSPHRASE="my private network"
NODE_SEED=<stellar1_private_key>
KNOWN_PEERS=[
"stellar-0",
"stellar-1",
"stellar-2"]
[QUORUM_SET]
VALIDATORS=[ <stellar0_pub_key>, <stellar2_pub_key> ]
stellar2.cnf: |
NETWORK_PASSPHRASE="my private network"
NODE_SEED=<stellar2_private_key>
KNOWN_PEERS=[
"stellar-0",
"stellar-1",
"stellar-2"]
[QUORUM_SET]
VALIDATORS=[ <stellar0_pub_key>, <stellar1_pub_key> ]
Run Code Online (Sandbox Code Playgroud)
StatefulSet:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stellarblockchain
spec:
selector:
matchLabels:
app: stellar
serviceName: stellar
replicas: 3
template:
metadata:
labels:
app: stellar
spec:
initContainers:
- name: init-stellar
image: stellar-image:version
command:
- bash
- "-c"
- |
set -ex
# Generate config from pod ordinal index.
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
# Copy appropriate conf.d files from config-map to emptyDir.
if [[ $ordinal -eq 0 ]]; then
cp /mnt/config-map/stellar0.cnf /mnt/conf.d/
elif [[ $ordinal -eq 1 ]]; then
cp /mnt/config-map/stellar1.cnf /mnt/conf.d/
else
cp /mnt/config-map/stellar2.cnf /mnt/conf.d/
fi
volumeMounts:
- name: conf
mountPath: /mnt/conf.d
- name: config-map
mountPath: /mnt/config-map
containers:
- name: stellar
image: stellar-image:version
ports:
- name: stellar
containerPort: <whatever port you need here>
volumeMounts:
- name: conf
mountPath: /etc/stellar/conf.d <== wherever your config for stellar needs to be
volumes:
- name: conf
emptyDir: {}
- name: config-map
configMap:
name: stellar
Run Code Online (Sandbox Code Playgroud)
服务(如果您需要公开它)
apiVersion: v1
kind: Service
metadata:
name: stellar
labels:
app: stellar
spec:
ports:
- name: stellar
port: <stellar-port>
clusterIP: None
selector:
app: stellar
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!
归档时间: |
|
查看次数: |
245 次 |
最近记录: |