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