forked from UoW-CPC/COLARepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_init_worker.yaml
executable file
·128 lines (114 loc) · 4.67 KB
/
cloud_init_worker.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#cloud-config
apt_upgrade: false
apt_update: false
manage_etc_hosts: false
package_update: false
package_upgrade: false
write_files:
- path: /etc/consul/config.json
content: |
{
"server": false,
"datacenter": "application",
"data_dir": "/var/consul",
"encrypt": "uohStneoKEoVYZIASGp6Nw==",
"log_level": "INFO",
"enable_syslog": false,
"retry_join": ["{{variables.master_host_ip}}"],
"rejoin_after_leave": true,
"services": [{"name":"worker_cluster","port":9100}, {"name":"app_docker_cluster","port":9200}]
}
- path: /bin/consul-set-network.sh
permissions: '755'
content: |
#!/bin/bash
echo "Setup NETWORK starts."
myhost=`hostname`
ipaddress=`ifconfig | awk '/inet addr/{print substr($2,6)}' | grep -v 127.0.0.1 | head -n 1`
cp /etc/hosts /etc/hosts.old
grep -v "$myhost" /etc/hosts.old > /etc/hosts
echo "IPADDRESS: $ipaddress"
echo "$ipaddress $myhost" >> /etc/hosts
rm -rf /etc/resolvconf/*
echo "Setup NETWORK finished."
- path: /etc/resolvconf/resolv.conf.d/base
content: |
nameserver 8.8.8.8
# Docker config for labels test with workernodes
- path: /etc/systemd/system/docker.service.d/docker.conf
content: |
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --label="host"="{{infra_name}}"
- path: /etc/micado/docker-compose.yml
content: |
version: '3.3'
services:
consul:
image: consul:1.0.0
container_name: consul
ports:
- 8300:8300
- 8301:8301
- 8301:8301/udp
- 8302:8302
- 8302:8302/udp
- 8500:8500
- 8600:8600
- 8600:8600/udp
volumes:
- "/etc/consul/:/etc/consul/"
command: agent -advertise=$IP -retry-join={{variables.master_host_ip}} -config-file=/etc/consul/config.json
node-exporter:
image: prom/node-exporter:v0.15.2
container_name: node-exporter
ports:
- 9100:9100
cadvisor:
image: google/cadvisor:v0.28.3
container_name: cadvisor
ports:
- 9200:8080
volumes:
- "/:/rootfs/:ro"
- "/var/run/:/var/run/:rw"
- "/sys:/sys/:ro"
- "/var/lib/docker/:/var/lib/docker/:ro"
- "/dev/disk/:/dev/disk/"
runcmd:
- adduser --disabled-password --gecos "" prometheus
- echo 'APT::Periodic::Unattended-Upgrade "0";' > /etc/apt/apt.conf.d/20auto-upgrades
- /bin/consul-set-network.sh
- dhclient
- oldhostname=$(hostname -s)
- new_host_name=worker-$(date +%s | sha256sum | base64 | head -c 32 ; echo)
- echo $new_host_name > /etc/hostname
- hostname -F /etc/hostname
- line=127.0.1.1'\t'$new_host_name
- sed -i "s/$oldhostname/$new_host_name/g" /etc/hosts
- echo $line >> /etc/hosts
- export DEBIAN_FRONTEND=noninteractive
- dpkg-reconfigure openssh-server
- resolvconf -u
- echo nameserver 8.8.8.8 >> /etc/resolv.conf
# Docker
- apt-get update
- apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common wget unzip
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update
- apt-get install -y docker-ce=17.09.1~ce-0~ubuntu
- systemctl enable docker
# Install Docker Compose
- curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
# Connect to Swarm
- wget --retry-connrefused -qO /tmp/swarm_join {{variables.master_host_ip}}:2375/v1.26/swarm
- export TOKEN=$(grep -Eo 'SWMTKN-[[:alnum:]]*-[[:alnum:]]*-[[:alnum:]]*' /tmp/swarm_join | head -1)
- docker swarm join --token $TOKEN {{variables.master_host_ip}}:2377
# Infra services start
- export IP=$(hostname -I | cut -d\ -f1)
- docker-compose -f /etc/micado/docker-compose.yml up -d
# - sudo docker run -d -p 9100:9100 prom/node-exporter:v0.15.2
# - sudo docker run -d --net=host -e 'CONSUL_LOCAL_CONFIG={"leave_on_terminate":true}' -p 8301:8301 -p 8301:8301/udp -p 8300:8300 -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600/udp -v /etc/consul/:/etc/consul consul:1.0.0 agent -advertise=$IP -retry-join={{variables.master_host_ip}} -config-file=/etc/consul/config.json
# - sudo docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=9200:8080 --detach=true --name=cadvisor google/cadvisor:v0.28.3