Ucloud » History » Version 7
Nico Schottelius, 07/21/2019 09:21 AM
1 | 1 | Ahmed Bilal | h1. ucloud (To Be Continued) |
---|---|---|---|
2 | |||
3 | 7 | Nico Schottelius | {{toc}} |
4 | |||
5 | 4 | Ahmed Bilal | h2. Requirements |
6 | 5 | Ahmed Bilal | |
7 | 4 | Ahmed Bilal | 1. Python 3.7, pip, pipenv |
8 | 2. etcd |
||
9 | 3. ceph |
||
10 | |||
11 | 6 | Ahmed Bilal | h2. Installation |
12 | |||
13 | **Note:** This installation guide assumes that the ~ is /root |
||
14 | |||
15 | * **Install QEMU** |
||
16 | <pre><code class="shell"> |
||
17 | sudo apt install qemu qemu-kvm |
||
18 | </code></pre> |
||
19 | |||
20 | |||
21 | * **Create Directory Structure** |
||
22 | <pre><code class="shell"> |
||
23 | mkdir /var/vm/ |
||
24 | mkdir /var/www/ |
||
25 | </code></pre> |
||
26 | |||
27 | |||
28 | * **Create User Directories** |
||
29 | <pre><code class="shell"> |
||
30 | mkdir /var/www/ahmedbilal-admin |
||
31 | mkdir /var/www/nico |
||
32 | mkdir /var/www/kjg |
||
33 | cd ~ |
||
34 | </code></pre> |
||
35 | |||
36 | * **Download and place Alpine Linux image in _/var/www/ahmedbilal-admin_** |
||
37 | <pre><code class="shell"> |
||
38 | wget https://www.dropbox.com/s/5eyryhxun6847hx/alpine.zip?dl=1 -O alpine.zip |
||
39 | unzip alpine.zip |
||
40 | mv alpine.qcow2 /var/www/ahmedbilal-admin |
||
41 | </code></pre> |
||
42 | |||
43 | * **Clone repos** |
||
44 | <pre><code class="shell"> |
||
45 | git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-api.git |
||
46 | git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-scheduler.git |
||
47 | git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-vm.git |
||
48 | git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-file-scan.git |
||
49 | git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-image-scanner.git |
||
50 | </code></pre> |
||
51 | |||
52 | |||
53 | h2. *+Put related .env inside all the above directories+* |
||
54 | |||
55 | * **Run "ucloud-api" as daemon** |
||
56 | <pre><code class="shell"> |
||
57 | cd ucloud-api |
||
58 | pipenv install |
||
59 | pipenv run gunicorn --bind [::]:80 main:app --daemon |
||
60 | wget https://www.dropbox.com/s/lyu3atymxyw3846/setup.py?dl=1 -O setup.py |
||
61 | pipenv run python setup.py |
||
62 | cd ~ |
||
63 | </code></pre> |
||
64 | |||
65 | * **Run "ucloud-scheduler" as daemon** |
||
66 | <pre><code class="shell"> |
||
67 | cd ucloud-scheduler |
||
68 | pipenv install |
||
69 | pipenv run python main.py &>/dev/null & |
||
70 | cd ~ |
||
71 | </code></pre> |
||
72 | |||
73 | * **Run "ucloud-vm" as daemon** |
||
74 | <pre><code class="shell"> |
||
75 | cd ucloud-vm |
||
76 | pipenv install |
||
77 | pipenv run python main.py /v1/host/1 --vm True &>/dev/null & |
||
78 | cd ~ |
||
79 | </code></pre> |
||
80 | |||
81 | * **Install ucloud-file-scan** |
||
82 | <pre><code class="shell"> |
||
83 | cd ucloud-file-scan |
||
84 | pipenv install |
||
85 | cd ~ |
||
86 | </code></pre> |
||
87 | |||
88 | * **Install ucloud-image-scanner** |
||
89 | <pre><code class="shell"> |
||
90 | cd ucloud-image-scanner |
||
91 | pipenv install |
||
92 | cd ~ |
||
93 | </code></pre> |
||
94 | |||
95 | * **Run @crontab -e@ and put these entries there and save by pressing @Ctrl+x@ then @y@ then @enter@** |
||
96 | <pre> |
||
97 | */1 * * * * (cd /root/ucloud-file-scan && /usr/local/bin/pipenv run python main.py) |
||
98 | */1 * * * * (cd /root/ucloud-image-scanner/ && /usr/local/bin/pipenv run python main.py) |
||
99 | </pre> |
||
100 | |||
101 | 1 | Ahmed Bilal | h2. ucloud-api |
102 | |||
103 | Outside world (indirect) communication with the internal systems. |
||
104 | |||
105 | Its responsibilities are |
||
106 | * Create VM *(Done)* POST _/vm/create_ |
||
107 | <pre><code class="javascript"> |
||
108 | { |
||
109 | "name": "username", |
||
110 | "realm": "user_realm", |
||
111 | "seed": "user_seed", |
||
112 | "specs": { |
||
113 | "cpu": 16, |
||
114 | "ram": 256, |
||
115 | 2 | Ahmed Bilal | "hdd": 2000, |
116 | "ssd": 256 |
||
117 | 1 | Ahmed Bilal | } |
118 | } |
||
119 | </code></pre> |
||
120 | |||
121 | * Delete VM *(Done)* POST _/vm/delete_ |
||
122 | <pre><code class="javascript"> |
||
123 | { |
||
124 | "name": "username", |
||
125 | "realm": "user_realm", |
||
126 | "seed": "user_seed", |
||
127 | "vmid": "id_of_virtual_machine" |
||
128 | } |
||
129 | </code></pre> |
||
130 | |||
131 | * Status VM *(Done)* GET _/vm/status_ |
||
132 | <pre><code class="javascript"> |
||
133 | { |
||
134 | "id": "id_of_virtual_machine" |
||
135 | } |
||
136 | </code></pre> |
||
137 | |||
138 | * Create new network |
||
139 | * Attach network to VM |
||
140 | * Detach network from VM |
||
141 | * Delete network |
||
142 | |||
143 | h2. ucloud-scheduler |
||
144 | |||
145 | It schedules/reschedules VM that are created using ucloud-api. How does it schedules? It does by watching any changes under the _/v1/vm/_ prefix. Basically, it deals with two ETCD entries |
||
146 | |||
147 | 1. Virtual Machines Entries that looks like |
||
148 | <pre><code class="javascript"> |
||
149 | /v1/vm/1 |
||
150 | { |
||
151 | "owner": "ahmedbilal-admin", |
||
152 | "specs": { |
||
153 | "cpu": 20, |
||
154 | "ram": 2, |
||
155 | "hdd": 10, |
||
156 | 3 | Ahmed Bilal | "ssd": 10 |
157 | 1 | Ahmed Bilal | }, |
158 | "hostname": "", |
||
159 | "status": "REQUESTED_NEW" |
||
160 | } |
||
161 | </code></pre> |
||
162 | 2. Hosts Entries that look like |
||
163 | <pre><code class="javascript"> |
||
164 | /v1/host/1 |
||
165 | { |
||
166 | "cpu": 32, |
||
167 | "ram": 128, |
||
168 | "hdd": 1024, |
||
169 | 3 | Ahmed Bilal | "ssd": 0 |
170 | 1 | Ahmed Bilal | "status": "UP" |
171 | } |
||
172 | </code></pre> |
||
173 | |||
174 | It loop through list of host entries found under _/v1/host/_ and check whether we can run the incoming VM on that host. if we can, then it (ucloud-scheduler) sets the hostname key of incoming VM to that host. Suppose, our scheduler decides that we can run the earlier shown VM _/v1/vm/1_ on _/v1/host/1_. Then, our updated entry would look like |
||
175 | |||
176 | <pre><code class="javascript"> |
||
177 | /v1/vm/1 |
||
178 | { |
||
179 | "owner": "ahmedbilal-admin", |
||
180 | "specs": { |
||
181 | "cpu": 20, |
||
182 | "ram": 2, |
||
183 | "hdd": 10, |
||
184 | 3 | Ahmed Bilal | "ssd": 10 |
185 | 1 | Ahmed Bilal | }, |
186 | "hostname": "/v1/host/1", |
||
187 | "status": "REQUESTED_NEW" |
||
188 | } |
||
189 | </code></pre> |
||
190 | |||
191 | *Note* the hostname key/value pair. |
||
192 | |||
193 | h2. ucloud-vm |
||
194 | It is responsible for creating (running) / deleting (stopping) / monitoring virtual machines |
||
195 | |||
196 | It watches the _/v1/vm/_ prefix for any changes like (Virtual Machines with status like *SCHEDULED_DEPLOY* or *REQUEST_DELETE*. |
||
197 | |||
198 | On, *SCHEDULED_DEPLOY* it creates the VM and run it. On, *REQUEST_DELETE* it stops the VM. |
||
199 | |||
200 | It is also responsible for monitoring VM statues i.e whether they are RUNNING or KILLED (in action). If a VM is killed we put that in log file, notify system administrator and restart it. |