Kubernetes Resource Management

Purpose

This subtopic addresses the automated definition and deployment of Kubernetes resources essential for running blockchain node services, indexers, and APIs within the ShapeShift Unchained platform. It specifically focuses on managing StatefulSets, Services, ConfigMaps, and IngressRoutes, which are critical Kubernetes constructs enabling reliable, scalable, and maintainable operation of blockchain coinstack components.

In the broader context of deployment automation, Kubernetes Resource Management ensures that each blockchain service is correctly containerized, configured, networked, and exposed with appropriate lifecycle management. It solves the problem of consistently and declaratively provisioning these resources across different blockchain coinstacks, environments, and infrastructure providers.

Functionality

At the core of this subtopic is a Pulumi-based TypeScript module that programmatically creates and deploys Kubernetes resource manifests tailored to each blockchain service’s requirements.

Key workflows and methods include:

Example Code Snippet: Creating a Coin Service Definition

const serviceContainer: k8s.types.input.core.v1.Container = {
  name,
  image: args.image,
  command: initScript && !args.command ? ['/init.sh'] : args.command,
  env,
  ports: ports.map(({ port: containerPort, name }) => ({ containerPort, name })),
  startupProbe: startupProbe && { exec: { command: ['/startup.sh'] } },
  livenessProbe: livenessProbe && { exec: { command: ['/liveness.sh'] } },
  readinessProbe: readinessProbe && { exec: { command: ['/readiness.sh'] } },
  volumeMounts: [
    { name: `data-${args.name}`, mountPath: args.dataDir ?? '/data' },
    // Mount lifecycle scripts ConfigMap
    { name: 'config-map', mountPath: '/init.sh', subPath: `${args.name}-init.sh` },
    // ... other lifecycle scripts
  ],
}

Example Code Snippet: Deploying StatefulSet and Services

new k8s.core.v1.Service(
  `${assetName}-svc`,
  {
    metadata: { name: `${assetName}-svc`, namespace, labels },
    spec: { ports, selector: labels, type: 'ClusterIP' },
  },
  { provider, deleteBeforeReplace: true }
)

new k8s.apps.v1.StatefulSet(
  `${assetName}-sts`,
  {
    metadata: { name: `${assetName}-sts`, namespace, labels },
    spec: {
      selector: { matchLabels: labels },
      serviceName: `${assetName}-svc`,
      replicas: config.statefulService.replicas,
      podManagementPolicy: 'Parallel',
      updateStrategy: { type: 'RollingUpdate' },
      template: podSpec,
      volumeClaimTemplates,
    },
  },
  { provider }
)

Integration

Kubernetes Resource Management is a foundational pillar within the Deployment Automation parent topic, responsible for translating high-level blockchain service configurations into concrete Kubernetes resources.

By abstracting Kubernetes resource management into programmable constructs, this subtopic enables consistent, repeatable, and scalable deployments across multiple blockchain nodes and environments, greatly reducing manual configuration and operational error.

Diagram

A flowchart illustrating the core process of Kubernetes resource creation and deployment for blockchain services:

flowchart TD
  Start[Start Deployment] --> LoadConfig[Load Coinstack Config & Env]
  LoadConfig --> CreateServices[Call createCoinService for Each Service]
  CreateServices --> AggregateResources[Aggregate Containers, Ports, ConfigMaps]
  AggregateResources --> CreateK8sObjects[Create Service & ConfigMap Resources]
  CreateK8sObjects --> DeployStatefulSet[Deploy StatefulSet with Volumes & Probes]
  DeployStatefulSet --> SetupIngress[Configure TLS Certificates & IngressRoutes]
  SetupIngress --> Complete[Deployment Complete]

This visualization emphasizes the modular process of converting configuration inputs into fully managed Kubernetes resources supporting blockchain service pods with health checks, storage, networking, and secure external access.