使用Helm在k8s集群上部署以太坊私有链
程序员文章站
2024-03-08 11:43:16
...
一、概述
使用k8s官方的包管理工具helm部署以太坊私有链并启动三类节点和一个前端服务:
- bootnode: used for Geth node discovery
- ethstats: Ethereum Network Stats
- geth-miner: Geth miner nodes
- geth-tx: Geth transaction nodes with mining disabled whose responsbility is to respond to API (websocket, rpc) queries
二、部署流程
(1)helm环境搭建,参考:https://helm.sh
(2)生成Eth帐号和私钥
$ git clone https://github.com/vkobel/ethereum-generate-wallet
$ cd ethereum-generate-wallet
$ pip3 install -r requirements.txt
$ python3 ethereum-wallet-generator.py
Private key: 38000e15ca07309cc2d0b30faaaadb293c45ea222a117e9e9c6a2a9872bb3bcf
Public key: 60758d37d431d34b920847212febbd583008ec2a34d00f907d48bd48b88dc2661806eb99cb6178312d228b2fd08cdb88bafc352d0395ae09b2fe453f0c4403ad
Address: 0xab70383d9207c6cc43ab85eeef9db4d33a8ad4e8
(3)在k8s集群里部署以太坊私有链
helm install --name my-release stable/ethereum
--set geth.account.address=[PUBLIC_ADDRESS]
--set geth.account.privateKey=[PRIVATE_KEY]
--set geth.account.secret=[SECRET]
三、问题记录
(1)集群中helm tiller pod启动失败,因为gcr.io/kubernetes-helm/tiller:v2.8.2镜像无法下载
解决方案:
// 使用私有镜像
helm init --service-account tiller --upgrade -i huwanyang168/tiller:v2.8.0 --skip-refresh
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
(2)unable to do port forwarding: socat not found.
解决方案:登入node,手动安装socat
四、部署检查
(1)集群检查
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-release-ethereum-bootnode-77df55bd8d-984tr 2/2 Running 0 3h
my-release-ethereum-ethstats-66d57558cb-jv4h8 1/1 Running 0 3h
my-release-ethereum-geth-miner-588d49d686-q6prj 1/1 Running 0 3h
my-release-ethereum-geth-miner-588d49d686-w4khs 1/1 Running 0 3h
my-release-ethereum-geth-miner-588d49d686-xwkwj 1/1 Running 0 3h
my-release-ethereum-geth-tx-d86fdbd8d-brx6q 1/1 Running 0 3h
my-release-ethereum-geth-tx-d86fdbd8d-zn692 1/1 Running 0 3h
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 172.16.0.1 <none> 443/TCP 5h
my-release-ethereum-bootnode ClusterIP None <none> 30301/UDP,80/TCP 3h
my-release-ethereum-ethstats LoadBalancer 172.16.193.170 180.76.58.29 80:32585/TCP 3h
my-release-ethereum-geth-tx ClusterIP 172.16.13.205 <none> 8545/TCP,8546/TCP 3h
(2)以太坊私有链检查
// 开启rpc的端口映射
kubectl port-forward my-release-ethereum-geth-tx-d86fdbd8d-brx6q 8545:8545
// 进入geth console
geth attach http://127.0.0.1:8545
// 在console里检查账户及挖矿情况
> eth.accounts[0]
"0xa2fce6f4e4230b3654fad70a37896488f135b8b0"
> eth.getBalance(eth.accounts[0])
1.00366e+24
五、参考
(1)https://hub.kubeapps.com/charts/stable/ethereum
(2)https://www.jianshu.com/p/0ba2ee3ce248
(3)https://github.com/kubernetes/helm