Merge pull request 'NomadでConsul Connectジョブを利用できるようにする' (#3) from nomad-modify into master

Reviewed-on: #3
This commit is contained in:
Kazuhiro MUSASHI 2022-03-14 14:22:17 +00:00
commit 6ed1e9cf90
7 changed files with 164 additions and 21 deletions

View File

@ -5,6 +5,4 @@ include_recipe './install.rb'
if node['nomad']['manager'] || node['nomad']['client']
include_recipe './setup.rb'
include_recipe './csi.rb'
include_recipe './shared_dir.rb'
end

View File

@ -1,3 +1,11 @@
client {
enabled = true
meta {
connect.log_level = "debug"
}
}
# consul {
# token = "11800359-1330-fe54-d858-44e8de9a14f6"
# }

View File

@ -0,0 +1,8 @@
Kind = "service-intentions"
Name = "count-api"
Sources = [
{
Name = "count-dashboard"
Action = "allow"
}
]

View File

@ -0,0 +1,98 @@
job "countdash" {
datacenters = ["dc1"]
group "api" {
network {
mode = "bridge"
port "envoy_metrics" {
to = 9102
}
}
service {
name = "count-api"
port = "9001"
meta {
envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}"
}
connect {
sidecar_service {
proxy {
config {
envoy_prometheus_bind_addr = "0.0.0.0:9102"
}
}
tags = ["envoy"]
}
}
}
task "web" {
driver = "docker"
config {
image = "hashicorpnomad/counter-api:v1"
}
# constraint {
# attribute = "${attr.unique.hostname}"
# value = "test01"
# }
}
}
group "dashboard" {
network {
mode ="bridge"
port "http" {
static = 9002
to = 9002
}
port "envoy_metrics" {
to = 9102
}
}
service {
name = "count-dashboard"
port = "9002"
meta {
envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}"
}
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "count-api"
local_bind_port = 8080
}
config {
envoy_prometheus_bind_addr = "0.0.0.0:9102"
}
}
tags = ["envoy"]
}
}
}
task "dashboard" {
driver = "docker"
env {
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
}
config {
image = "hashicorpnomad/counter-dashboard:v1"
}
# constraint {
# attribute = "${attr.unique.hostname}"
# value = "test03"
# }
}
}
}

View File

@ -0,0 +1,24 @@
namespace "*" {
policy = "write"
capabilities = ["alloc-node-exec"]
}
agent {
policy = "write"
}
operator {
policy = "write"
}
quota {
policy = "write"
}
node {
policy = "write"
}
host_volume "*" {
policy = "write"
}

View File

@ -22,6 +22,18 @@ if node['nomad']['manager']
notifies :restart, 'service[nomad]'
end
end
directory '/etc/nomad.d/policies' do
owner 'nomad'
group 'nomad'
mode '755'
end
remote_file '/etc/nomad.d/policies/anonymous.hcl' do
owner 'nomad'
group 'nomad'
mode '644'
end
end
if node['nomad']['client']
@ -34,6 +46,20 @@ if node['nomad']['client']
notifies :restart, 'service[nomad]'
end
end
directory '/etc/nomad.d/jobs' do
owner 'nomad'
group 'nomad'
mode '755'
end
%w( countdash.hcl countdash-intention.hcl ).each do |f|
remote_file "/etc/nomad.d/jobs/#{f}" do
owner 'nomad'
group 'nomad'
mode '644'
end
end
end
# Create directory:

View File

@ -1,19 +0,0 @@
%w( /mnt/shared ).each do |d|
directory d do
owner 'root'
group 'root'
end
end
# Add the fstab entry:
file '/etc/fstab' do
action :edit
block do |content|
content << "//192.168.10.200/Shared/AppData /mnt/shared cifs username=admin,password=Holiday88,uid=root,gid=root,file_mode=0777,dir_mode=0777,vers=3.0,_netdev 0 0\n"
end
not_if 'grep shared /etc/fstab'
end
execute 'mount -a || true'