Running Hyperledger Fabric chaincode as an external service

Fabric's supported way to run chaincode outside the peer: an external builder and launcher on each peer, an endpoint and TLS package instead of source, and chaincode servers managed as Kubernetes workloads.

On this page

Running Hyperledger Fabric chaincode as an external service: what it changes for your team

Fabric 2.0 and later let you run chaincode as a service outside the peer, so the chaincode runtime can be managed separately from the peer process. The mechanism is the external builder and launcher, a set of programs the operator attaches to a peer to build, launch and discover chaincode. The Fabric docs describe this model for cloud deployments such as Kubernetes, where a team wants the chaincode workload to follow its own release, scaling and restart rules rather than the peer's.

In the default model, every peer that endorses a chaincode must install and build the package from source, so each organization's peer builds and starts its own copy. With an external service, the package carries only the chaincode server endpoint and TLS artifacts, and per the Fabric docs, installing chaincode on each peer is no longer required. For your team, the practical shift is that the peer's job shrinks to pointing at a reachable service, while the chaincode runtime becomes a workload with its own deployment, logs and health checks. Confirm with your chaincode developers which language runtime and build steps they need inside that workload, since those move with the code.

The trade-off is that the endpoint becomes a dependency. A peer that cannot reach its chaincode server cannot run transactions for that chaincode, so network policy, DNS names and service availability become part of the endorsement path. The Fabric docs call TLS optional but highly recommended outside simple test environments, which means your security team should decide early how certificates for each chaincode server are issued, rotated and trusted by the peer.

What you need before chaincode runs as a service

Running chaincode as an external service touches the peer, the cluster that hosts the chaincode, your certificate authority and the network between them. Each card below is a prerequisite to confirm before you change any peer or chaincode package, so that the first deployment does not depend on assumptions about versions, trust or routing.

Choose the Fabric release line

Decide whether the network stays on the v2.5 LTS line or moves to the 3.x line before you design the chaincode runtime. The Fabric docs name v2.5 as the long-term support release for production users, and both lines receive patch releases in parallel. A 3.x network must already have moved off Kafka ordering, retired v1.x legacy lifecycle chaincode and completed the channel migration steps, so check those first.

Fabric what's new

Peer access to the external builder

The external builder and launcher is configured on each peer, so you need administrative access to the peer's configuration and file system, and a change process that restarts peers in a controlled order. Confirm the exact external builder configuration keys and the directory layout against the Fabric docs for your version, because the keys are version-specific. Record who owns the peer configuration, since it is the piece that decides whether chaincode can be discovered at all.

Chaincode as a service docs

A Kubernetes cluster you control

You need a cluster your team operates, with a supported Kubernetes minor version and a planned upgrade path. Kubernetes maintains the three most recent minor releases, so pick a version inside that window and confirm the end-of-life date before go-live. The control plane should run highly available with an odd number of etcd members, and Kubernetes Secrets that hold chaincode TLS material need encryption at rest, because Secrets are stored unencrypted in etcd by default.

Kubernetes releases

TLS certificates from your CA

Chaincode servers need TLS certificates that peers trust, and those certificates should come from the same certificate authority that issues your network identities so that rotation and revocation follow one process. Confirm who issues the server certificates, the subject names or SANs they carry and how long they are valid. Plan renewal before expiry, because a chaincode server with an expired certificate stops answering peers and the failure appears in peer logs rather than in your monitoring.

Network paths from peers to chaincode

Each peer must reach every chaincode endpoint it is configured to use over the port the chaincode server listens on. Map the routes between the peer's network segment and the cluster, including any network policies, load balancers and firewall rules that sit in between. Confirm the path from a peer pod or host with a connection test before you publish a chaincode package, because a blocked route looks like a chaincode failure during transaction endorsement.

Ownership of chaincode packages

Decide which team builds and publishes the chaincode package, which team holds the endpoint and TLS artifacts, and who approves a change to either. The package contains endpoint information and TLS artifacts rather than source, so a change to the chaincode server address or certificate is a package change that every organization must approve through the channel's chaincode definition process. Write this into your governance policy before the first deployment.

How to configure external chaincode, step by step

This sequence moves chaincode out of each peer and into its own server workload, so peers reach it through an endpoint and TLS artifacts in a package instead of building source locally. The end state is an approved chaincode definition that peers invoke over verified TLS.

  1. Install the external builder and launcher on each peer

    Each peer operator adds the external builder and launcher program to the peer's image or filesystem and points the peer configuration at it, so the peer can run the builder when it processes a chaincode package. This step is done per peer, and the peer team owns it because the change lives in each peer's runtime. Confirm completion by restarting the peer and checking its logs for the external builder being registered without errors. Ask your platform team to confirm how the builder is delivered into the peer image, since this depends on how your peers are packaged.

  2. Build the chaincode server image

    The chaincode developer builds a container image that runs the chaincode as a server listening on a known port, with no dependency on the peer's build tooling. The image is pushed to a registry your cluster can pull from, and its contents are reviewed like any other production workload. Confirm the image by starting it locally or in a test namespace and checking that the server process starts and listens on the expected port.

  3. Deploy the chaincode server as a Kubernetes workload

    The platform team deploys the chaincode server as a Kubernetes Deployment with a Service that exposes the port peers will call, so the chaincode runs independently of every peer. Set the workload's security context and network policy in line with your cluster standards, and store any TLS key material in a Secret your access model covers. Confirm the deployment by checking that the pod reaches the Running state and that the Service resolves from a pod in the peer namespace.

  4. Create the connection.json and metadata.json package

    The chaincode owner writes a connection.json file with the chaincode server address and TLS artifacts, and a metadata.json file that names the chaincode and declares its type as external, then archives both into a chaincode package. Because the package holds endpoint and TLS information and no source code, it is the same package every peer installs. Confirm the package by listing its contents and checking that the address in connection.json matches the Service name and port from the previous step.

  5. Install the package on each peer

    Each peer organization installs the same package with the peer lifecycle commands, and the peer hands the package to its external builder, which records the endpoint and TLS details without compiling anything. Installing on each peer is still required, but the build step that normally runs per peer is removed. Confirm the install by running the installed-chaincode query on each peer and checking that the returned package identifier matches across all peers.

  6. Approve the chaincode definition

    Each organization approves the chaincode definition for the channel, which records the package identifier, endpoint-independent settings and the endorsement policy that governs the chaincode. Approvals are collected until the channel's lifecycle policy is satisfied, and the definition is then committed to the channel. Confirm the commit by querying the committed chaincode definition on the channel and checking that the sequence and version match what the members agreed.

  7. Verify peer-to-chaincode TLS

    The operator confirms that each peer connects to the chaincode server over TLS, using the certificates named in the package and the trust chain the server presents. Check the peer logs for the external chaincode connection and the absence of TLS handshake errors, then send a test invocation and confirm it returns a successful response. Ask your security team to confirm the certificate rotation process, since expired chaincode server certificates will stop invocations.

How a peer reaches an external chaincode server

The diagram starts at the peer, which runs the external builder and launcher to read the endpoint package that holds only the chaincode server address and TLS artifacts, not source code. The peer then opens a connection to the chaincode service running as a Kubernetes workload, and that connection is where the trust boundary sits. Check that both sides present certificates issued by the same CA, and that the chaincode service is reached over mutual TLS rather than left as an optional setting.

Peer to external chaincode server connection, with the trust boundary and issuing CA.

Why removing per-peer builds changes release work

An external chaincode package carries no source code and no build step. Under the documented model, the package contains only the chaincode server endpoint information and TLS artifacts, so each peer no longer needs the chaincode source or a local build of it. In practice, a chaincode release becomes one server image built once by your pipeline, deployed to a runtime you operate, and then referenced by a changed endpoint or TLS artifact in the package. Your release process moves from asking every peer operator to rebuild and install the same code to publishing one artifact and one set of connection details. Peers that were previously the place where builds could drift now have nothing to drift.

The effect on channel work is the part teams most often underestimate. The chaincode definition is still approved by the channel's organizations and committed to the channel, so a new chaincode version still needs the usual sequence of approvals before it runs. What changes is the content being approved: the package identifier, the endpoint and the TLS material, rather than a reference to source that every organization compiled itself. Confirm with the documentation for your Fabric version exactly which lifecycle commands, package identifiers and approval thresholds apply, because the external package format and the sequence of install, approve and commit steps are where version-specific details matter.

Plan the release around ownership. Decide who builds and signs the server image, who controls the endpoint and TLS artifacts, and how each member organization confirms it is connecting to the expected server before approving. Test a server change on a non-production channel first, and keep the previous image and endpoint available so a failed rollout can be reversed through the same approval path. Ask your implementation partner or internal platform team to document each lifecycle step against your Fabric version, since the removed per-peer build also removes a check that peers used to perform implicitly.

Which identities and settings map between peer, chaincode and cluster

This table compares each identity or setting that must line up across the peer, the external chaincode server and the Kubernetes cluster. Read each row as a pairing: the value set on one side must match what the other side expects, or the peer cannot reach the chaincode. Items the docs do not pin down are marked for confirmation with your own environment.

ItemWhere it livesWhat must match
Peer identity and MSP certificatesPeer MSP directory, enrolled by the organization's CAThe peer's enrollment identity must belong to the MSP the channel recognizes for that organization
Chaincode server TLS certificateChaincode server, issued to the endpoint name the peer dialsThe certificate must cover the service name or address placed in connection.json
Peer TLS client materialPeer TLS directory, used when the peer calls the chaincode serverThe chaincode server must trust the CA that signed the peer's TLS client certificate when mutual TLS is enabled
connection.json fieldsInside the external chaincode package (code.tar.gz)Address, dial timeout and TLS settings must point to the Kubernetes service and the certificate files the server actually serves
Kubernetes service name and portCluster service for the chaincode workloadThe address in connection.json must resolve from the peer's namespace or network, so confirm DNS and network policy
Kubernetes secrets holding keysSecrets mounted into the chaincode podSecret names and mount paths must match the chaincode server's configuration, and access should follow least-privilege RBAC
Chaincode definition on the channelChannel configuration, approved by organizations and committed by the lifecycle processThe package ID and chaincode name and version must match the definition approved for each organization, and endpoint details live in the package, not the definition
Peer count and per-peer buildsEach peer's installed chaincode listConfirm that each peer uses the same external package and that no peer needs a source build; check the exact install steps in the docs

Security controls for chaincode servers

An external chaincode server is a network service that peers call, so it inherits the attack surface of any Kubernetes workload. The controls below cover the connection between peer and chaincode, the keys and secrets that connect them, the pod runtime, and the benchmark you review the whole setup against.

TLS between peers and chaincode

The Fabric docs describe TLS as optional but highly recommended outside simple test environments, so treat it as required for any shared or production network. Each chaincode server needs a server certificate and the peer needs the matching trust material in the external chaincode package. Confirm that every chaincode endpoint rejects plaintext connections before you admit real transactions, and test that an expired or wrong certificate fails closed.

External chaincode docs

File-based TLS keys

Fabric's HSM docs say TLS keys must remain file-based even when peer and orderer MSP keys sit in an HSM. Chaincode TLS private keys therefore land on a volume or in a mounted secret, not in an HSM. Decide who can read those files, how they rotate, and whether the mount is read-only. Note that the prebuilt Fabric images are not built with PKCS#11, so MSP keys in an HSM require custom images.

HSM docs

Encryption at rest for Secrets

Kubernetes stores Secrets unencrypted in etcd by default, and that includes the chaincode TLS material you mount into pods. Configure encryption at rest for etcd before the first deployment, and confirm that etcd backups are also encrypted. Ask your platform team who holds etcd snapshot access, since a snapshot exposes every Secret in the cluster.

Secrets good practices

Least-privilege RBAC for Secrets

Restrict list and watch access to Secrets, because a principal that can list Secrets can read every chaincode key in the namespace. Give peer operators, chaincode developers and CI pipelines separate roles, and grant each only the verbs and namespaces it needs. Where secrets come from an external store, the Secrets Store CSI Driver can reduce what sits in the cluster, so review that option against your key custody model.

Pod Security Standards for chaincode pods

Chaincode servers run application code that you did not write for the peer, so they need the same pod hardening as any workload that handles business data. Apply the Pod Security Standards at the namespace level, starting with the restricted profile where the chaincode image allows it. Check that pods run as non-root, drop unneeded capabilities and block privilege escalation, and document any exception with its owner.

Pod Security Standards

Review against the CIS Kubernetes Benchmark

Use the CIS Kubernetes Benchmark as the reference checklist for the cluster that hosts chaincode, and record which recommendations you accept, change or reject with a reason. Run the scan on a schedule, not only at go-live, because cluster upgrades and new namespaces change the results. Ask whether the scan covers the namespaces and nodes that host peers and chaincode, not only the control plane.

CIS Kubernetes Benchmark

How to test an external chaincode rollout before production

Test the external chaincode rollout in a non-production channel before any production approval, and treat each check as a gate that must pass before the next one starts. First, confirm that every peer can reach the chaincode server endpoint recorded in the connection package, from inside the peer's own network namespace and not from a laptop. Then complete a TLS handshake check against that endpoint using the client certificate and CA material the peer will present. The Fabric docs describe TLS as optional but highly recommended outside simple test environments, so the handshake check is where a mismatched CA chain or an expired certificate shows up before it blocks transactions.

After the chaincode definition is approved by the required organizations and committed, invoke a test transaction that exercises read and write paths through each endpoint. Confirm that the endpoint resolves to the expected pod set after a Kubernetes service change, and check the peer logs for launch or connection errors. Use the operations service on peers and the chaincode runtime to read /healthz and /version, adjust log levels through /logspec for the duration of the test, and scrape /metrics into your Prometheus setup. Confirm that mutual TLS client certificates are enforced on those endpoints, since they expose operational detail.

Define the rollback path before the rollout, not during an incident. Keep the previous chaincode package and its connection file available, and confirm with your governance group which approvals are needed to return the definition to the earlier version. Operators own scaling and restarts of chaincode pods, so rehearse pod restarts, replica scale-ups and a forced rollback on the test channel, and time how long each takes in your cluster. Confirm the exact sequence with your Fabric and Kubernetes administrators, because a rollback that depends on a single person's knowledge is not a tested rollback.

Common failures when chaincode runs as an external service

This table lists five failures teams commonly hit when chaincode runs as an external service, with the likely cause and a general fix for each. Use it as a first-pass checklist during deployment or after a change, then confirm the exact messages and config keys against the Fabric version you run.

FailureLikely causeGeneral fix
Builder not found or not executable on the peerThe external builder and launcher is not mounted into the peer container, its path in core.yaml does not match, or the scripts lack execute permission.Confirm the builder directory path in the peer configuration, check that detect, build and release scripts are present and executable inside the running peer, and restart the peer after correcting the path.
connection.json endpoint unreachable from the peer namespaceThe address in connection.json points to a service name, port or namespace the peer cannot resolve, often a service in another namespace or a pod IP that changed.Test name resolution and TCP reachability from the peer pod to the chaincode address, check network policies between namespaces, and confirm the address and port in the package match the service.
TLS certificate mismatch between chaincode server and packageThe certificate or key packaged in the chaincode archive does not match the server certificate, the subject alternative names do not include the address the peer dials, or the CA chain differs.Compare the certificate in the package with the one the server presents, confirm the names in the certificate cover the endpoint, and repackage and reinstall the chaincode after correcting the TLS artifacts.
Chaincode definition not approved by enough organizationsThe chaincode definition was committed before the required number of organizations approved it under the channel's lifecycle endorsement policy, or approvals used a different package ID or sequence number.Query the approval status for each organization using the same definition parameters, have the remaining organizations approve the identical definition, and confirm the package ID and sequence before committing.
Stale endpoint after a Kubernetes service changeThe chaincode service was recreated with a new cluster IP, DNS name or port, while the connection details recorded in the installed package still point to the old value.Keep a stable Service name and port where possible, verify the address after each change, and plan a package update with a new sequence number if the endpoint must change. Confirm the exact update path for your Fabric version.

Questions teams ask before running chaincode as a service

What drives the cost of running Fabric chaincode as an external service?

The cost follows the number of peers, the number of chaincode packages, the number of organizations that must agree on endpoints and TLS material, and the Kubernetes skill available in-house. Each peer that needs a chaincode server adds configuration, testing and monitoring work, and each chaincode definition adds an approval step on the channel. One-time costs include designing the workload layout, building the external builder and launcher setup on peers, writing deployment manifests and testing. Recurring costs include certificate renewal, Kubernetes and Fabric patching, and on-call time. Ask any quote to split these items and to state which parts are paid per peer, per chaincode and per environment.

Can our own team run chaincode as a service without outside help?

A team with Kubernetes operations experience, Fabric administration experience and someone who owns the TLS and certificate process can usually do it alone, and the Fabric documentation describes the mechanism in enough detail to start. The gaps tend to be in certificate lifecycle work across organizations, network policy between member clusters, and testing that proves a chaincode server fails safely. Assess your team against those three areas before deciding. A partner is most useful for a fixed-scope build with written deliverables, followed by a handover so your staff can operate the result.

How long does the work take, and what changes the duration?

No duration is quoted here because it depends on scope rather than a fixed template. The main inputs are the number of peers and organizations, how many chaincode packages move to external services, whether TLS is already in place, whether a Kubernetes cluster exists, and how many change windows your channel governance allows. Each channel approval and each organization's review adds calendar time that engineering effort does not shorten. Ask for a timeline that lists the milestones, the approvals you must give and the test cycles, so you can see which dependencies set the pace.

What does the work need from our organization?

Plan for access and decisions before work starts. You will need cluster access for each organization that runs peers or chaincode, access to the Fabric CA or the process that issues TLS certificates, and a named owner who approves channel configuration and chaincode definition changes. Change windows must be agreed for peer restarts and for any channel update. Each member organization should confirm which endpoints it exposes and which network paths are allowed. Missing any of these usually delays the build more than the engineering work itself.

How do Fabric and Kubernetes upgrades affect a chaincode service setup?

Fabric and Kubernetes upgrades run on separate schedules, so the setup must tolerate both. For Fabric, the upgrade guide describes backing up the ledger and MSPs, upgrading orderer binaries in a rolling fashion, upgrading peer binaries in a rolling fashion, and then updating channel capability levels, which is a separate step. The Fabric Gateway client API is compatible with both v2.5 and v3.0, so client applications can move separately. For Kubernetes, the version skew policy requires the API server to move one minor version at a time before controller manager, scheduler and kubelets, and kubelets may be up to three minor versions older. Check the chaincode image and endpoint configuration against each Fabric and Kubernetes version before you upgrade either one.

Which TLS and certificate work should we expect?

TLS is optional in the Fabric documentation but highly recommended outside simple test environments, so most production setups will require it. Expect work to issue and install certificates for each chaincode server, configure peers to trust the right certificate authority, and renew them before they expire. Plan the rotation procedure in advance, because a chaincode endpoint that fails on certificate expiry stops transactions for every channel that uses it. Confirm with your CA owner which issuer signs these certificates and how revocation is handled.

What testing should be in scope before we go live?

Testing should prove three things: that transactions endorse correctly when the external chaincode server is reachable, that peers fail in a controlled way when the server is down or its certificate is invalid, and that a restart or rescheduling of the Kubernetes workload does not break endorsement. Add a test of the chaincode server's network policy and of any secrets it reads from Kubernetes. Kubernetes stores Secrets unencrypted in etcd by default, so confirm encryption at rest is enabled before the chaincode process depends on them. Ask for test evidence as part of the deliverables.

How DeployOpen scopes and delivers external chaincode

DeployOpen plans, builds, documents and supports external chaincode services inside infrastructure you control, so the chaincode runtime is operated separately from your Fabric peers. We start from a written scope that names the channels, organizations, chaincode packages and clusters involved, then deliver the work with handover material your team can run.

How we scope

  • Inventory which chaincode packages will move to external services and which peers and channels depend on them.
  • Confirm the target Kubernetes clusters, namespaces, ingress and network paths between each member organization's peers and its chaincode servers.
  • Agree in writing how TLS certificates for chaincode endpoints will be issued, rotated and stored before any build begins.

How we build

  • Configure the external builder and launcher on each peer, then verify that builds and launches work before any chaincode moves.
  • Produce connection and TLS packages from chaincode endpoints rather than shipping source, and test them against each peer's installed definitions.
  • Test chaincode server behavior under restarts, certificate rotation and failed endpoints, and record the results against the agreed scope.

How we hand over

  • Deliver runbooks for deploying, scaling and restarting chaincode workloads, with the steps your operators run on each peer.
  • Document the per-organization responsibilities for endpoints, TLS material and chaincode definition approvals so every member knows what it owns.
  • Walk your platform and Fabric teams through the build, rollback and verification steps, and leave them with the configuration that was tested.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, chaincode runtime upgrades and continuous testing are available as a retainer.
  • Confirm with your team which Fabric release line and Kubernetes version your network will run before a retainer scope is written.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.