The author has opened the source code modified (with the full DevOps process attached) : Hacker-Linner/ NanoServer
Familiar with K8S partners can also ignore this article, can directly start the DevOps project! Get straight to DevOps! Get straight to DevOps!
The related Dockerfile file is ready
Dockerfile.base
Prepare the project online CI building base Image.
FROM Golang: 1.15 - alpine
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
RUN mkdir -p /nanoserver/
WORKDIR /nanoserver
COPY go.mod go.mod
RUN go mod download
Copy the code
To generate the Image hackerlinner/nanoserver: base
docker build -f Dockerfile.alpine.base -t hackerlinner/nanoserver:base . --no-cache
Copy the code
Dockerfile.alpine.base
Prepare project production base Image.
FROM Alpine: 3.12
RUN addgroup -S app \
&& adduser -S -g app app \
&& apk --no-cache add \
ca-certificates curl netcat-openbsd
Copy the code
To generate the Image hackerlinner/nanoserver – alpine: base
docker build -f Dockerfile.alpine.base -t hackerlinner/nanoserver-alpine:base . --no-cache
Copy the code
Dockerfile.prod
CI produces the dockerfiles required for the build
### nanoserver:base
FROM hackerlinner/nanoserver:base as builder
WORKDIR /nanoserver
COPY . .
RUN CGO_ENABLED=0 go build -a -o bin/nanoserver
### nanoserver-alpine:base
FROM hackerlinner/nanoserver-alpine:base
LABEL Maintainer = "for less"
WORKDIR /home/app
COPY --from=builder /nanoserver/bin/nanoserver .
COPY ./configs ./configs
RUN chown -R app:app . /
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
USER app
CMD ["./nanoserver"]
Copy the code
Prepare relevant Kubernetes deployment files
Helm 3 Deploys MySql
The related deployment files are at: K8S /mysql
First allocate deployment space in your cluster, here I am Nano:
kubectl create ns nano
Copy the code
Assign folders to your persistent server, I’m using NFS:
Select * from MySql
mkdir -p /data/nfs/nano/nanoserver-mysql
chmod -R 777 /data/nfs/nano/nanoserver-mysql
Copy the code
Create PV & PVC and associate it with NFS
PVC, yaml: k8s/mysql/PVC, yaml
kubectl apply -f pvc.yaml -n nano
Copy the code
Deployment:
helm install nanoserver-mysql ./mysql -f values.yaml -n nano
Copy the code
Database creation:
create database
mysql -u root -phacker12345
create database scmj default character set utf8mb4 collate utf8mb4_unicode_ci;
Copy the code
Helm 3 deploys nanoServer
The related deployment file is k8s/mnanoserverysql
Prepare nanoServer’s configMap to allow the cluster to centrally manage Server configuration files.
apiVersion: v1
kind: ConfigMap
metadata:
name: nanoserver-config
labels:
app: nanoserver
data:
config.toml: | - [core] # enable the debug mode the debug = true heartbeat = 30 consume = "4/2, 8/3 dec / 4 # room card consumption, the use of commas, innings/room card number, four games such as consumption of one, If 1 card is consumed in 8 games and 2 cards are consumed in 16 games, it is 4/1,8/1,16/2
#WEB server setup
[webserver]
addr = "0.0.0.0:12307" # monitor address
enable_ssl = false If true, the cert and key paths must be configured
static_dir = "web/static"
# certificate Settings
[webserver.certificates]
cert = "configs/****.crt" Certificate path
key = "configs/****.key" # Key path
[game-server]
host = "nanoserver.your-domain.com"
port = 30251
# Redis server config
[redis]
host = "127.0.0.1"
port = 6357
# Mysql server config
[database]
host = "nanoserver-mysql"
port = 3306
dbname = "scmj"
password = "hacker12345"
username = "root"
args = "charset=utf8mb4"
buf_size = 10
max_idle_conns = 20
max_open_conns = 15
show_sql = true
# WeChat
[wechat]
appid = "YOUR_WX_APPID"
appsecret = "YOUR_APP_SECRET"
callback_url = "YOUR_CALLBACK"
mer_id = "YOUR_MER_ID"
unify_order_url = "https://api.mch.weixin.qq.com/pay/unifiedorder"
# Token set
[token]
expires = 21600 # Token expiration time
# whitelist Settings
[whitelist]
ip = ["10.10. *"."127.0.0.1".". *"] # Whitelist address, support golang regular expression syntax
# Share information
[share]
title = "To the bitter end."
desc = "Pure Sichuan play, quick and convenient handhelds, easily set up the game, anytime, anywhere to enjoy the game."
# Update Settings
[update]
force = true # Whether to force updates
version = "1.9.3"
android = "https://fir.im/tand"
ios = "https://fir.im/tios"
# Contact Settings
[contact]
daili1 = "kefuweixin01"
daili2 = "kefuweixin01"
kefu1 = "kefuweixin01"
# voice account at http://gcloud.qq.com/product/6
[voice]
appid = "xxx"
appkey = "xxx"
# Broadcast message
[broadcast]
message = ["System news: Healthy games, no gambling."."Welcome to the game."]
# Login related
[login]
guest = true
lists = ["test"."konglai"]
Copy the code
About ingressroute-tcp.yaml, because nanoServer itself starts two servers, Web and game:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: nanoserver-game-route
spec:
entryPoints:
- nanoserver-gm This needs to be set in traefik's deployment configuration
routes:
- match: HostSNI(`*`)
kind: Rule
services:
- name: nanoserver
port: 30251
Copy the code
Ingressroute-tcp. yaml is the game’s external entry point, and I need it because I’m using Traefik.
Drone CI/CD configuration
.drone.yml
kind: pipeline
type: kubernetes
name: NanoServer
steps:
- name: update Chart.yaml appVersion
image: busybox
commands:
- echo $DRONE_COMMIT
- '[ -n "$DRONE_COMMIT" ] && ( sed -i "s/APP_VERSION/${DRONE_COMMIT}/g" k8s/nanoserver/nanoserver/Chart.yaml; ) '
- cat k8s/nanoserver/nanoserver/Chart.yaml
- name: build Docker Image
image: plugins/docker
settings:
debug: true
dockerfile: Dockerfile.prod
repo: hub.your-domain.com/library/nanoserver
tags: ${DRONE_COMMIT}
registry: hub.your-domain.com
username:
from_secret: docker_user
password:
from_secret: docker_pass
- name: The cloud (HelmV3) -> K8S Cluster
image: pelotech/drone-helm3
settings:
helm_command: upgrade
chart: ./k8s/nanoserver/nanoserver
release: nanoserver
vaules_yaml: ./k8s/nanoserver/values.yaml
namespace: nano
api_server:
from_secret: api_server
kubernetes_token:
from_secret: k8s_token
skip_tls_verify: true
trigger:
branch:
- master
Copy the code
aboutapi_server
与 k8s_token
, played the children’s shoes of Kubernetes should know, I will not repeat.
I am for less. Wechat: uuhells123. Public account: Hacker afternoon tea.
Thank you for your support 👍👍👍!