Skip to content

Commit

Permalink
deployment添加configmap映射 && 去掉服务自定义端口号,通过service做端口映射
Browse files Browse the repository at this point in the history
  • Loading branch information
Weaxs committed Jul 18, 2023
1 parent 20b9256 commit 2aaa61e
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ payment/warehouse 模块提供了protobuf协议的RPC接口

[viper接入configmap](https://medium.com/@xcoulon/kubernetes-configmap-hot-reload-in-action-with-viper-d413128a1c9a)

[Deployment添加ConfigMap和Secret映射](https://medium.com/@xcoulon/managing-pod-configuration-using-configmaps-and-secrets-in-kubernetes-93a2de9449be)

[golang微服务示例](https://github.com/EwanValentine/shippy)

2 changes: 1 addition & 1 deletion bookstore-domain-account/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENV GO111MODULE=on \
PORT=8810

COPY *.go ./
COPY *.toml ./
COPY go.mod go.sum ./
RUN go mod tidy
RUN CGO_ENABLED=0 go build -o bookstore-domain-account *.go
Expand All @@ -21,6 +20,7 @@ RUN apk --no-cache add ca-certificates

RUN mkdir /app
WORKDIR /app
COPY conf/*.toml conf/
COPY --from=builder /app/bookstore-domain-account .

EXPOSE $PORT
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions bookstore-domain-account/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
"log"
"net"
)

func main() {
initLog()
addr, err := net.ResolveTCPAddr("tcp", ":8810")
if err != nil {
panic(any(err))
}
//addr, err := net.ResolveTCPAddr("tcp", ":8810")
//if err != nil {
// panic(any(err))
//}

var options []server.Option
// service address
options = append(options, server.WithServiceAddr(addr))
//options = append(options, server.WithServiceAddr(addr))
// Multiplexing
options = append(options, server.WithMuxTransport())

Expand Down
2 changes: 1 addition & 1 deletion bookstore-domain-payment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENV GO111MODULE=on \
PORT=8812

COPY *.go ./
COPY *.toml ./
COPY go.mod go.sum ./
RUN go mod tidy
RUN CGO_ENABLED=0 go build -o bookstore-domain-payment *.go
Expand All @@ -21,6 +20,7 @@ RUN apk --no-cache add ca-certificates

RUN mkdir /app
WORKDIR /app
COPY conf/*.toml conf/
COPY --from=builder /app/bookstore-domain-payment .

EXPOSE $PORT
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions bookstore-domain-payment/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
"log"
"net"
)

func main() {
initLog()
addr, err := net.ResolveTCPAddr("tcp", ":8812")
if err != nil {
panic(any(err))
}
//addr, err := net.ResolveTCPAddr("tcp", ":8812")
//if err != nil {
// panic(any(err))
//}

var options []server.Option
// service address
options = append(options, server.WithServiceAddr(addr))
//options = append(options, server.WithServiceAddr(addr))
// Multiplexing
options = append(options, server.WithMuxTransport())

Expand Down
2 changes: 1 addition & 1 deletion bookstore-domain-warehouse/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENV GO111MODULE=on \
PORT=8811

COPY *.go ./
COPY *.toml ./
COPY go.mod go.sum ./
RUN go mod tidy
RUN CGO_ENABLED=0 go build -o bookstore-domain-warehouse *.go
Expand All @@ -21,6 +20,7 @@ RUN apk --no-cache add ca-certificates

RUN mkdir /app
WORKDIR /app
COPY conf/*.toml conf/
COPY --from=builder /app/bookstore-domain-warehouse .

EXPOSE $PORT
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions bookstore-domain-warehouse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
"log"
"net"
)

func main() {
initLog()
addr, err := net.ResolveTCPAddr("tcp", ":8811")
if err != nil {
panic(any(err))
}
//addr, err := net.ResolveTCPAddr("tcp", ":8811")
//if err != nil {
// panic(any(err))
//}

var options []server.Option
// service address
options = append(options, server.WithServiceAddr(addr))
//options = append(options, server.WithServiceAddr(addr))
// Multiplexing
options = append(options, server.WithMuxTransport())

Expand Down
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/account-configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data:
host = "host.docker.internal"
port = 3306
user = "root"
password = ""
password = "12345678"
database = "bookstore"
16 changes: 14 additions & 2 deletions bookstore-kubernetes-manifests/account-deployment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bookstore-microservices-domain-account
name: bookstore-domain-account
namespace: bookstore-microservices
labels:
app: account
Expand All @@ -20,4 +20,16 @@ spec:
- name: account
image: icyfenix/bookstore-domain-account
ports:
- containerPort: 8810
- containerPort: 8888
name: rpc-server
env:
- name: CONFIG_PATH
value: /app/conf/config.toml
volumeMounts:
- name: config-volume
mountPath: /app/conf
# 映射configmap
volumes:
- name: config-volume
configMap:
name: account
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/account-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
app: account
ports:
- port: 8810
targetPort: server
targetPort: rpc-server
11 changes: 11 additions & 0 deletions bookstore-kubernetes-manifests/gateway-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ spec:
ports:
- name: http-server
containerPort: 8888
env:
- name: CONFIG_PATH
value: /app/conf/config.toml
volumeMounts:
- name: config-volume
mountPath: /app/conf
# 映射configmap
volumes:
- name: config-volume
configMap:
name: gateway
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/payment-configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data:
host = "host.docker.internal"
port = 3306
user = "root"
password = ""
password = "12345678"
database = "bookstore"
[account.client]
Expand Down
15 changes: 13 additions & 2 deletions bookstore-kubernetes-manifests/payment-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ spec:
- name: payment
image: icyfenix/bookstore-domain-payment
ports:
- name: server
containerPort: 8812
- name: rpc-server
containerPort: 8888
env:
- name: CONFIG_PATH
value: /app/conf/config.toml
volumeMounts:
- name: config-volume
mountPath: /app/conf
# 映射configmap
volumes:
- name: config-volume
configMap:
name: payment
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/payment-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
app: payment
ports:
- port: 8812
targetPort: server
targetPort: rpc-server
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/warehouse-configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data:
host = "host.docker.internal"
port = 3306
user = "root"
password = ""
password = "12345678"
database = "bookstore"
16 changes: 14 additions & 2 deletions bookstore-kubernetes-manifests/warehouse-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ spec:
labels:
app: warehouse
spec:
serviceAccountName: book-admin
containers:
- name: warehouse
image: icyfenix/bookstore-domain-warehouse
ports:
- containerPort: 8811
name: server
- containerPort: 8888
name: rpc-server
env:
- name: CONFIG_PATH
value: /app/conf/config.toml
volumeMounts:
- name: config-volume
mountPath: /app/conf
# 映射configmap
volumes:
- name: config-volume
configMap:
name: warehouse
2 changes: 1 addition & 1 deletion bookstore-kubernetes-manifests/warehouse-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
app: warehouse
ports:
- port: 8811
targetPort: http-server
targetPort: rpc-server
2 changes: 1 addition & 1 deletion bookstore-platform-gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENV GO111MODULE=on \
PORT=8888

COPY *.go ./
COPY *.toml ./
COPY go.mod go.sum ./
RUN go mod tidy
RUN CGO_ENABLED=0 go build -o bookstore-platform-gateway *.go
Expand All @@ -21,6 +20,7 @@ RUN apk --no-cache add ca-certificates

RUN mkdir /app
WORKDIR /app
COPY conf/*.toml conf/
COPY --from=builder /app/bookstore-platform-gateway .

EXPOSE $PORT
Expand Down
File renamed without changes.

0 comments on commit 2aaa61e

Please sign in to comment.