Skip to content

Commit

Permalink
Trying to simplify the provisioners for readability (#17)
Browse files Browse the repository at this point in the history
* Trying to simplify the provisioners for readability

* more scenarios

* Changes to Nomad

* Refactor

* Added README
  • Loading branch information
Ranjandas authored Jun 18, 2024
1 parent 4e8b935 commit 62c4b6e
Show file tree
Hide file tree
Showing 6 changed files with 603 additions and 160 deletions.
71 changes: 71 additions & 0 deletions scenarios/nomad-consul-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Scenario: Nomad Consul Quickstart

This scenario deploys both Nomad and Consul with out any of the security configurations in place. This scenario is useful when you have to play around the features of Nomad (with or without Consul) and not worry about the security aspects.

## Prerequsites

This scenario has the following pre-requsites:

* Shikari and Lima with Socket_VMNet configured
* Requires a base VM image built using packer (`../../packer/hashibox.pkr.hcl`)
* Uses `qemu` driver (you can use `vz` by modifying `vmType` in the template)
* If running enterprise binaries, the Consul and Nomad licenses should be passed as environment variable (shown in the example below)

### Usage

#### Create

Use the following command to launch the scenario using Shikari.

```
$ shikari create --name murphy \
--servers 3 \
--clients 3 \
--env CONSUL_LICENSE=$(cat /location/to/consul/license) \
--env NOMAD_LICENSE=$(cat /location/to/nomad/license) \
--image ../../packer/.artifacts/<imagedir>/<image-file>.qcow2
```

#### List

List the VMs in the cluster

```
shikari list
CLUSTER VM NAME SATUS DISK(GB) MEMORY(GB) CPUS
murphy murphy-cli-01 Running 100 4 4
murphy murphy-cli-02 Running 100 4 4
murphy murphy-cli-03 Running 100 4 4
murphy murphy-srv-01 Running 100 4 4
murphy murphy-srv-02 Running 100 4 4
murphy murphy-srv-03 Running 100 4 4
```

#### Access

You can export the required environment variables to access both Nomad and Consul

```
$ eval $(shikari env -n murphy)
$ consul members
Node Address Status Type Build Protocol DC Partition Segment
lima-murphy-srv-01 192.168.105.13:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-srv-02 192.168.105.12:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-srv-03 192.168.105.11:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-cli-01 192.168.105.10:8301 alive client 1.18.2 2 murphy default <default>
lima-murphy-cli-02 192.168.105.14:8301 alive client 1.18.2 2 murphy default <default>
lima-murphy-cli-03 192.168.105.9:8301 alive client 1.18.2 2 murphy default <default>
$ nomad node status
ID Node Pool DC Name Class Drain Eligibility Status
94665b9b default murphy lima-murphy-cli-01 <none> false eligible ready
83c90834 default murphy lima-murphy-cli-03 <none> false eligible ready
65ecc0ed default murphy lima-murphy-cli-02 <none> false eligible ready
```

#### Destroy

```
$ shikari destroy -f -n murphy
```
173 changes: 70 additions & 103 deletions scenarios/nomad-consul-quickstart/hashibox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,146 +2,114 @@ images:
# Try to use a local image first.
- location: ~/artifacts/qemu/c-1.18-n-1.7/c-1.18-n-1.7.qcow2

mounts: []
containerd:
system: false
user: false

# disable port-mapping, mounts, containerd etc
plain: true

provision:
- mode: system # configure Consul
- mode: system # install Consul and Nomad Licenses if any
script: |
#!/bin/bash
function setConfig {
local mode=$1
local cluster=$2
if [[ -n $CONSUL_LICENSE ]]; then
echo "CONSUL_LICENSE=$CONSUL_LICENSE" > /etc/consul.d/consul.env
fi
if [[ -n $NOMAD_LICENSE ]]; then
echo "NOMAD_LICENSE=$NOMAD_LICENSE" > /etc/nomad.d/nomad.env
fi
- mode: system # Configure Consul common settings
script: |
#!/bin/bash
# Set the config files accordingly
if [[ $mode == "server" ]]; then
# common config for Server and Client
cat <<-EOF > /etc/consul.d/consul.hcl
data_dir = "/opt/consul/data"
log_level = "INFO"
bind_addr = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
client_addr = "0.0.0.0"
retry_join = ["lima-$cluster-srv-01.local"]
datacenter = "$cluster"
retry_join = ["lima-$CLUSTER-srv-01.local"]
datacenter = "$CLUSTER"
ui_config {
enabled = true
}
EOF
- mode: system # Configure Consul server settings
script: |
#!/bin/bash
if [[ $MODE == "server" ]]; then
cat <<-EOF > /etc/consul.d/server.hcl
connect {
enabled = true
}
server = true
bootstrap_expect = $BOOTSTRAP_EXPECT
EOF
fi
elif [[ $mode == "client" ]]; then
cat <<-EOF > /etc/consul.d/consul.hcl
data_dir = "/opt/consul/data"
log_level = "INFO"
bind_addr = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
client_addr = "0.0.0.0"
retry_join = ["lima-$cluster-srv-01.local"]
datacenter = "$cluster"
- mode: system # Configure Consul client settings
script: |
#!/bin/bash
connect {
enabled = true
if [[ $MODE == "client" ]]; then
cat <<-EOF > /etc/consul.d/client.hcl
ports {
grpc = 8502
}
server = false
EOF
else
echo "Invalid mode for setConfig"
fi
}
# Check if the environment variable 'MODE' is set
if [[ -n $MODE ]]; then
echo "MODE is set to: $MODE"
else
echo "MODE is not set."
fi
# Check if the environment variable 'CLUSTER' is set
if [[ -n $CLUSTER ]]; then
echo "CLUSTER is set to: $CLUSTER"
else
echo "CLUSTER is not set."
fi
fi
if [[ -n $CONSUL_LICENSE ]]; then
echo "CONSUL_LICENSE=$CONSUL_LICENSE" > /etc/consul.d/consul.env
fi
setConfig $MODE $CLUSTER
- mode: system # configure Nomad
- mode: system # Configure Nomad common settings
script: |
#!/bin/bash
function setConfig {
local mode=$1
local cluster=$2
# Set the config files accordingly
if [[ $mode == "server" ]]; then
#!/bin/bash
cat <<-EOF > /etc/nomad.d/nomad.hcl
data_dir = "/opt/nomad/data"
bind_addr = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
datacenter = "$CLUSTER"
log_level = "DEBUG"
advertise {
http = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
rpc = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
serf = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
}
EOF
server {
#license_path = "/etc/nomad.d/license.hclic"
enabled = true
bootstrap_expect = $BOOTSTRAP_EXPECT
- mode: system # configure Nomad server settings
script: |
#!/bin/bash
server_join {
retry_join = ["lima-$cluster-srv-01.local"]
}
}
datacenter = "$cluster"
if [[ $MODE == "server" ]]; then
cat <<-EOF > /etc/nomad.d/server.hcl
server {
#license_path = "/etc/nomad.d/license.hclic"
enabled = true
bootstrap_expect = $BOOTSTRAP_EXPECT
client {
enabled = true
servers = ["lima-$cluster-srv-01.local"]
server_join {
retry_join = ["lima-$CLUSTER-srv-01.local"]
}
}
EOF
fi
elif [[ $mode == "client" ]]; then
cat <<-EOF > /etc/nomad.d/nomad.hcl
data_dir = "/opt/nomad/data"
bind_addr = {{ "\"{{ GetInterfaceIP \\\"lima0\\\"}}\"" }}
datacenter = "$cluster"
- mode: system # configure Nomad client settings
script: |
#!/bin/bash
client {
if [[ $MODE == "client" ]]; then
cat <<-EOF > /etc/nomad.d/client.hcl
client {
enabled = true
servers = ["lima-$cluster-srv-01.local"]
}
servers = ["lima-$CLUSTER-srv-01.local"]
}
EOF
else
echo "Invalid mode for setConfig"
fi
}
# Check if the environment variable 'MODE' is set
if [[ -n $MODE ]]; then
echo "MODE is set to: $MODE"
else
echo "MODE is not set."
fi
# Check if the environment variable 'CLUSTER' is set
if [[ -n $CLUSTER ]]; then
echo "CLUSTER is set to: $CLUSTER"
else
echo "CLUSTER is not set."
fi
if [[ -n $NOMAD_LICENSE ]]; then
echo "NOMAD_LICENSE=$NOMAD_LICENSE" > /etc/nomad.d/nomad.env
fi
setConfig $MODE $CLUSTER
fi
- mode:
script: |
systemctl enable --now docker
Expand All @@ -154,4 +122,3 @@ provision:
networks:
- lima: shared
vmType: qemu

71 changes: 71 additions & 0 deletions scenarios/nomad-consul-secure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Scenario: Nomad Consul Quickstart

This scenario deploys both Nomad and Consul with out any of the security configurations in place. This scenario is useful when you have to play around the features of Nomad (with or without Consul) and not worry about the security aspects.

## Prerequsites

This scenario has the following pre-requsites:

* Shikari and Lima with Socket_VMNet configured
* Requires a base VM image built using packer (`../../packer/hashibox.pkr.hcl`)
* Uses `qemu` driver (you can use `vz` by modifying `vmType` in the template)
* If running enterprise binaries, the Consul and Nomad licenses should be passed as environment variable (shown in the example below)

### Usage

#### Create

Use the following command to launch the scenario using Shikari.

```
$ shikari create --name murphy \
--servers 3 \
--clients 3 \
--env CONSUL_LICENSE=$(cat /location/to/consul/license) \
--env NOMAD_LICENSE=$(cat /location/to/nomad/license) \
--image ../../packer/.artifacts/<imagedir>/<image-file>.qcow2
```

#### List

List the VMs in the cluster

```
shikari list
CLUSTER VM NAME SATUS DISK(GB) MEMORY(GB) CPUS
murphy murphy-cli-01 Running 100 4 4
murphy murphy-cli-02 Running 100 4 4
murphy murphy-cli-03 Running 100 4 4
murphy murphy-srv-01 Running 100 4 4
murphy murphy-srv-02 Running 100 4 4
murphy murphy-srv-03 Running 100 4 4
```

#### Access

You can export the required environment variables to access both Nomad and Consul

```
$ eval $(shikari env -n murphy)
$ consul members
Node Address Status Type Build Protocol DC Partition Segment
lima-murphy-srv-01 192.168.105.13:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-srv-02 192.168.105.12:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-srv-03 192.168.105.11:8301 alive server 1.18.2 2 murphy default <all>
lima-murphy-cli-01 192.168.105.10:8301 alive client 1.18.2 2 murphy default <default>
lima-murphy-cli-02 192.168.105.14:8301 alive client 1.18.2 2 murphy default <default>
lima-murphy-cli-03 192.168.105.9:8301 alive client 1.18.2 2 murphy default <default>
$ nomad node status
ID Node Pool DC Name Class Drain Eligibility Status
94665b9b default murphy lima-murphy-cli-01 <none> false eligible ready
83c90834 default murphy lima-murphy-cli-03 <none> false eligible ready
65ecc0ed default murphy lima-murphy-cli-02 <none> false eligible ready
```

#### Destroy

```
$ shikari destroy -f -n murphy
```
Loading

0 comments on commit 62c4b6e

Please sign in to comment.