Code Monkey home page Code Monkey logo

next-hat / nanocl Goto Github PK

View Code? Open in Web Editor NEW
655.0 11.0 37.0 56.08 MB

Distributed System that simplifies the management of containers and virtual machines.

Home Page: https://next-hat.com/nanocl

License: Apache License 2.0

Shell 1.07% Rust 97.01% Dockerfile 1.56% PLpgSQL 0.13% HTML 0.10% Crystal 0.13%
hybrid-cloud self-hosted orchestrator cli containers dns-manager kubernetes-alternative proxy-manager self-hosting virtual-machines vpn-manager distributed networking distributed-systems daemon microservices

nanocl's Introduction

Develop, Distribute

DocsExamplesDiscord

Tests Clippy

codecov

Test, Deploy, Scale, Monitor, Orchestrate

Nanocl is an open-source distributed system designed to revolutionize developers' workflows.
It aims to provide an easy solution for localhost development, addressing common issues like CORS and cookies when working with complex microservice architectures.
Nanocl also facilitates seamless deployment to production.
By empowering developers and DevOps professionals, Nanocl helps optimize workflows, enhance security, and reduce operational costs.

Join our discord and help us shape the future of infrastructure management.

Latest news

Installation

To install Nanocl for your system, please refer to our online installation guide.

Documentation

To learn more about Nanocl, you can take a look at the following resources:

Usage

Nanocl is designed to be easy to operate by mostly using Statefiles.
Statefiles are yaml, toml or json files that define the state you want.
There is an example used to deploy our documentation:

ApiVersion: v0.14

# See all options:
# https://docs.next-hat.com/references/nanocl/objects/cargo
Cargoes:
- Name: doc
  Container:
    Image: ghcr.io/next-hat/documentation:0.14.0

# See all options:
# https://docs.next-hat.com/references/nanocl/objects/resource
Resources:
- Name: docs.next-hat.com
  Kind: ncproxy.io/rule
  Data:
    Rules:
    - Domain: docs.next-hat.com
      Network: Public
      Locations:
      - Path: /
        Target:
          Key: doc.global.c
          Port: 80

To apply a state you can do it easily bu running nanocl state apply -s path|url
You can also remove a state by calling nanocl state rm -s path|url

Demo

Below are live demos of Nanocl in action:

Cargo and Resource

Job

Vm

Architecture

Nanocl is designed in a micro services architecture several component are required and they are running as container included the Nanocl Daemon itself. The following components will be installed during nanocl install and are required to ensure Nanocl functionality:

  • nstore to save our state
  • ndaemon as REST API to manage everything
  • nmetrics to monitor cpu, memory and network usage
  • nproxy proxy to redirect traffic to our containers and virtual machines (optional)
  • ncproxy to update proxy configuration based on the current state (optional)
  • ndns to manage the dns entries for the containers and virtual machines (optional)
  • ncdns to update dns entries based on the current state (optional)

Simplified version of our architecture for a single node:

Contributing

Every contribution is very welcome. Bug reports, feature requests, and pull requests are the most common ways to contribute.

You can also help us by improving the documentation.

Learn how to setup a development environment by reading the contribution guide. Also don't hesitate to join the discord if you have any question!

Sponsors

Sponsors are the ones who make this project possible. They help us to keep the project alive and to improve it. If you want to become a sponsor, you can do so by clicking on the sponsor button.

People that sponsor us will have their name or logo displayed here, and will have access to a special role on our discord server.

If you sponsor for more then 40$ you will be rewarded with a VPS server with nanocl pre-installed ready to use for 1 month.

You can also help us by contributing to the project, by reporting bugs, by suggesting new features, or by improving the documentation.

Or just give a star it's free and it helps us a lot! ⭐️

Huge thanks to our sponsors

mamaicode
Mamaicode
xf10w
xf10w

nanocl's People

Contributors

anonkey avatar creepypvp avatar dependabot[bot] avatar joao-moura avatar leon3s avatar mamaicode avatar narayanbhat166 avatar tyrone-wu avatar zhiburt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nanocl's Issues

Refactor: state apply and revert

Is your feature request related to a problem? Please describe.
We should remove the need of mustache in favor of liquid that will unlock more feature in the future
We should also make the option -f optional and try to look for a StateFile.yml or StateFile.yaml in the current directory !

Bug: Last tabled version doesn't compile

Describe the bug
Nanocl doesn't compile with the latest version of Tabled see #221

To Reproduce
Upgrade Tabled and try to build

Expected behavior
We expect to build with last version

Additional context
It's basically a refactor of the print_table in bin/nanocl/src/utils/print.rs

Openapi: Controller PROXY (ncdproxy)

Is your feature request related to a problem? Please describe.
We should add utoipa to the project and generate the openapi specification when the dev feature is enabled

Bug: Unable to use SSL with coackroachdb and diesel

Describe the bug
I'm unable to use self generated certificate to connect to the database

To Reproduce
Following this tutorial
I generate certificate for the node and the client, but after copying client.root.crt and client.root.key to ~/.postgresql folder i have an connection ssl error

Expected behavior
I expect a connection between my client and my server using a ssl/tls connection

Additional context
You can find the function to connect to the store and the config can be found at:
./bin/nanocld/src/utils/store
./bin/nanocld/specs/store.yml
To generate the ssl certificate you can do it using docker:

docker -v /var/lib/nanocl/store/certs:/certs -v /var/lib/nanocl/store/ca:/ca -it --rm cockroachdb/cockroach:v22.2.6 cockroach cert [...] --certs-dir=/certs --ca-key=/ca/ca.key

Feature: Change the setup command to be able to choose custom image

Is your feature request related to a problem? Please describe.
I'm change how nanocl is setup, right now the daemon start the required services with different configuration depending on if we are in development, test or release. This is now done with a docker compose for development and tests.
For production the nanocl setup command will start required services with the ability to override settings before starting the daemon.

After this change. Even in development, docker compose will have to be used.

Congratulations and questions

I just found out nanocl and I'm still speechless. Thanks for your work!

Since I'm not very experienced I ask you:

  • is it conceivable today to use nanocl instead of kubernetes? (I'm referring to a very simple use of kubernetes: nginx as a reverse-proxy and a few pods (deployments) of simple web applications);

  • are there any dashboards that can be used (even very simple ones)?

  • are there online tutorials/guides?

Refactor: Error handling

Is your feature request related to a problem? Please describe.
Error handling with IoError and HttpError on nanocld_client and nanocl

RFC: ProxyRule

Could be nice to brainstorm about how the resource ProxyRule should be defined.

We should be able to :

  • enable a hostname to target a cargo at specific location using http and https
  • redirect domain to another eg: www.domain.com -> domain.com
  • enable tcp / udp to target a specific cargo at specific port
  • pass extra http header ?

What else should we have ?

This is for now how look look like http and https to target a cargo at specific location:

  • Http

    Resources:
      - Name: resource-example
        Kind: ProxyRule
        Config:
          # List of cargo to watch updates
          Watch:
            - get-started@global
          Http:
            Domain: get-started.com
            Network: Public
            # Optional SSL config
            Ssl:
              Certificate: /path/to/cert
              CertificateKey: /path/to/cert
              DhParam: /path/to/dhparam
            # Http location
            Locations:
              - Path: /
                Target:
                  # The cargo to target for the location
                  Key: get-started@global
                  Port: 9000
  • Stream

    Resources:
        - Name: resource-example
          Kind: ProxyRule
          Config:
            # List of cargo to watch updates
            Watch:
              - get-started@global
            Stream:
              Network: Public
              # The protocol to use Tcp | Udp
              Protocol: Tcp
              Port: 8888
              # Optional SSL config
              Ssl:
                Certificate: /path/to/cert
                CertificateKey: /path/to/cert
                DhParam: /path/to/dhparam
              # Http location
              Target:
                # The cargo to target for the location
                Key: get-started@global
                Port: 9000

Feature: Disable loggin for specific location

Is your feature request related to a problem? Please describe.
The ncdproxy log everything, even if you send credentials for example a login form.
If you don't disable loggin for this specific path the credentials of the user aka login and password, will be in clear text inside the logs.
I want to have loggin enable by default as zero trust policy, but we should give the ability to disable it.

A configuration like this should be considered:

Kind: Deployment
ApiVersion: v0.7

Namespace: global

Resources:
  - Name: deploy-example.com
    Kind: ProxyRule
    Version: v0.4
    Config:
      Watch:
        - deploy-example.global
        - deploy-example2.global
      Rules:
        - Domain: deploy-example.com
          Network: Public
          Locations:
            - Path: /
              Target:
                CargoKey: deploy-example.global
                CargoPort: 9000
            - Path: /users/login
              Target:
                CargoKey: deploy-example.global
                CargoPort: 9000
                Path: /users/login
                DisableLoggin: true

Cargoes:
  - Name: deploy-example
    Container:
      Image: nexthat/nanocl-get-started:latest
      Env:
        - APP=GET_STARTED1

Where Path and DisableLoggin are optinal values.
You have to take a look at nginx.

Feature: Create a type `VirtualMachine` for a State File

Is your feature request related to a problem? Please describe.
Like for cargoes we should be able to create set a virtual machine from a state file

Describe the solution you'd like
Create a new VirtualMachineState model with a new type and accept it inside our state service to create, patch and delete them. The model should be added inside crates/nanocl_stubs/src/state.rs the function to create, patch and delete a virtual machine already exists inside bin/nanocld/src/utils/vm.rs

Feature: Filter cargoes

Describe the solution you'd like
Add a new query parameter to filter cargoes on GET /cargoes :

  • Name: to perform a like on the name
  • Limit: to add a limit
  • Offset: to add an offset

This will be usefull on the dashboard for example to enable data on scroll.

You can see an example on GET /namespaces.

We could also add filter parameters to the cli

Configuration files

We should be able to create cargoes and resources directly from configuration file see examples.
A command on the CLI should be created something like:

nanocl state apply -f examples/resource_example.yml

On the Daemon side the route should directly accept configuration file from examples folder.
We should have an extra parameter to know if we want delete them for example a query paramater.
If the delete parameter is not set we create or update our data based on the configuration file received.

Import container image from tarball.

We should be able to import image from tarball.
Something like:

nanocl cargo image import my-image.tar

That require to add a route in the Daemon and the command in the CLI

Bugfix: `nanocl state apply -a` don't follow logs anymore

Is your feature request related to a problem? Please describe.

Since the refactor of the cargo logs endpoint nanocl state apply -a don't follow logs anymore and it's should.
We need to add the parameters follow to our request.

Feature: Allow network options when creating a namespace

Is your feature request related to a problem? Please describe.
When creating a namespace, we should take extra optionnal parameters to be abble to setup some network options.

Options to add are relation to options for create a network that can be found there

This is a DAEMON and CLI change.

A command like this should be considered:

nanocl namespace create my-namespace --attachable --gateway 172.25.0.1

Choosing the right license for the project

I am opening this issue to decide or set a goal of which license to use for our project.
A license determines how our code can be used, modified, and distributed by others. We need to consider factors such as the goals of the project, the level of openness we want to provide, and any legal requirements that may apply.

Feature: Options to logs cargo

Describe the solution you'd like
Use a new query parameter for cargo logs to enable these features:

  • since: number as unix tmestamp
  • until: number as unix timestamp
  • tail: "all" or number (see bollard types)
  • timestamps: boolean Add timestamps to every log line
  • follow: boolean return a stream or not (optional)

These options should be passed to bollard docker logs function.

We should also add CLI options to use them for example:

nanocl cargo logs my-cargo -f -t 100 --timestamps

Feature: Save nginx logs in database

Is your feature request related to a problem? Please describe.
We should save nginx logs inside the database with a TTL of 4 months ?
The logs have to be well save so we can sort them and be able to generate some statistics

Describe the solution you'd like
We should spawn a thread and watch for logs of our proxy container to save them in the database, we should also change nginx config in order to logs tcp/udp request, right now only http request are logged.

Bug: Namespace `global` and `system` can be deleted

Describe the bug
The namespace global and system can be deleted but it shouldn't be allowed.

To Reproduce
Run:

nanocl namespace rm global

When no cargoes are created in the global namespace.

Expected behavior
This should return an error maybe a 401 because if both of this namespace doesn't exist it can cause unexpected behavior.

This is just a daemon/api change.

Command to execute a command inside a container

We should have a command to run command inside containers.

Something like:

nanocl cargo exec my-container -- my-command

or

nanocl exec my-container -- my-command

This feature include to create a method in the daemon

Feature: Add Virtual Machine definition inside `Deployment` State

Is your feature request related to a problem? Please describe.
We should be able to create, patch and delete virtual machine from a state file

Describe the solution you'd like
Add and Vector of VmConfigPartial inside the DeploymentState model and update the state service to create, patch or delete them the DeploymentState model exists inside crates/nanocl_stubs/src/state.rs the VmConfigPartial models is inside crates/nanocl_stubs/src/vm_config.rs

Feature: Save tcp and udp request inside database

Is your feature request related to a problem? Please describe.
It's already done for http request, we should do it aswell for tcp and udp stream.

This is a daemon change you can see how i did it for inside bin/nanocld/src/utils/proxy.rs
You basically have to create a database model with diesel then create the data when you receive it.
The receive process is already done. The ncdproxy should print a line starting with #STREAM when a tcp / udp request is fired.

Feature: Force delete a namespace

Is your feature request related to a problem? Please describe.
When deleting a namespace we should add a force option in the query to delete all cargoes and virtual machine existing in the namespace.

Additional context
The command should look like this:

nanocl namespace rm -f my-namespace

Beeing able to browse history and reset a cargo or a resource

We should be able to browser history of Cargoes and Resources

A method GET /cargoes/{id}/histories and GET /resources/{id}/histories should be implemented to be able to browse them in the CLI
using those commands :

nanocl cargo history id
nanocl resource history id

Then a method to reset them you be implemented PATCH /cargoes/{cargo_id}/reset/{history_id}} and PATCH /resources/{cargo_id}/reset/{history_id}
That will create a new config from the history id it's basically like a patch but with a config from our history

Then add command like this:

nanocl cargo reset id history_id
nanocl cargo reset id history_id

Feature: Remove the unsecure mode of cockroachdb

We should configure cockroachdb to be ready for multinode.
Remove his unsecure mode with a generated SSL certificat.
We should generate the certificate in the nanocl setup command or in nanocld boot.

Feature: network ipv6 support

Is your feature request related to a problem? Please describe.
When creating a namespace we also are creating a network.
The created network should have ipv6 enabled and actually maybe we should only support ipv6
That will allow us to manage more cargo/container inside a single network

Tests: Improve coverage.

Is your feature request related to a problem? Please describe.
It could be nice to try to improve the code coverage as much as possible.
Arround 75% would be really nice !
You should be able to go on this website to see what is covered or not !

I'll keep this issue open till the goal of 75% is reached.

[BUG] Docker exec cat on big files

Trying to execute both command just produce no output and never end :

nanocl cargo --namespace system exec proxy -- cat /var/log/nginx/error.log
docker exec system-proxy cat /var/log/nginx/error.log

Feature: Create network inside namespace

By default when creating a namespace it will create an associated network and all cargo created will use this network.
End-User may want to create other custom network ?

A command like :

nanocl namespace global network create my-network

or

nanocl network create --namespace global my-network

could be implemented. With associated list remove and inspect methods.

This can improove container network isolation.

RFC: Cargo replication

Could be nice to brainstorm about how we can define a cargo replication.

We should be able to :

  • run only one instance on all nodes
  • run only one instance on targeted nodes
  • run one instance in one node
  • run x defined instances in all node
  • run x defined instances in targeted nodes
  • run x defined instances in one node
  • autoscale on all nodes
  • autoscale on targeted nodes
  • autoscale on one node

What else we should be able to do ?
And how we define the data ?

Example of the enum that came in my mind:

/// Auto is used to automatically define that the number of replicas in the cluster
/// Number is used to manually set the number of replicas
/// Note: auto will ensure at least 1 replica exists in the cluster
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
#[cfg_attr(feature = "dev", derive(ToSchema))]
pub enum ReplicationMode {
  /// Auto is used to automatically define that the number of replicas in the cluster
  /// This will ensure at least 1 replica exists in the cluster
  /// And automatically add more replicas in the cluster if needed for redundancy
  Auto,
  /// Unique is used to ensure that only one replica exists in the cluster
  Unique,
  /// UniqueByNode is used to ensure one replica is running on each node
  UniqueByNode,
  /// UniqueByNodeGroups is used to ensure one replica is running on each node group
  UniqueByNodeGroups { groups: Vec<String> },
  /// UniqueByNodeNames is used to ensure one replica is running on each node name
  UniqueByNodeNames { names: Vec<String> },
  /// Number is used to manually set the number of replicas in one node
  Number(i64),
  /// NumberByNodes is used to manually set the number of replicas in each node
  NumberByNodes(i64),
  /// NumberByNodeGroups is used to manually set the number of replicas in each node group
  NumberByNodeGroups { groups: Vec<String>, number: i64 },
  /// NumberByNodeNames is used to manually set the number of replicas in each node name
  NumberByNodeNames { names: Vec<String>, number: i64 },
}

RFC: DnsRule

Is your feature request related to a problem? Please describe.
To fully unlock the control of the network, we need to think about a spec for the dns controller.
By default we use DNSMASQ

First the data type :

Type: Resource
ApiVersion: v0.5

Resources:
- Name: resource-example
  Kind: DnsRule
  Version: v0.1
  Config:
    Network: "Public" | "Private" | "Nsp.{namespace_name}" # To bind to specific namespace ip address
    Entries:
    - Name: test.com
      IpAddress: "127.0.0.1" | "Nsp.{namespace_name}" # To redirect to specific namespace ip address

We should handle two methods:

  • PUT /rules to create new / update a DnsRule
  • DELETE /rules/{Name} to delete the DnsRule

Creating a rule mean creating a file in this case, nothing have to be stored in database.
That mean we have to create specific dnsmasq config for given resource.

The service should generate an openapi spec aswell.

Feel free to share any though about the config spec for the DnsRule

Feature: Resource kind with url for hook

Is your feature request related to a problem? Please describe.
We have to refactor the way Custom Resource can be created.

Currently we can create custom resource using this method:

Type: Resource
ApiVersion: v0.6

Resources:
  - Name: VpnUser
    Kind: Custom
    Version: v0.1
    Config:
      title: VpnUser
      description: Create a new vpn user
      type: object
      required:
        - Username
      properties:
        Username:
          description: Cargo to watch for changes
          type: string

I want to refactor it so we can add an extra url along the custom schema.
Note: the schema use json schema to be defined.

The refactor i want should access this configuration:

Type: Resource
ApiVersion: v0.6

Resources:
  - Name: VpnUser
    Kind: Kind
    Version: v0.1
    Config:
      Url: my-custom-url.com
      Schema:
        title: VpnUser
        description: Create a new vpn user
        type: object
        required:
          - Username
        properties:
          Username:
            description: Cargo to watch for changes
            type: string

By changing this configuration, ProxyRule and DnsRule should now be defined as Resources and we should ensure they exist during boot time of the daemon. By default they just have and Url property pointing to the url already existing in the project starting with unix://

Note that both Url and Schema property can be optional but if both are unset on the creation of the new Ressource Kind we should return an error.

We should create a custom structure for example ResourceKind.

pub struct ResourceKind {
  pub  url: Option<String>,
  pub schema: Option<serde_json::Value>,
}

Doc: Better developer documentation

Is your feature request related to a problem? Please describe.
I should definitely work on a good developer documentation so people will contribute more easily

Feature: Endpoint to restart a cargo

Is your feature request related to a problem? Please describe.
Considering docker have a restart endpoint, we should implement it aswell for our cargoes,

This is an api / cli change

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.