Skip to content

Networks (networks) ​

The networks block allows you to define custom virtual networks for your infrastructure, ensuring secure and isolated communication between services.

Property Reference ​

PropertyTypeDefaultDescription
cidrstring—Custom IP range in CIDR notation (e.g., 10.0.0.0/16) for the network.
visibilitypublic | privatepublicDefines if the network is reachable from outside the provider's VPC.
vpcIdstring—An existing VPC identifier to attach the network to (Cloud specific).

How it works ​

Nanokit automatically creates a default network for each environment if none is provided. However, explicitly defining networks gives you control over:

  1. Isolation: You can place sensitive databases in a private network while keeping the web gateway in a public one.
  2. Cloud Integration: By providing a vpcId, you can deploy Nanokit services into your existing enterprise infrastructure.
  3. Deterministic IP Ranges: Useful for configuring firewalls or VPNs that require known CIDR blocks.

Example: Public and Private Subnets ​

yaml
networks:
  frontend:
    cidr: 10.0.1.0/24
    visibility: public
  backend:
    cidr: 10.0.2.0/24
    visibility: private

services:
  web:
    image: nginx
    networks:
      - frontend
  
  api:
    image: my-api
    networks:
      - frontend
      - backend

  db:
    image: postgres
    networks:
      - backend

Example: Attaching to Existing AWS VPC ​

yaml
infra:
  provider: aws
  region: us-east-1

networks:
  app-network:
    vpcId: vpc-0a1b2c3d4e5f
    cidr: 10.0.10.0/24

Tip.Inter-service Communication: Services on the same network can reach each other using their service name as the hostname (e.g., api can connect to db:5432).