Skip to content
Next Hat
All Statefiles
Nanocl v0.18Statefile 0.1.0

Wireguard

Deploy a Wireguard VPN server using LinuxServer.io image.

Description

This cargo deploys a Wireguard VPN server using the popular LinuxServer.io Wireguard image. It allows you to easily set up and manage a secure VPN server for your network. You can configure users, DNS settings, and other options through environment variables and arguments. The Wireguard configuration files are stored on the host for persistence and easy access.

We recommand to create a .env with the WG_USERS variable to avoid exposing it in the cargo file. Example .env content:

CODE
WG_USERS=user1,user2,user3

Synopsis

SH
nanocl state apply -s nr.next-hat.com/v0.18/wireguard/0.1.0 -- [--help] ARGUMENTS
nanocl state rm -s nr.next-hat.com/v0.18/wireguard/0.1.0 -- [--help] ARGUMENTS

Arguments

ArgumentTypeDescriptionDefault
--namespace
Optional
StringNanocl namespace where to deploy the cargo.wireguard
--puid
Optional
StringUser ID for the Wireguard process inside the container.1000
--pgid
Optional
StringGroup ID for the Wireguard process inside the container.1000
--dns
Optional
StringDNS server to use for the VPN clients.1.1.1.1
--config-path
Optional
StringPath on the host where to store the Wireguard configuration files./opt/containers/wireguard

Render locally

Render this Statefile and save the result to Statefile.yml for review before applying it.

Pass any required Statefile arguments after --.

SH
nanocl state render -s nr.next-hat.com/v0.18/wireguard/0.1.0 -o Statefile.yml

Content

YAML
ApiVersion: v0.18
Args:
  - Name: namespace
    Kind: String
    Default: wireguard
    Description: Nanocl namespace where to deploy the cargo.
  - Name: puid
    Kind: String
    Default: 1000
    Description: User ID for the Wireguard process inside the container.
  - Name: pgid
    Kind: String
    Default: 1000
    Description: Group ID for the Wireguard process inside the container.
  - Name: dns
    Kind: String
    Default: 1.1.1.1
    Description: DNS server to use for the VPN clients.
  - Name: config-path
    Kind: String
    Default: /opt/containers/wireguard
    Description: Path on the host where to store the Wireguard configuration files.
Namespace: ${{ Args.namespace }}
Cargoes:
  - Name: wgsrv
    PortBindings:
      51820/udp:
        - HostPort: '51820'
    Dns:
      - $$INTERNAL_GATEWAY
      - ${{ Args.dns }}
    Containers:
      - Name: wireguard
        Image: lscr.io/linuxserver/wireguard:latest
        Cmd:
          - -c
          - SERVERURL=$NANOCL_NODE_ADDR sh /init
        Env:
          - PUID=${{ Args.puid }}
          - PGID=${{ Args.pgid }}
          - PEERS=${{ Envs.WG_USERS }}
          - PERSISTENTKEEPALIVE_PEERS=all
        HostConfig:
          CapAdd:
            - NET_ADMIN
          Binds:
            - ${{ Args.config-path }}/config:/config
          Sysctls:
            net.ipv4.ip_forward: '1'