commit 084ed53b2a380b62717791855ef176e41dc5154b Author: Vassiliy Yegorov Date: Tue Nov 24 14:39:03 2020 +0700 init diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2fc684f --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +PVE_USER=root +PVE_PASSWD=password + +PVE_NODE="pve-nsk" # node name +PVE_HOST="192.168.9.2" # proxmox api ip +PVE_REALM="pam" # pam or pve +PVE_CPU="4" # qty +PVE_MEMORY="4" # Gb +PVE_STORAGE_SIZE="32" # Gb +PVE_STORAGE_TYPE="RAW" $ RAW or QCOW2 +PVE_STORAGE_PATH="local" # name +PVE_IMAGE_FILE="hdd0:iso/rancheros-autoformat.iso" # full path with storage name diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/docker-compose-minio.yaml b/docker-compose-minio.yaml new file mode 100644 index 0000000..9b27228 --- /dev/null +++ b/docker-compose-minio.yaml @@ -0,0 +1,141 @@ +version: '3.7' + +services: + balancer: + image: nginx + hostname: balancer + ports: + - "8080:80" + networks: + - minio_distributed + deploy: + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.role==manager + configs: + - source: lb.conf + target: /etc/nginx/conf.d/lb.conf + + minio1: + image: minio/minio:RELEASE.2020-11-13T20-10-18Z + hostname: minio1 + volumes: + - minio1-data:/export + networks: + - minio_distributed + deploy: + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.minio1==true + command: server http://minio{1...4}/export + secrets: + - secret_key + - access_key + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + minio2: + image: minio/minio:RELEASE.2020-11-13T20-10-18Z + hostname: minio2 + volumes: + - minio2-data:/export + networks: + - minio_distributed + deploy: + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.minio2==true + command: server http://minio{1...4}/export + secrets: + - secret_key + - access_key + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + minio3: + image: minio/minio:RELEASE.2020-11-13T20-10-18Z + hostname: minio3 + volumes: + - minio3-data:/export + networks: + - minio_distributed + deploy: + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.minio3==true + command: server http://minio{1...4}/export + secrets: + - secret_key + - access_key + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + minio4: + image: minio/minio:RELEASE.2020-11-13T20-10-18Z + hostname: minio4 + volumes: + - minio4-data:/export + networks: + - minio_distributed + deploy: + restart_policy: + delay: 10s + max_attempts: 10 + window: 60s + placement: + constraints: + - node.labels.minio4==true + command: server http://minio{1...4}/export + secrets: + - secret_key + - access_key + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + +volumes: + minio1-data: + minio2-data: + minio3-data: + minio4-data: + +networks: + minio_distributed: + driver: overlay + +configs: + lb.conf: + external: true + +secrets: + secret_key: + external: true + access_key: + external: true diff --git a/docker-init.sh b/docker-init.sh new file mode 100755 index 0000000..66c192b --- /dev/null +++ b/docker-init.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +[[ ! -f .env ]] && { + cp .env.example .env + echo "put true envs in .env file" +} + +source .env + +VM_NAME="${1:-docker-master}" + +docker-machine rm --force $VM_NAME >/dev/null 2>&1 || true + +docker-machine --debug \ + create \ + -d proxmoxve \ + --proxmoxve-proxmox-host $PVE_HOST \ + --proxmoxve-proxmox-user-name $PVE_USER \ + --proxmoxve-proxmox-realm $PVE_REALM \ + --proxmoxve-proxmox-user-password $PVE_PASSWD \ + --proxmoxve-proxmox-node "$PVE_NODE" \ + --proxmoxve-vm-cpu-sockets $PVE_CPU \ + --proxmoxve-vm-memory $PVE_MEMORY \ + --proxmoxve-vm-image-file $PVE_IMAGE_FILE \ + --proxmoxve-vm-storage-size $PVE_STORAGE_SIZE \ + --proxmoxve-vm-storage-type $PVE_STORAGE_TYPE \ + --proxmoxve-vm-storage-path $PVE_STORAGE_PATH \ + $VM_NAME + +echo "/================================/" +echo "/ VM $VM_NAME is started" +echo "/================================/" diff --git a/lb.conf b/lb.conf new file mode 100644 index 0000000..4598782 --- /dev/null +++ b/lb.conf @@ -0,0 +1,41 @@ +proxy_cache_path /var/cache/nginx/minio_cache levels=1:2 keys_zone=minio_cache:10m max_size=100m inactive=60m use_temp_path=off; + +upstream minio_servers { + server minio1:9000; + server minio2:9000; + server minio3:9000; + server minio4:9000; +} + +server { + listen 80; + server_name minio.local; + + client_max_body_size 1g; + sendfile on; + + ignore_invalid_headers off; + + location / { + + proxy_cache minio_cache; + add_header X-Cache-Status $upstream_cache_status; + proxy_cache_revalidate on; + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; + proxy_cache_lock on; + proxy_ignore_headers Set-Cookie; + proxy_cache_valid 1m; + + client_body_buffer_size 128k; + proxy_connect_timeout 90; + proxy_send_timeout 6000; + proxy_read_timeout 6000; + proxy_buffer_size 4k; + proxy_buffers 4 32k; + proxy_busy_buffers_size 64k; + proxy_temp_file_write_size 128m; + + proxy_set_header Host $http_host; + proxy_pass http://minio_servers; + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..cbd3781 --- /dev/null +++ b/readme.md @@ -0,0 +1,63 @@ +# Практическая работа по развовоту swarm-кластера на Proxmox VE + +1. развернем кластер +2. запустим панель управления +3. развернем s3 хранилище с балансировщиком + +## Предустановки + +1. Само собой, имеем уже настроенный Proxmox VE +2. На локальной машине ставим docker-machine (`brew install docker-machine` - если у вас MacOS) +3. Просаживаем плагин для работы с Proxmox: + 1. качаем от [сюда](https://github.com/lnxbil/docker-machine-driver-proxmox-ve/releases/download/v4/docker-machine-driver-proxmoxve.macos-amd64) + 2. даем права на запуск - `chmod +x docker-machine-driver-proxmoxve.macos-amd64` + 3. перемещаем рабочую папку - `mv docker-machine-driver-proxmoxve.macos-amd64 /usr/local/bin/docker-machine-driver-proxmoxve` + 4. проверяем, что работает плагин `docker-machine create -d proxmoxve --help` (должен появится листинг параметров плагина) +4. качаем образ [докера](https://releases.rancher.com/os/v1.5.1/proxmoxve/rancheros-autoformat.iso) и заливаем его себе в Proxmox + +## Использование + +1. переименовываем `.env.example` в `.env` и заполняем логопасс от доступа в ваш Proxmox +2. запускаем `swarm-init.sh` - он пробуем цепляться в Proxmox и создает 4 машины (одну мастера и 3 воркера - формально, пока просто 4 пустых машины) +3. идем на мастер `docker-machine ssh docker-master` и запускаем там: + 1. `docker swarm init` - создает мастера и инициализирует рой + 2. `docker swarm join-token worker` - показывает токен, копируем всю строчку в буфер + 3. `exit` - выходим +4. далее, цепляемся к каждому воркеру `docker-machine ssh docker-1` и выполняем команду из буфера +5. после инициализации воркеров и идем снова на мастер `docker-machine ssh docker-master` и проверяем что воркеры подцепились `docker node ls` + +## Portainer + +1. на мастере запускаем установку стека + 1. `wget https://downloads.portainer.io/portainer-agent-stack.yml --output-document portainer-agent-stack.yml` + 2. `docker stack deploy --compose-file=portainer-agent-stack.yml portainer` + 3. на мастере подсматриваем айпишник `ifconfig eth0` и идем на веб-морду http://ip:9000 + +## Minio + +1. на мастере + 1. создаем секреты (само собой - свои, а не из примера) + 1. `echo "AKIAIOSFODNN7EXAMPLE" | docker secret create access_key -` + 2. `echo "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | docker secret create secret_key -` + 2. проставляем метки на воркеры + 1. `docker node update --label-add minio1=true docker-master` + 2. `docker node update --label-add minio2=true docker-2` + 3. `docker node update --label-add minio3=true docker-3` + 4. `docker node update --label-add minio4=true docker-1` + 3. импортируем + 4. в конфиги файлик `lb.conf` и называем его там так же `lb.conf` + 5. запускает новый стек используя код из файла `docker-compose-minio.yaml` и называем стек `minio` + 6. стек поднимет 4 независимые реплики minio со своими дисками на каждой их четырех нод и одну реплику nginx на мастер-ноде, выставит ингресс-линк на порте `8080` + 7. доменное имя для minio выглядит как `minio.local` (можно поменять в lb.conf перед его импортом), не забудьте прописать его у себя в /etc/hosts на айпишники нод (или хотя бы мастер-ноды) + + +## Чистим за собой +1. `./swarm-rm.sh` + +## Видео к курсу +- [видео]() + +##### Автор +- **Vassiliy Yegorov** [vasyakrg](https://github.com/vasyakrg) +- [сайт](vk.com/realmanual) +- [youtube](youtube.com/realmanual) diff --git a/swarm-init.sh b/swarm-init.sh new file mode 100755 index 0000000..452c137 --- /dev/null +++ b/swarm-init.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +./docker-init.sh + +./docker-init.sh docker-1 +./docker-init.sh docker-2 +./docker-init.sh docker-3 diff --git a/swarm-rm.sh b/swarm-rm.sh new file mode 100755 index 0000000..bec395a --- /dev/null +++ b/swarm-rm.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker-machine rm docker-master docker-1 docker-2 docker-3