Skip to content

Commit 48b18e0

Browse files
wallyxjhlingdie
andauthored
Launchpad (#4645)
* update kafka monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * launchpad monitor * fix build error. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> --------- Signed-off-by: yy <[email protected]> Co-authored-by: yy <[email protected]> Co-authored-by: yy <[email protected]>
1 parent 900d3fc commit 48b18e0

File tree

18 files changed

+620
-11
lines changed

18 files changed

+620
-11
lines changed

Diff for: .github/workflows/services.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
strategy:
8888
matrix:
8989
## TODO: add more modules
90-
module: [database, pay, account, minio]
90+
module: [database, pay, account, minio, launchpad]
9191
steps:
9292
- name: Checkout
9393
uses: actions/checkout@v3
@@ -182,7 +182,7 @@ jobs:
182182
strategy:
183183
matrix:
184184
## TODO: add more modules
185-
module: [database, pay, account, minio]
185+
module: [database, pay, account, minio, launchpad]
186186
steps:
187187
- name: Checkout
188188
uses: actions/checkout@v3

Diff for: frontend/providers/applaunchpad/deploy/Kubefile

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ ENV cloudPort=""
1010

1111
ENV certSecretName="wildcard-cert"
1212
ENV ingressSecret="wildcard-cert"
13+
ENv monitorUrl="http://database-monitor.sealos.svc.cluster.local:9090"
1314

1415
CMD ["kubectl apply -f manifests"]

Diff for: frontend/providers/applaunchpad/deploy/manifests/deploy.yaml.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ spec:
4545
- env:
4646
- name: SEALOS_DOMAIN
4747
value: {{ .cloudDomain }}
48+
- name: MONITOR_URL
49+
value {{ .monitorUrl }}
4850
- name: DOMAIN_PORT
4951
value: "{{ if .cloudPort }}:{{ .cloudPort }}{{ end }}"
5052
- name: INGRESS_SECRET

Diff for: scripts/cloud/install.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ openebs_version=${openebs_version:-"3.10.0"}
2929
ingress_nginx_version=${ingress_nginx_version:-"1.9.4"}
3030
kubeblocks_version=${kubeblocks_version:-"0.8.2"}
3131
metrics_server_version=${metrics_server_version:-"0.6.4"}
32-
kube_prometheus_stack_version=${kube_prometheus_stack_version:-"0.70.0"}
32+
victoria_metrics_k8s_stack_version=${victoria_metrics_k8s_stack_version:-"1.96.0"}
3333

3434

3535
# Define English and Chinese prompts
@@ -256,7 +256,7 @@ init() {
256256
pull_image "kubeblocks-postgresql" "v${kubeblocks_version#v:-0.8.2}"
257257
pull_image "kubeblocks-mongodb" "v${kubeblocks_version#v:-0.8.2}"
258258
pull_image "metrics-server" "v${metrics_server_version#v:-0.6.4}"
259-
pull_image "kube-prometheus-stack" "v${kube_prometheus_stack_version#v:-0.63.0}"
259+
pull_image "victoria-metrics-k8s-stack" "v${victoria_metrics_k8s_stack_version#v:-1.96.0}"
260260
pull_image "sealos-cloud" "${cloud_version}"
261261
}
262262

@@ -649,7 +649,8 @@ EOF
649649
kbcli addon enable snapshot-controller
650650

651651
get_prompt "installing_monitoring"
652-
sealos run "${image_registry}/${image_repository}/kube-prometheus-stack:v${kube_prometheus_stack_version#v:-0.63.0}"
652+
sealos run "${image_registry}/${image_repository}/victoria-metrics-k8s-stack:v${victoria_metrics_k8s_stack_version#v:-1.96.0}"
653+
653654
kubectl patch cm kb-addon-prometheus-server -n kb-system --patch-file $CLOUD_DIR/kb-addon-prometheus-server-patch.yaml
654655

655656
get_prompt "patching_ingress"

Diff for: service/go.work

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use (
44
./database
55
./pay
66
./account
7+
./launchpad
78
.
89
)
910

Diff for: service/launchpad/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# FROM scratch
2+
FROM gcr.io/distroless/static:nonroot
3+
# FROM gengweifeng/gcr-io-distroless-static-nonroot
4+
ARG TARGETARCH
5+
COPY bin/service-launchpad-$TARGETARCH /manager
6+
EXPOSE 9090
7+
USER 65532:65532
8+
9+
ENTRYPOINT ["/manager"]

Diff for: service/launchpad/Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
IMG ?= ghcr.io/labring/sealos-launchpad-service:latest
2+
3+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4+
ifeq (,$(shell go env GOBIN))
5+
GOBIN=$(shell go env GOPATH)/bin
6+
else
7+
GOBIN=$(shell go env GOBIN)
8+
endif
9+
10+
# only support linux, non cgo
11+
PLATFORMS ?= linux_arm64 linux_amd64
12+
GOOS=linux
13+
CGO_ENABLED=0
14+
GOARCH=$(shell go env GOARCH)
15+
16+
GO_BUILD_FLAGS=-trimpath -ldflags "-s -w"
17+
18+
.PHONY: all
19+
all: build
20+
21+
##@ General
22+
23+
# The help target prints out all targets with their descriptions organized
24+
# beneath their categories. The categories are represented by '##@' and the
25+
# target descriptions by '##'. The awk commands is responsible for reading the
26+
# entire set of makefiles included in this invocation, looking for lines of the
27+
# file as xyz: ## something, and then pretty-format the target and help. Then,
28+
# if there's a line with ##@ something, that gets pretty-printed as a category.
29+
# More info on the usage of ANSI control characters for terminal formatting:
30+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
31+
# More info on the awk command:
32+
# http://linuxcommand.org/lc3_adv_awk.php
33+
34+
.PHONY: help
35+
help: ## Display this help.
36+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
37+
38+
##@ Build
39+
40+
.PHONY: clean
41+
clean:
42+
rm -f $(SERVICE_NAME)
43+
44+
.PHONY: build
45+
build: clean ## Build service-hub binary.
46+
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go build $(GO_BUILD_FLAGS) -o bin/manager main.go
47+
48+
.PHONY: docker-build
49+
docker-build: build
50+
mv bin/manager bin/service-launchpad-${TARGETARCH}
51+
docker build -t $(IMG) .
52+
53+
.PHONY: docker-push
54+
docker-push:
55+
docker push $(IMG)

Diff for: service/launchpad/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RESTServer
2+
3+
## Description
4+
5+
restserver for database monitoring
6+
7+
## Getting Started
8+
9+
### Running on the cluster
10+
11+
1. Build and push your image to the location specified by `IMG`:
12+
13+
```sh
14+
make docker-build docker-push IMG=<some-registry>/sealos-cloud-database-monitor:tag
15+
```
16+
17+
2. Deploy the restserver:
18+
19+
```sh
20+
kubectl apply -f deploy/manifests/
21+
```
22+
23+
### How it works
24+
25+
To enable the database frontend application to retrieve monitoring data, you need to modify the environment variable `MONITOR_URL` of the frontend deployment to the corresponding address of the restserver.
26+
27+
Additionally, to configure the data source, you need to set the environment variable `VM_SERVICE_HOST` of the restserver deployment to the correct address.
28+
29+
```
30+
e.g.
31+
http://prometheus.sealos.svc.cluster.local
32+
```
33+
34+
## License
35+
36+
Copyright 2023.
37+
38+
Licensed under the Apache License, Version 2.0 (the "License");
39+
40+
you may not use this file except in compliance with the License.
41+
42+
You may obtain a copy of the License at
43+
44+
    http://www.apache.org/licenses/LICENSE-2.0
45+
46+
Unless required by applicable law or agreed to in writing, software
47+
48+
distributed under the License is distributed on an "AS IS" BASIS,
49+
50+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51+
52+
See the License for the specific language governing permissions and
53+
54+
limitations under the License.

Diff for: service/launchpad/config/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server:
2+
addr: ":8428"

Diff for: service/launchpad/deploy/Kubefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM scratch
2+
COPY registry registry
3+
COPY manifests manifests
4+
5+
CMD ["kubectl apply -f manifests/deploy.yaml"]

Diff for: service/launchpad/deploy/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### docker image build and deploy
2+
```bash
3+
make docker-build IMG=$(YourImageName)
4+
# edit deploy/manifests/depoly.yaml and deploy
5+
kubectl apply -f deploy/manifests/depoly.yaml
6+
```
7+
8+
### cluster image build and deploy
9+
```bash
10+
```
11+
12+
### Victoria Metrics
13+
14+
In order to prevent performance degradation or abnormal behavior caused by excessive data size in Prometheus, VictoriaMetrics is utilized for data collection.
15+
16+
> By default, we use kb-prometheus-server for the data collection service.

Diff for: service/launchpad/deploy/manifests/deploy.yaml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
labels:
5+
app: launchpad-monitor
6+
name: launchpad-monitor-config
7+
namespace: sealos
8+
data:
9+
config.yml: |
10+
server:
11+
addr: ":8428"
12+
---
13+
apiVersion: apps/v1
14+
kind: Deployment
15+
metadata:
16+
labels:
17+
app: launchpad-monitor
18+
name: launchpad-monitor-deployment
19+
namespace: sealos
20+
spec:
21+
replicas: 1
22+
selector:
23+
matchLabels:
24+
app: launchpad-monitor
25+
strategy:
26+
type: Recreate
27+
template:
28+
metadata:
29+
labels:
30+
app: launchpad-monitor
31+
spec:
32+
containers:
33+
- args:
34+
- /config/config.yml
35+
command:
36+
- /manager
37+
env:
38+
- name: VM_SERVICE_HOST
39+
value: http://vmsingle-victoria-metrics-k8s-stack.vm.svc:8429
40+
image: ghcr.io/labring/sealos-launchpad-service:latest
41+
imagePullPolicy: Always
42+
name: launchpad-monitor
43+
ports:
44+
- containerPort: 8428
45+
protocol: TCP
46+
resources:
47+
limits:
48+
cpu: 500m
49+
memory: 1Gi
50+
requests:
51+
cpu: 5m
52+
memory: 64Mi
53+
securityContext:
54+
allowPrivilegeEscalation: false
55+
capabilities:
56+
drop:
57+
- ALL
58+
runAsNonRoot: true
59+
terminationMessagePath: /dev/termination-log
60+
terminationMessagePolicy: File
61+
volumeMounts:
62+
- mountPath: /config
63+
name: config-vol
64+
dnsPolicy: ClusterFirst
65+
restartPolicy: Always
66+
volumes:
67+
- configMap:
68+
defaultMode: 420
69+
name: launchpad-monitor-config
70+
name: config-vol
71+
---
72+
apiVersion: v1
73+
kind: Service
74+
metadata:
75+
labels:
76+
app: launchpad-monitor
77+
name: launchpad-monitor
78+
namespace: sealos
79+
spec:
80+
ports:
81+
- name: http
82+
port: 8428
83+
protocol: TCP
84+
targetPort: 8428
85+
selector:
86+
app: launchpad-monitor

Diff for: service/launchpad/go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/labring/sealos/service/launchpad
2+
3+
go 1.20
4+
5+
require (
6+
github.com/labring/sealos/service v0.0.0-00010101000000-000000000000
7+
gopkg.in/yaml.v2 v2.4.0
8+
)
9+
10+
replace github.com/labring/sealos/service => ../../service

Diff for: service/launchpad/main.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"net"
8+
"net/http"
9+
"os"
10+
11+
launchpadServer "github.com/labring/sealos/service/launchpad/server"
12+
)
13+
14+
type RestartableServer struct {
15+
configFile string
16+
}
17+
18+
func (rs *RestartableServer) Serve(c *launchpadServer.Config) {
19+
var vs, err = launchpadServer.NewVMServer(c)
20+
if err != nil {
21+
fmt.Printf("Failed to create auth server: %s\n", err)
22+
return
23+
}
24+
25+
hs := &http.Server{
26+
Addr: c.Server.ListenAddress,
27+
Handler: vs,
28+
}
29+
30+
var listener net.Listener
31+
listener, err = net.Listen("tcp", c.Server.ListenAddress)
32+
if err != nil {
33+
fmt.Println(err)
34+
return
35+
}
36+
fmt.Printf("Serve on %s\n", c.Server.ListenAddress)
37+
38+
if err := hs.Serve(listener); err != nil {
39+
fmt.Println(err)
40+
return
41+
}
42+
}
43+
44+
func main() {
45+
log.SetOutput(os.Stdout) // 将日志输出定向到标准输出(stdout)
46+
log.SetFlags(log.LstdFlags | log.Lshortfile)
47+
flag.Parse()
48+
49+
cf := flag.Arg(0)
50+
if cf == "" {
51+
fmt.Println("Config file not sepcified")
52+
return
53+
}
54+
55+
config, err := launchpadServer.InitConfig(cf)
56+
if err != nil {
57+
fmt.Println(err)
58+
return
59+
}
60+
rs := RestartableServer{
61+
configFile: cf,
62+
}
63+
rs.Serve(config)
64+
}

0 commit comments

Comments
 (0)