NodePort to a Geth pod doesn't work on k8s

10/3/2020

I'm trying to deploy Geth(ethereum/client-go) pod on k8s. But I can't deploy the pod with error "Fatal: Error starting protocol stack: listen tcp: lookup "192.168.1.10": no such host".

My deploy.yaml is here.

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: chaindatastorage
spec:
  capacity:
    storage: 1000Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-ssd-storage
  local:
    path: /k8sNodeData/ethDataDir
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: disktype
          operator: In
          values:
          - ssd
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: chaindatavolumeclaim
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1000Gi
  storageClassName: local-ssd-storage
---
apiVersion: v1
kind: Service
metadata:
  name: geth-port
spec:
  type: NodePort
  ports:
    - name: geth-sync-port
      port: 30303
      targetPort: 30303
      nodePort: 30303
    - name: geth-rpc-port
      port: 8545
      targetPort: 8545
      nodePort: 8545
  selector:
    name: gethnode
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gethnodedeployment
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gethnode
  template:
    metadata:
      labels:
        name: gethnode
    spec:
      containers:
      - name: gethnode
        image: ethereum/client-go
        args:
        - "--syncmode=full"
        - "--maxpeers=80"
        - "--cache=8192"
        - "--http"
        - "--http.addr=\"192.168.1.10\""
        - "--http.port=8545"
        volumeMounts:
          - name: gethchaindata
            mountPath: /root/.ethereum
        resources:
          limits:
            memory: 20480Mi
            cpu: 4000m
      volumes:
        - name: gethchaindata
          persistentVolumeClaim:
            claimName: chaindatavolumeclaim
---

The results of kubectl get service is here.

NAME                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                         AGE
geth-port                 NodePort    10.110.121.244   <none>        30303:30303/TCP,8545:8545/TCP   78s
kubernetes                ClusterIP   10.96.0.1        <none>        443/TCP                         29d

The results of kubectl get logs of the pod is here.

INFO [10-03|09:40:33.482] Starting Geth on Ethereum mainnet... 
INFO [10-03|09:40:33.483] Maximum peer count                       ETH=80 LES=0 total=80
INFO [10-03|09:40:33.483] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=ledger vendor=11415 failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=trezor vendor=21324 failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=trezor vendor=4617  failcount=1 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=ledger vendor=11415 failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=trezor vendor=21324 failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:33.483] Failed to enumerate USB devices          hub=trezor vendor=4617  failcount=2 err="failed to initialize libusb: libusb: unknown error [code -99]"
INFO [10-03|09:40:33.483] Set global gas cap                       cap=25000000
INFO [10-03|09:40:33.483] Allocated trie memory caches             clean=2.00GiB dirty=2.00GiB
INFO [10-03|09:40:33.483] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=4.00GiB handles=524288
ERROR[10-03|09:40:34.483] Failed to enumerate USB devices          hub=trezor vendor=4617  failcount=3 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:34.483] Failed to enumerate USB devices          hub=trezor vendor=21324 failcount=3 err="failed to initialize libusb: libusb: unknown error [code -99]"
ERROR[10-03|09:40:34.483] Failed to enumerate USB devices          hub=ledger vendor=11415 failcount=3 err="failed to initialize libusb: libusb: unknown error [code -99]"
INFO [10-03|09:40:34.769] Opened ancient database                  database=/root/.ethereum/geth/chaindata/ancient
INFO [10-03|09:40:34.825] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: 7280000 Petersburg: 7280000 Istanbul: 9069000, Muir Glacier: 9200000, YOLO v1: <nil>, Engine: ethash}"
INFO [10-03|09:40:34.825] Disk storage enabled for ethash caches   dir=/root/.ethereum/geth/ethash count=3
INFO [10-03|09:40:34.825] Disk storage enabled for ethash DAGs     dir=/root/.ethash               count=2
INFO [10-03|09:40:34.826] Initialising Ethereum protocol           versions="[65 64 63]" network=1 dbversion=8
INFO [10-03|09:40:37.518] Loaded most recent local header          number=10974617 hash="d28c04…5fe44a" td=17763879313328271327648 age=1d4h43m
INFO [10-03|09:40:37.519] Loaded most recent local full block      number=10973423 hash="92578b…ae09c1" td=17759925126330650308055 age=1d9h14m
INFO [10-03|09:40:37.519] Loaded most recent local fast block      number=10974617 hash="d28c04…5fe44a" td=17763879313328271327648 age=1d4h43m
INFO [10-03|09:40:37.521] Loaded local transaction journal         transactions=0 dropped=0
INFO [10-03|09:40:37.521] Regenerated local transaction journal    transactions=0 accounts=0
INFO [10-03|09:40:37.522] Starting peer-to-peer node               instance=Geth/v1.9.23-unstable-9d1e2027-20200930/linux-amd64/go1.15.2
INFO [10-03|09:40:37.576] New local node record                    seq=52227 id=78ab8e1d111e4ab5 ip=127.0.0.1 udp=30303 tcp=30303
INFO [10-03|09:40:37.577] Started P2P networking                   self=enode://0b9ee2182b4382638cd77fc8b4369d00b4c14cc6c46d4c71d84a9a9fc191cab75c6566b78a42ddcf4a4d00ba9057747588750f518133bf821cd09e69d769ba0b@127.0.0.1:30303
INFO [10-03|09:40:37.580] IPC endpoint opened                      url=/root/.ethereum/geth.ipc
INFO [10-03|09:40:37.581] IPC endpoint closed                      url=/root/.ethereum/geth.ipc
Fatal: Error starting protocol stack: listen tcp: lookup "192.168.1.10": no such host
Fatal: Error starting protocol stack: listen tcp: lookup "192.168.1.10": no such host

When I turned off the - "--http" - "--http.addr=\"192.168.1.10\"" - "--http.port=8545" settings, the pod works without any problems. The pod begins syncing. nping to 192.168.1.10:30303 works without any problems. So I think the format of NodePort setting is correct. I wonder why the pod can't be started only when I add the series of --http settings.

I have already changed the range of port of k8s. So I think the port 30303 and 8545 are not wrong.

I'd like to know where to fix it or the cause of the error.

10/05<br> The result of kubectl get pod -A

NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
default       gethnodedeployment-6f5cd5cf4b-wnqst        1/1     Running   1          20s
default       intelnuc-mysql-deployment-9685c849-q6c9j   1/1     Running   0          6d20h
kube-system   coredns-66bff467f8-gbf9r                   1/1     Running   0          30d
kube-system   coredns-66bff467f8-xg72w                   1/1     Running   0          30d
kube-system   etcd-k8smaster                             1/1     Running   0          30d
kube-system   kube-apiserver-k8smaster                   1/1     Running   1          40h
kube-system   kube-controller-manager-k8smaster          1/1     Running   3          30d
kube-system   kube-flannel-ds-amd64-gcg5c                1/1     Running   0          30d
kube-system   kube-flannel-ds-amd64-mn7zq                1/1     Running   0          17d
kube-system   kube-flannel-ds-amd64-p6lkz                1/1     Running   0          30d
kube-system   kube-proxy-ckfkm                           1/1     Running   0          30d
kube-system   kube-proxy-qhnbn                           1/1     Running   0          17d
kube-system   kube-proxy-rr6b8                           1/1     Running   0          30d
kube-system   kube-scheduler-k8smaster                   1/1     Running   3          30d
-- Pierogi
geth
kubernetes
yaml

1 Answer

10/3/2020

Your deployment is missing a label:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gethnodedeployment

needs to become

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gethnodedeployment
  labels:
    name: gethnode

The label is what the service selector uses to find matching pods.

-- Justin Tamblyn
Source: StackOverflow