Skip to content

Commit

Permalink
Launchpad (#4645)
Browse files Browse the repository at this point in the history
* 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 <lingdie.yy@outlook.com>

Signed-off-by: yy <lingdie.yy@outlook.com>

---------

Signed-off-by: yy <lingdie.yy@outlook.com>
Co-authored-by: yy <56745951+lingdie@users.noreply.github.com>
Co-authored-by: yy <lingdie.yy@outlook.com>
  • Loading branch information
3 people committed Apr 1, 2024
1 parent 900d3fc commit 48b18e0
Show file tree
Hide file tree
Showing 18 changed files with 620 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/services.yml
Expand Up @@ -87,7 +87,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio]
module: [database, pay, account, minio, launchpad]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio]
module: [database, pay, account, minio, launchpad]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions frontend/providers/applaunchpad/deploy/Kubefile
Expand Up @@ -10,5 +10,6 @@ ENV cloudPort=""

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

CMD ["kubectl apply -f manifests"]
Expand Up @@ -45,6 +45,8 @@ spec:
- env:
- name: SEALOS_DOMAIN
value: {{ .cloudDomain }}
- name: MONITOR_URL
value {{ .monitorUrl }}
- name: DOMAIN_PORT
value: "{{ if .cloudPort }}:{{ .cloudPort }}{{ end }}"
- name: INGRESS_SECRET
Expand Down
7 changes: 4 additions & 3 deletions scripts/cloud/install.sh
Expand Up @@ -29,7 +29,7 @@ openebs_version=${openebs_version:-"3.10.0"}
ingress_nginx_version=${ingress_nginx_version:-"1.9.4"}
kubeblocks_version=${kubeblocks_version:-"0.8.2"}
metrics_server_version=${metrics_server_version:-"0.6.4"}
kube_prometheus_stack_version=${kube_prometheus_stack_version:-"0.70.0"}
victoria_metrics_k8s_stack_version=${victoria_metrics_k8s_stack_version:-"1.96.0"}


# Define English and Chinese prompts
Expand Down Expand Up @@ -256,7 +256,7 @@ init() {
pull_image "kubeblocks-postgresql" "v${kubeblocks_version#v:-0.8.2}"
pull_image "kubeblocks-mongodb" "v${kubeblocks_version#v:-0.8.2}"
pull_image "metrics-server" "v${metrics_server_version#v:-0.6.4}"
pull_image "kube-prometheus-stack" "v${kube_prometheus_stack_version#v:-0.63.0}"
pull_image "victoria-metrics-k8s-stack" "v${victoria_metrics_k8s_stack_version#v:-1.96.0}"
pull_image "sealos-cloud" "${cloud_version}"
}

Expand Down Expand Up @@ -649,7 +649,8 @@ EOF
kbcli addon enable snapshot-controller

get_prompt "installing_monitoring"
sealos run "${image_registry}/${image_repository}/kube-prometheus-stack:v${kube_prometheus_stack_version#v:-0.63.0}"
sealos run "${image_registry}/${image_repository}/victoria-metrics-k8s-stack:v${victoria_metrics_k8s_stack_version#v:-1.96.0}"

kubectl patch cm kb-addon-prometheus-server -n kb-system --patch-file $CLOUD_DIR/kb-addon-prometheus-server-patch.yaml

get_prompt "patching_ingress"
Expand Down
1 change: 1 addition & 0 deletions service/go.work
Expand Up @@ -4,6 +4,7 @@ use (
./database
./pay
./account
./launchpad
.
)

Expand Down
9 changes: 9 additions & 0 deletions service/launchpad/Dockerfile
@@ -0,0 +1,9 @@
# FROM scratch
FROM gcr.io/distroless/static:nonroot
# FROM gengweifeng/gcr-io-distroless-static-nonroot
ARG TARGETARCH
COPY bin/service-launchpad-$TARGETARCH /manager
EXPOSE 9090
USER 65532:65532

ENTRYPOINT ["/manager"]
55 changes: 55 additions & 0 deletions service/launchpad/Makefile
@@ -0,0 +1,55 @@
IMG ?= ghcr.io/labring/sealos-launchpad-service:latest

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# only support linux, non cgo
PLATFORMS ?= linux_arm64 linux_amd64
GOOS=linux
CGO_ENABLED=0
GOARCH=$(shell go env GOARCH)

GO_BUILD_FLAGS=-trimpath -ldflags "-s -w"

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@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)

##@ Build

.PHONY: clean
clean:
rm -f $(SERVICE_NAME)

.PHONY: build
build: clean ## Build service-hub binary.
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go build $(GO_BUILD_FLAGS) -o bin/manager main.go

.PHONY: docker-build
docker-build: build
mv bin/manager bin/service-launchpad-${TARGETARCH}
docker build -t $(IMG) .

.PHONY: docker-push
docker-push:
docker push $(IMG)
54 changes: 54 additions & 0 deletions service/launchpad/README.md
@@ -0,0 +1,54 @@
# RESTServer

## Description

restserver for database monitoring

## Getting Started

### Running on the cluster

1. Build and push your image to the location specified by `IMG`:

```sh
make docker-build docker-push IMG=<some-registry>/sealos-cloud-database-monitor:tag
```

2. Deploy the restserver:

```sh
kubectl apply -f deploy/manifests/
```

### How it works

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.

Additionally, to configure the data source, you need to set the environment variable `VM_SERVICE_HOST` of the restserver deployment to the correct address.

```
e.g.
http://prometheus.sealos.svc.cluster.local
```

## License

Copyright 2023.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.
2 changes: 2 additions & 0 deletions service/launchpad/config/config.yml
@@ -0,0 +1,2 @@
server:
addr: ":8428"
5 changes: 5 additions & 0 deletions service/launchpad/deploy/Kubefile
@@ -0,0 +1,5 @@
FROM scratch
COPY registry registry
COPY manifests manifests

CMD ["kubectl apply -f manifests/deploy.yaml"]
16 changes: 16 additions & 0 deletions service/launchpad/deploy/README.md
@@ -0,0 +1,16 @@
### docker image build and deploy
```bash
make docker-build IMG=$(YourImageName)
# edit deploy/manifests/depoly.yaml and deploy
kubectl apply -f deploy/manifests/depoly.yaml
```

### cluster image build and deploy
```bash
```

### Victoria Metrics

In order to prevent performance degradation or abnormal behavior caused by excessive data size in Prometheus, VictoriaMetrics is utilized for data collection.

> By default, we use kb-prometheus-server for the data collection service.
86 changes: 86 additions & 0 deletions service/launchpad/deploy/manifests/deploy.yaml
@@ -0,0 +1,86 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor-config
namespace: sealos
data:
config.yml: |
server:
addr: ":8428"
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor-deployment
namespace: sealos
spec:
replicas: 1
selector:
matchLabels:
app: launchpad-monitor
strategy:
type: Recreate
template:
metadata:
labels:
app: launchpad-monitor
spec:
containers:
- args:
- /config/config.yml
command:
- /manager
env:
- name: VM_SERVICE_HOST
value: http://vmsingle-victoria-metrics-k8s-stack.vm.svc:8429
image: ghcr.io/labring/sealos-launchpad-service:latest
imagePullPolicy: Always
name: launchpad-monitor
ports:
- containerPort: 8428
protocol: TCP
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 5m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
runAsNonRoot: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /config
name: config-vol
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
name: launchpad-monitor-config
name: config-vol
---
apiVersion: v1
kind: Service
metadata:
labels:
app: launchpad-monitor
name: launchpad-monitor
namespace: sealos
spec:
ports:
- name: http
port: 8428
protocol: TCP
targetPort: 8428
selector:
app: launchpad-monitor
10 changes: 10 additions & 0 deletions service/launchpad/go.mod
@@ -0,0 +1,10 @@
module github.com/labring/sealos/service/launchpad

go 1.20

require (
github.com/labring/sealos/service v0.0.0-00010101000000-000000000000
gopkg.in/yaml.v2 v2.4.0
)

replace github.com/labring/sealos/service => ../../service
64 changes: 64 additions & 0 deletions service/launchpad/main.go
@@ -0,0 +1,64 @@
package main

import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"

launchpadServer "github.com/labring/sealos/service/launchpad/server"
)

type RestartableServer struct {
configFile string
}

func (rs *RestartableServer) Serve(c *launchpadServer.Config) {
var vs, err = launchpadServer.NewVMServer(c)
if err != nil {
fmt.Printf("Failed to create auth server: %s\n", err)
return
}

hs := &http.Server{
Addr: c.Server.ListenAddress,
Handler: vs,
}

var listener net.Listener
listener, err = net.Listen("tcp", c.Server.ListenAddress)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Serve on %s\n", c.Server.ListenAddress)

if err := hs.Serve(listener); err != nil {
fmt.Println(err)
return
}
}

func main() {
log.SetOutput(os.Stdout) // 将日志输出定向到标准输出(stdout)
log.SetFlags(log.LstdFlags | log.Lshortfile)
flag.Parse()

cf := flag.Arg(0)
if cf == "" {
fmt.Println("Config file not sepcified")
return
}

config, err := launchpadServer.InitConfig(cf)
if err != nil {
fmt.Println(err)
return
}
rs := RestartableServer{
configFile: cf,
}
rs.Serve(config)
}

0 comments on commit 48b18e0

Please sign in to comment.