use nginx as load balancing for multiple scheduler nodes.
Signed-off-by: Cao Xueliang caoxl78320@163.com --- container/scheduler-nginx/Dockerfile | 8 +++++++ container/scheduler-nginx/build | 9 ++++++++ container/scheduler-nginx/nginx.conf | 29 +++++++++++++++++++++++++ container/scheduler-nginx/start | 32 ++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 container/scheduler-nginx/Dockerfile create mode 100755 container/scheduler-nginx/build create mode 100644 container/scheduler-nginx/nginx.conf create mode 100755 container/scheduler-nginx/start
diff --git a/container/scheduler-nginx/Dockerfile b/container/scheduler-nginx/Dockerfile new file mode 100644 index 0000000..2cc430b --- /dev/null +++ b/container/scheduler-nginx/Dockerfile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +FROM nginx:alpine + +MAINTAINER Cao Xueliang caoxl78320@163.com + +COPY nginx.conf /etc/nginx/ diff --git a/container/scheduler-nginx/build b/container/scheduler-nginx/build new file mode 100755 index 0000000..4b491d9 --- /dev/null +++ b/container/scheduler-nginx/build @@ -0,0 +1,9 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +. ../defconfig.sh + +docker_skip_rebuild "scheduler-nginx" + +docker build -t scheduler-nginx . diff --git a/container/scheduler-nginx/nginx.conf b/container/scheduler-nginx/nginx.conf new file mode 100644 index 0000000..c8c3783 --- /dev/null +++ b/container/scheduler-nginx/nginx.conf @@ -0,0 +1,29 @@ +# This is a default site configuration which will simply return 404, preventing +# chance access to any other virtualhost. +events { + worker_connections 65535; +} + +http{ + upstream sched { + server 172.17.0.1:3001; + server 172.17.0.1:3002; + server 172.17.0.1:3003; + } + + + server { + listen 3000 default_server; + listen [::]:3000 default_server; + + location / { + proxy_pass http://sched; + proxy_read_timeout 1814400; + } + + location = /404.html { + internal; + } + } +} + diff --git a/container/scheduler-nginx/start b/container/scheduler-nginx/start new file mode 100755 index 0000000..dc2dfbc --- /dev/null +++ b/container/scheduler-nginx/start @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'set' +require_relative '../defconfig.rb' + +names = Set.new %w[ + SCHED_PORT +] + +defaults = relevant_defaults(names) +SCHED_PORT = defaults['SCHED_PORT'] +env = docker_env(defaults) + +docker_rm 'scheduler-nginx' + +cmd = %w[ + docker run + --name scheduler-nginx + --restart=always + -d +] + env + %W[ + -p #{SCHED_PORT}:#{SCHED_PORT} + -v /etc/localtime:/etc/localtime:ro + --log-opt mode=non-blocking + --log-opt max-buffer-size=4m + scheduler-nginx +] + +system(*cmd)