Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to registry service to consul #9

Closed
zh4n7wm opened this issue Mar 31, 2021 · 7 comments
Closed

How to registry service to consul #9

zh4n7wm opened this issue Mar 31, 2021 · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@zh4n7wm
Copy link

zh4n7wm commented Mar 31, 2021

Hi cneira,

The driver can not support register service to consul

job "neverwinter" {
    datacenters = ["dc1"]
    type        = "service"

    group "nwn-group" {
        network {
            mode = "cni/microvms"
        }

        service {
            name = "nwn-service"
            port = 22
            address_mode = "alloc"
            check {
                type = "tcp"
                interval = "10s"
                timeout = "2s"
                address_mode = "alloc"
            }
        }

        task "nwn-server" {
            driver = "firecracker-task-driver"
            config {
                Vcpus = 1
                KernelImage = "/home/cneira/Development/vmlinuxs/vmlinux"
                BootDisk= "/home/cneira/Development/rootfs/ubuntu/18.04/nwnrootfs.ext4"
                Disks = [ "/home/cneira/Development/disks/disk0.ext4:rw" ]
                Mem = 1000
                Network = "microvms"
            }
        }
    }
}

I modify some code, but it's not work correctly.
support-cni-service.txt

note: move support-cni-service.txt support-cni-service.patch

I think I should get the IP Address assigned by group -> network section, then setup taskConfigSpec.Nic.

Could you give me so me advice?

Thx!

@zh4n7wm zh4n7wm changed the title How to config nomad network/service How to registry service to consul Mar 31, 2021
@cneira cneira added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Apr 5, 2021
@cneira
Copy link
Owner

cneira commented Apr 5, 2021

I'll take a look next week, if you solve this before let me know.

@zh4n7wm
Copy link
Author

zh4n7wm commented Apr 21, 2021

I tried but I failed, I can not make it work.

Because I can't get the CNI assigned IP Address.

@cneira cneira added the good first issue Good for newcomers label Apr 26, 2021
@cneira
Copy link
Owner

cneira commented May 5, 2021

@ox0spy I have not checked that yet, but I'm assuming is a CNI more related configuration.
I want to make a couple of updates to the driver this couple of weeks so I could check this problem at the same time.

@cneira cneira self-assigned this May 13, 2021
@cneira cneira added this to the v1.3.0 milestone May 13, 2021
@cneira
Copy link
Owner

cneira commented May 13, 2021

@ox0spy is any of the examples working for you?, the network interface should pickup the ip address provided by your cni network configuration.

@cneira
Copy link
Owner

cneira commented May 18, 2021

@ox0spy
This is working for me I just installed consul and tried the following

job "consul-example" {
  datacenters = ["dc1"]
  type        = "service"
  group "test" {
    restart {
      attempts = 0
      mode     = "fail"
    }
 service {
            name = "nwn-service"
            port = 22
            check {
                type = "tcp"
                interval = "10s"
                timeout = "5s"
            }
        }
    task "nwn" {
     driver = "firecracker-task-driver"
      config {
       Vcpus = 1 
       Mem = 128
       KernelImage= "/home/cneira/kernel-images/vmlinux.bin"
       BootDisk = "/dev/zvol/vms/centos7"
       Network = "default"
      }
    }
  }
}

and I also deploy consul by nomad

job "consul" {
  datacenters = ["dc1"]  group "consul" {
    count = 1
    task "consul" {
      driver = "raw_exec"
            
      config {
        command = "consul"
        args    = ["agent", "-dev"]
      }     
    }
  }
}

I followed this guide https://medium.com/hashicorp-engineering/hashicorp-nomad-from-zero-to-wow-1615345aa539 and the service registers on consul.

@cneira
Copy link
Owner

cneira commented May 18, 2021

@ox0spy feel free to re-open if needed.

@cneira cneira closed this as completed May 18, 2021
@zh4n7wm
Copy link
Author

zh4n7wm commented Jun 16, 2021

@cneira Thanks for your update.

Now also can not support address_mode = "alloc"

cni conf: /etc/cni/conf.d/firecracker.conflist

{
  "name": "firecracker",
  "cniVersion": "0.4.0",
  "plugins": [
    {
      "type": "ptp",
      "ipMasq": true,
      "ipam": {
        "type": "host-local",
        "subnet": "192.168.60.0/24",
        "resolvConf": "/etc/resolv.conf"
      }
    },
    {
      "type": "tc-redirect-tap"
    }
  ]
}

job config

job "hello" {
    datacenters = ["dc1"]
    type = "service"

    group "sshd" {
        network {
            # mode = "cni/mynet"
            port "ssh" {
                to = 22
            }
        }
        service {
            name = "sshd"
            port = "ssh"
            address_mode = "alloc"
            check {
                type = "tcp"
                interval = "10s"
                timeout = "2s"
                address_mode = "alloc"
            }
        }

        task "sshd" {
            driver = "firecracker-task-driver"

            config {
                KernelImage = "/home/ox0spy/projects/nomad/study/firecracker/vmlinux.bin"
                BootDisk = "/home/ox0spy/projects/nomad/study/firecracker/rootfs.ext4"
                Firecracker = "/usr/local/bin/firecracker"
                Vcpus       = 1
                Mem         = 128
                Network     = "firecracker"
            }
        }
    }
}

docs for address_mode in service block: https://www.nomadproject.io/docs/job-specification/service#address_mode

run job

nomad status <alloc-id> got the below error message:

Setup Failure  failed to setup alloc: pre-run hook "group_services" failed: unable to get address for service "sshd": cannot use address_mode="alloc": no allocation network status reported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants