Search code examples
node.jskuberneteshyperledger-fabrichyperledger-fabric-ca

how to configure hyperledger node sdk with kubernetes cluster?


i am able to configure hyperledger fabric and kubernetes with cli. But now i want to configure hyperledger fabric node sdk with kubernetes. I have created with files but, not able to connect it through node sdk rest endpoints.

my hyperledger services:

[ec2-user@ip-172-31-21-223 ~]$ kubectl get services --namespace=fabrick8s
NAME                   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                           AGE
ca0-org1               NodePort   10.110.184.19   <none>        30101:30101/TCP,30102:30102/TCP   26h
orderer0-orgorderer1   NodePort   10.99.12.255    <none>        32000:32000/TCP                   46h
peer0-org1             NodePort   10.101.50.225   <none>        30001:30001/TCP,30002:30002/TCP   3h5m

i have added cluser ip into node network config file but i am not able to connect. getting following error:

[2019-09-12 09:12:08.169] [INFO] SampleWebApp - ****************** SERVER STARTED ************************
[2019-09-12 09:12:08.175] [INFO] SampleWebApp - ***************  http://localhost:4000  ******************
(node:2199) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
[2019-09-12 09:12:16.427] [DEBUG] SampleWebApp -  ------>>>>>> new request for /users
[2019-09-12 09:12:16.428] [DEBUG] SampleWebApp - End point : /users
[2019-09-12 09:12:16.428] [DEBUG] SampleWebApp - User name : test
[2019-09-12 09:12:16.428] [DEBUG] SampleWebApp - Org name  : Org1
[2019-09-12 09:12:16.432] [DEBUG] Helper - getClientForOrg - ****** START Org1 undefined
[2019-09-12 09:12:16.439] [DEBUG] Helper - [NetworkConfig101.js]: constructor, network_config: {"name":"HlfV1","x-type":"hlfv1","description":"Hyperledger Node SDK","version":"1.0","channels":{"mychannel":{"orderers":["orderer0-orgorderer1"],"peers":{"peer0-org1":{"endorsingPeer":true,"chaincodeQuery":true,"ledgerQuery":true,"eventSource":true}},"chaincodes":["mycc:v0"]}},"organizations":{"Org1":{"mspid":"Org1MSP","peers":["peer0-org1"],"certificateAuthorities":["ca0-org1"],"adminPrivateKey":{"path":"/var/lib/nfs-share/crypto-config/peerOrganizations/org1/users/Admin@org1/msp/keystore/a6b8f684b67417335a33972cf115efe2222fdf07de1187cfab36c4873e7591af_sk"},"signedCert":{"path":"/var/lib/nfs-share/crypto-config/peerOrganizations/org1/users/Admin@org1/msp/signcerts/[email protected]"}}},"orderers":{"orderer0-orgorderer1":{"url":"grpcs://localhost:32000","grpcOptions":{"ssl-target-name-override":"orderer0-orgorderer1"},"tlsCACerts":{"path":"/var/lib/nfs-share/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/tls/ca.crt"}}},"peers":{"peer0-org1":{"url":"grpcs://localhost:30001","grpcOptions":{"ssl-target-name-override":"peer0-org1"},"tlsCACerts":{"path":"/var/lib/nfs-share/crypto-config/peerOrganizations/org1/peers/peer0.org1/tls/ca.crt"}}},"certificateAuthorities":{"ca0-org1":{"url":"https://localhost:30101","httpOptions":{"verify":false},"tlsCACerts":{"path":"/var/lib/nfs-share/crypto-config/peerOrganizations/org1/ca/ca.org1-cert.pem"},"registrar":[{"enrollId":"admin","enrollSecret":"adminpw"}],"caName":"ca0-org1"}}}
[2019-09-12 09:12:16.439] [DEBUG] Helper - [NetworkConfig101.js]: constructor, network_config: {"name":"HLF-Framework-Org1","x-type":"hlfv1","description":"HLF-Framework - client definition for Org1","version":"1.0","client":{"organization":"Org1","credentialStore":{"path":"./fabric-client-kv-Org1","cryptoStore":{"path":"/tmp/fabric-client-kv-Org1"},"wallet":"wallet-name"}}}
[2019-09-12 09:12:16.440] [DEBUG] Helper - [NetworkConfig101.js]: mergeSettings - additions start
[2019-09-12 09:12:16.440] [DEBUG] Helper - [NetworkConfig101.js]: getOrganization - name Org1
[2019-09-12 09:12:16.440] [DEBUG] Helper - [Organization.js]: Organization.const
[2019-09-12 09:12:16.441] [DEBUG] Helper - [NetworkConfig101.js]: getCertificateAuthority - name ca0-org1
[2019-09-12 09:12:16.444] [DEBUG] Helper - [CertificateAuthority.js]: CertificateAuthority.const
[2019-09-12 09:12:16.626] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2019-09-12 09:12:16.696] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - start
[2019-09-12 09:12:16.698] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - have the key [Circular]
[2019-09-12 09:12:16.699] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - start
[2019-09-12 09:12:16.701] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - have the key [Circular]
[2019-09-12 09:12:16.701] [DEBUG] Helper - [NetworkConfig101.js]: getOrganization - name Org1
[2019-09-12 09:12:16.702] [DEBUG] Helper - [Organization.js]: Organization.const
[2019-09-12 09:12:16.702] [DEBUG] Helper - [NetworkConfig101.js]: getCertificateAuthority - name ca0-org1
[2019-09-12 09:12:16.702] [DEBUG] Helper - [CertificateAuthority.js]: CertificateAuthority.const
[2019-09-12 09:12:16.703] [DEBUG] Helper - [FileKeyValueStore.js]: constructor { options:
   { path: '/home/ec2-user/kube-node-sdk/fabric-client-kv-Org1',
     wallet: 'wallet-name',
     cryptoStore: { path: '/tmp/fabric-client-kv-Org1' } } }
[2019-09-12 09:12:16.708] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2019-09-12 09:12:16.709] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2019-09-12 09:12:16.709] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2019-09-12 09:12:16.709] [DEBUG] Helper - getClientForOrg - ****** END Org1 undefined


[2019-09-12 09:12:16.709] [DEBUG] Helper - Successfully initialized the credential stores
[2019-09-12 09:12:16.710] [DEBUG] Helper - [FileKeyValueStore.js]: getValue { key: 'test' }
[2019-09-12 09:12:16.716] [INFO] Helper - User test was not enrolled, so we will need an admin user object to register
[2019-09-12 09:12:16.717] [DEBUG] Helper - [FileKeyValueStore.js]: getValue { key: 'admin' }
[2019-09-12 09:12:16.717] [DEBUG] Helper - [NetworkConfig101.js]: getOrganization - name Org1
[2019-09-12 09:12:16.717] [DEBUG] Helper - [Organization.js]: Organization.const
[2019-09-12 09:12:16.717] [DEBUG] Helper - [NetworkConfig101.js]: getCertificateAuthority - name ca0-org1
[2019-09-12 09:12:16.718] [DEBUG] Helper - [CertificateAuthority.js]: CertificateAuthority.const
[2019-09-12 09:12:16.718] [DEBUG] Helper - [NetworkConfig101.js]: getOrganization - name Org1
[2019-09-12 09:12:16.718] [DEBUG] Helper - [Organization.js]: Organization.const
[2019-09-12 09:12:16.718] [DEBUG] Helper - [NetworkConfig101.js]: getCertificateAuthority - name ca0-org1
[2019-09-12 09:12:16.718] [DEBUG] Helper - [CertificateAuthority.js]: CertificateAuthority.const
[2019-09-12 09:12:16.732] [DEBUG] Helper - [FabricCAClient.js]: Successfully constructed Fabric CA client from options - {"caname":"ca0-org1","protocol":"https","hostname":"localhost","port":30101,"tlsOptions":{"trustedRoots":["-----BEGIN CERTIFICATE-----\nMIICIjCCAcigAwIBAgIRANPRopfisvYPfsGHY1tke+MwCgYIKoZIzj0EAwIwWzEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xDTALBgNVBAoTBG9yZzExEDAOBgNVBAMTB2NhLm9yZzEwHhcNMTkw\nNzA5MjMzMDAwWhcNMjkwNzA2MjMzMDAwWjBbMQswCQYDVQQGEwJVUzETMBEGA1UE\nCBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzENMAsGA1UEChME\nb3JnMTEQMA4GA1UEAxMHY2Eub3JnMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBMQsUoC5j79WG1YA0ZgfjnxYkv3TQlFUujWvSpcSG3911uxWBBG8tBxalcY6XubW\ndEk+QNReLYz5XWVclzmJZZujbTBrMA4GA1UdDwEB/wQEAwIBpjAdBgNVHSUEFjAU\nBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQg\nxbTg5ty+qp3Jny2uw/eHWhfPT3w0LrE/MeG74D9Vd2YwCgYIKoZIzj0EAwIDSAAw\nRQIhANJxDvpI0R59X3DLoegKxwpFKKwnA3yhJZCtsoQ4TvPAAiBOKIf3AMpBrfFl\nx9DjYULlHqYcCMCG9jROisk8e0y2uA==\n-----END CERTIFICATE-----\n"],"verify":false}}
[2019-09-12 09:12:16.732] [DEBUG] Helper - [FabricCAClientService.js]: Successfully constructed Fabric CA service client: endpoint - {"protocol":"https","hostname":"localhost","port":30101}
[2019-09-12 09:12:16.785] [DEBUG] Helper - [utils.CryptoKeyStore]: This class requires a CryptoKeyStore to save keys, using the store: {"opts":{"path":"/tmp/fabric-client-kv-Org1"}}
[2019-09-12 09:12:16.785] [DEBUG] Helper - [FileKeyValueStore.js]: constructor { options: { path: '/tmp/fabric-client-kv-Org1' } }
[2019-09-12 09:12:16.786] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore returning ks
[2019-09-12 09:12:16.786] [DEBUG] Helper - [crypto_ecdsa_aes]: generateKey, store.setValue
[2019-09-12 09:12:16.786] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: c93658d3386293eed8cbbd07d9124d7e0bb354ceb1bbbba80099dc9a942b9ed3
[2019-09-12 09:12:16.787] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: 3444c31a9342c0bedae13aff1e5d43ed610ca641a597355e5af25c973708c4ef
[2019-09-12 09:12:16.791] [DEBUG] Helper - [FileKeyValueStore.js]: setValue { key:
   '4ef322eb862cc68caf4341999813959a931baa492a0dcd227f73bf8afa803301-priv' }
[2019-09-12 09:12:16.843] [ERROR] Helper - Failed to get registered user: test with error: Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:30101]
[2019-09-12 09:12:16.843] [DEBUG] SampleWebApp - -- returned from registering the username test for organization Org1
[2019-09-12 09:12:16.843] [DEBUG] SampleWebApp - Failed to register the username test for organization Org1 with::failed Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:30101]

Solution

  • i have given the wrong targetPort.. for CA target port is 7054. solved my issue :)

    apiVersion: v1
    kind: Service
    metadata:
       namespace: fabrick8s
       name: ca0-org1
    spec:
     selector:
       name: ca0-org1
     type: NodePort
     ports:
       - name: grpc
         protocol: TCP
         port: 30101
         targetPort: 7054
         nodePort: 30101