This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dengtuo <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## version | ||
SERVER_VERSION = v1.0.0 | ||
## command | ||
GO = go | ||
GO_VENDOR = go mod | ||
MKDIR_P = mkdir -p | ||
|
||
## build | ||
.PHONY: build | ||
build: | ||
GO111MODULE=on $(GO) build -v -o _output/balancer ./ | ||
|
||
|
||
## dockerfile | ||
|
||
.PHONY: docker.build | ||
docker.build: | ||
docker build --no-cache --rm --tag balancer:$(SERVER_VERSION) -f ./build/Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Building stage | ||
FROM golang:1.17.3 AS builder | ||
|
||
ENV GO111MODULE=on \ | ||
CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOPROXY="https://goproxy.cn,direct" | ||
|
||
WORKDIR /go/src | ||
|
||
COPY . /go/src | ||
|
||
ENV TIMEZONE "Asia/Shanghai" | ||
|
||
RUN go build -v -o _output/balancer ./ | ||
|
||
FROM reg.hrlyit.com/base/ubuntu:20.04 | ||
COPY --from=builder /go/src/_output/balancer /opt/ | ||
|
||
ENTRYPOINT ["./opt/balancer"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: balancer | ||
namespace: default | ||
data: | ||
config.yaml: | | ||
schema: http # support http and https | ||
port: 8089 # port for balancer | ||
ssl_certificate: | ||
ssl_certificate_key: | ||
tcp_health_check: true | ||
health_check_interval: 3 # health check interval (second) | ||
# The maximum number of requests that the balancer can handle at the same time | ||
# 0 refers to no limit to the maximum number of requests | ||
max_allowed: 100 | ||
location: # route matching for reverse proxy | ||
- pattern: / | ||
proxy_pass: # URL of the reverse proxy | ||
- "http://192.168.1.1" | ||
- "http://192.168.1.2:1015" | ||
- "https://192.168.1.2" | ||
- "http://my-server.com" | ||
balance_mode: round-robin # load balancing algorithm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: balancer | ||
namespace: default | ||
labels: | ||
app: balancer | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: balancer | ||
template: | ||
metadata: | ||
labels: | ||
app: balancer | ||
spec: | ||
containers: | ||
- name: balancer | ||
image: balancer:v1.0.0 | ||
imagePullPolicy: IfNotPresent | ||
volumeMounts: | ||
- name: config | ||
mountPath: /opt | ||
readOnly: true | ||
volumes: | ||
- name: config | ||
configMap: | ||
name: balancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: balancer | ||
namespace: default | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: balancer | ||
ports: | ||
- name: balancer | ||
protocol: TCP | ||
nodePort: 30089 | ||
port: 80 | ||
targetPort: 8089 |