Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Add docker deploy (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: dengtuo <[email protected]>
  • Loading branch information
tuoeg authored Apr 14, 2023
1 parent 3e41641 commit 6e8ef29
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Makefile
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 .
20 changes: 20 additions & 0 deletions build/Dockerfile
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"]
24 changes: 24 additions & 0 deletions deploy/configmap.yaml
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
29 changes: 29 additions & 0 deletions deploy/deployment.yaml
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
15 changes: 15 additions & 0 deletions deploy/service.yaml
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

0 comments on commit 6e8ef29

Please sign in to comment.