nomad concise tutorial

K8s is actually too complicated. For a small team, it takes several manpower just to hold k8s, and the k8s update iteration is too fast. It feels like you can't get down when you get on a thief ship.
nomad is much simpler. It is a scheduler without anything. It seems a little crude. However, it is completely enough for small and medium-sized teams.

Here is a simple comparison between k8s and nomad:

Comparison itemk8snomad
Easy to usecomplexsimple
Conceptual complexitycomplexsecondary
Update iteration speedIt's too fastreasonable
Installation complexitycomplexsimple
Functional richnessrichsimple

Manually install the nomad cluster

Some terms to understand before installation: https://www.nomadproject.io/docs/internals/architecture.html

  • First, you need to download the binary file, wget https://releases.hashicorp.com/nomad/0.9.1/nomad_0.9.1_linux_amd64.zip
  • Then unzip and put the binary file in / usr/local/bin
  • Change user sudo chown root:root /usr/local/bin/nomad
  • Edit / etc / SYSTEMd / system / nomad Service, the content is:
[Unit]
Description=Nomad
Documentation=https://nomadproject.io/docs/
Wants=network-online.target
After=network-online.target

# When using Nomad with Consul it is not necessary to start Consul first. These
# lines start Consul before Nomad as an optimization to avoid Nomad logging
# that Consul is unavailable at startup.
#Wants=consul.service
#After=consul.service

[Service]
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=infinity
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
StartLimitBurst=3
StartLimitIntervalSec=10
TasksMax=infinity

[Install]
WantedBy=multi-user.target
  • Create a folder for storing data sudo mkdir -p /opt/nomad/
  • Create a folder sudo MKDIR - P / etc / nomad d/
  • Create a public configuration. The path is / etc / nomad d/nomad. HCl, the content is:

datacenter is a data center, data_dir is used to store data in the nomad we just created

datacenter = "home"
data_dir = "/opt/nomad"
  • Create the configuration of the server. The path is / etc / nomad d/server. HCl, the content is:

server_ Add all three of our nodes in the join. You can only add yourself, and then add it with commands

server {
  enabled = true
  bootstrap_expect = 3

  server_join {
    retry_join = ["192.168.122.116:4648", "192.168.122.221:4648", "192.168.122.20:4648"]
  }
}
  • Create the configuration of the client. The path is / etc / nomad d/client. HCl, the content is:

Write in the server address and write one, because they will synchronize

client {
  enabled = true
  servers = ["192.168.122.116:4647"]
}

Note that you need to create these before starting nomad. The virtual machine cannot be replicated after startup. If you do this, you will find that nomad server members
There is output, but there is only one nomad node status. The solution is to stop the service of nomad, delete the data of / opt/nomad, and then restart nomad.

After startup, it is found that it has been set up, which is several orders of magnitude simpler than k8s:

jiajun@ubuntu1:~$ nomad server members
Name            Address          Port  Status  Leader  Protocol  Build  Datacenter  Region
ubuntu1.global  192.168.122.116  4648  alive   true    2         0.9.1  home        global
ubuntu2.global  192.168.122.221  4648  alive   false   2         0.9.1  home        global
ubuntu3.global  192.168.122.20   4648  alive   false   2         0.9.1  home        global
jiajun@ubuntu1:~$ nomad node status
ID        DC    Name     Class   Drain  Eligibility  Status
1e1a0cb2  home  ubuntu3  <none>  false  eligible     ready
3afa1c4e  home  ubuntu2  <none>  false  eligible     ready
880defee  home  ubuntu1  <none>  false  eligible     ready

Start a job

Finally set up a nomad cluster and run a job:

job "httpecho" {
    region = "global"
    datacenters = ["home"]
    type = "service"

    group "web" {
        count = 2

        task "server" {
            driver = "docker"

            config {
                image = "hashicorp/http-echo"
                args  = ["-text", "hello world"]
                port_map = {
                    http = 5678
                }
            }

            resources {
                network {
                    mbits = 250

                    port "http" {}
                }
            }
        }
    }
}

Perform the following:

jiajun@ubuntu1:~$ nomad job run httpecho.nomad
==> Monitoring evaluation "ef18e4d2"
    Evaluation triggered by job "httpecho"
    Allocation "20515739" created: node "1e1a0cb2", group "web"
    Allocation "bfa03c3c" created: node "3afa1c4e", group "web"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "ef18e4d2" finished with status "complete"
jiajun@ubuntu1:~$ logout
Connection to 192.168.122.116 closed.
jiajun@idea  ~ $ ansible ubuntu -a 'docker ps -a'
ubuntu3 | CHANGED | rc=0 >>
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                            NAMES
e0c56865dd11        hashicorp/http-echo   "/http-echo -text 'h..."   5 seconds ago       Up 5 seconds        192.168.122.20:27191->5678/tcp, 192.168.122.20:27191->5678/udp   server-20515739-01f9-e7d4-ffff-07b4c64df802

ubuntu2 | CHANGED | rc=0 >>
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
0c3c7a9ad015        hashicorp/http-echo   "/http-echo -text 'h..."   7 seconds ago       Up 6 seconds        192.168.122.221:21704->5678/tcp, 192.168.122.221:21704->5678/udp   server-bfa03c3c-64f3-ca87-4b28-e157ea980181

ubuntu1 | CHANGED | rc=0 >>
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

jiajun@idea  ~ $ http 192.168.122.221:21704
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: text/plain; charset=utf-8
Date: Fri, 31 May 2019 06:34:49 GMT
X-App-Name: http-echo
X-App-Version: 0.2.3

hello world

be accomplished!

summary

In the initial experience, nomad is much better than k8s in ease of use, but there is a problem that hinders the use of medium and large teams: the open source version has namespace support... Unfortunately, unfortunately,
Seeing that the world of container scheduling will be k8s eaten up, it's not quick to release the function to grab a share.

reference material:



Author: Go and Python Institute
Link: https://www.jianshu.com/p/b822ceda022c/
Source: Jianshu
The copyright of Jianshu belongs to the author. Please contact the author for authorization and indicate the source for any form of reprint.

Added by alen on Wed, 22 Dec 2021 16:56:07 +0200