Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update kubernetes deployment files. #617

Merged
merged 12 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use Go 1.21 Alpine as the base image for building the application
FROM golang:1.21-alpine as builder
FROM golang:1.22-alpine as builder

# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-chat
Expand All @@ -22,7 +22,7 @@ RUN go install github.com/magefile/[email protected]
RUN mage build

# Using Alpine Linux with Go environment for the final image
FROM golang:1.21-alpine
FROM golang:1.22-alpine

# Install necessary packages, such as bash
RUN apk add --no-cache bash
Expand Down
122 changes: 122 additions & 0 deletions deployments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# OpenIM Chat Deployment

## Preconditions

- Ensure deployed OpenIM Server and its dependencies.
- Redis
- MongoDB
- Kafka
- MinIO
- Expose the corresponding Services and ports of OpenIM Server.

## Deploy OpenIM Chat

**Chat depends on OpenIM Server, so you need to deploy OpenIM Server first.**

enter the target directory

```shell
cd deployments/deploy
```

### Modify ConfigMap

You need to modify the `chat-config.yml` file to match your environment. Focus on the following fields:
**discovery.yml**

- `kubernetes.namespace`: default is `default`, you can change it to your namespace.

**mongodb.yml**

- `address`: set to your already mongodb address or mongo Service name and port in your deployed.
- `database`: set to your mongodb database name.(Need have a created database.)
- `authSource`: et to your mongodb authSource. (authSource is specify the database name associated with the user's credentials, user need create in this database.)

**redis.yml**

- `address`: set to your already redis address or redis Service name and port in your deployed.

**share.yml**

- `openIM.apiURL`: modify to your already API address or use your `openim-api` service name and port
- `openIM.secret`: same to IM Server `share.secret` value.

### Set the secret

A Secret is an object that contains a small amount of sensitive data. Such as password and secret. Secret is similar to ConfigMaps.

#### Redis:

Update the `redis-password` value in `redis-secret.yml` to your Redis password encoded in base64.

```yaml
apiVersion: v1
kind: Secret
metadata:
name: openim-redis-secret
type: Opaque
data:
redis-password: b3BlbklNMTIz # update to your redis password encoded in base64, if need empty, you can set to ""
```

#### Mongo:

Update the `mongo_openim_username`, `mongo_openim_password` value in `mongo-secret.yml` to your Mongo username and password encoded in base64.

```yaml
apiVersion: v1
kind: Secret
metadata:
name: openim-mongo-secret
type: Opaque
data:
mongo_openim_username: b3BlbklN # update to your mongo username encoded in base64, if need empty, you can set to "" (this user credentials need in authSource database)
mongo_openim_password: b3BlbklNMTIz # update to your mongo password encoded in base64, if need empty, you can set to ""
```

### Apply the secret.

```shell
kubectl apply -f redis-secret.yml -f mongo-secret.yml
```

### Apply Config and Services

deploy the config and services

```shell
kubectl apply -f chat-config.yml -f openim-admin-api-service.yml -f openim-chat-api-service.yml -f openim-admin-rpc-service.yml -f openim-chat-rpc-service.yml
```

### Start Chat Deployments

```shell
kubectl apply -f openim-chat-api-deployment.yml -f openim-admin-api-deployment.yml -f openim-chat-rpc-deployment.yml -f openim-admin-rpc-deployment.yml
```

## Verify

After the deployment is complete, you can verify the deployment status.

```shell
# Check the status of all pods
kubectl get pods

# Check the status of services
kubectl get svc

# Check the status of deployments
kubectl get deployments

# View all resources
kubectl get all

```

## clean all

`kubectl delete -f ./`

## Notes:

- If you use a specific namespace for your deployment, be sure to append the -n <namespace> flag to your kubectl commands.
148 changes: 148 additions & 0 deletions deployments/deploy/chat-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: openim-chat-config
data:
discovery.yml: |
enable: kubernetes
kubernetes:
namespace: default
etcd:
rootDirectory: openim
address: [ localhost:12379 ]
username: ''
password: ''

rpcService:
chat: chat-rpc-service
admin: admin-rpc-service

log.yml: |
# Log storage path, default is acceptable, change to a full path if modification is needed
# storageLocation: ../../../../logs/
storageLocation: ./logs/
# Log rotation period (in hours), default is acceptable
rotationTime: 24
# Number of log files to retain, default is acceptable
remainRotationCount: 2
# Log level settings: 3 for production environment; 6 for more verbose logging in debugging environments
remainLogLevel: 6
# Whether to output to standard output, default is acceptable
isStdout: true
# Whether to log in JSON format, default is acceptable
isJson: false
# output simplify log when KeyAndValues's value len is bigger than 50 in rpc method log
isSimplify: true

mongodb.yml: |
# URI for database connection, leave empty if using address and credential settings directly
uri: ''
# List of MongoDB server addresses
address: [ mongo-service:37017 ]
# Name of the database
database: openim_v3
# Username for database authentication
username: openIM
# Password for database authentication
password: # openIM123
# Authentication source for database authentication, if use root user, set it to admin
authSource: openim_v3
# Maximum number of connections in the connection pool
maxPoolSize: 100
# Maximum number of retry attempts for a failed database connection
maxRetry: 10

redis.yml: |
# List of Redis server addresses
address: [ redis-service:16379 ]
# Username for Redis authentication (leave blank if not used)
username: ''
# Password for Redis authentication
password: # openIM123
# Enable or disable pipeline processing
enablePipeline: false
# Enable or disable cluster mode
clusterMode: false
# Database index to be used
db: 0
# Maximum number of retry attempts for a failed connection
maxRetry: 10

share.yml: |
openIM:
# OpenIM API address
apiURL: http://openim-api-service:10002
# OpenIM secret key, must be consistent with OpenIM
secret: openIM123
# OpenIM administrator userID, must be consistent with OpenIM
adminUserID: imAdmin

chatAdmin:
# Default username and password for the admin
- "chatAdmin"

chat-api-admin.yml: |
api:
# Listening IP; 0.0.0.0 means both internal and external IPs are listened to, default is recommended
listenIP: 0.0.0.0
# Listening ports; if multiple are configured, multiple instances will be launched
ports: [ 10009 ]

chat-rpc-admin.yml: |
rpc:
# The IP address where this RPC service registers itself; if left blank, it defaults to the internal network IP
registerIP: ''
# IP address that the RPC service listens on; setting to 0.0.0.0 listens on both internal and external IPs. If left blank, it automatically uses the internal network IP
listenIP: 0.0.0.0
# List of ports that the RPC service listens on; configuring multiple ports will launch multiple instances.
ports: [ 30200 ]

tokenPolicy:
expire: 90

secret: chat123
chat-api-chat.yml: |
api:
# Listening IP; 0.0.0.0 means both internal and external IPs are listened to, default is recommended
listenIP: 0.0.0.0
# Listening ports; if multiple are configured, multiple instances will be launched
ports: [ 10008 ]

chat-rpc-chat.yml: |
rpc:
# The IP address where this RPC service registers itself; if left blank, it defaults to the internal network IP
registerIP: ''
# IP address that the RPC service listens on; setting to 0.0.0.0 listens on both internal and external IPs. If left blank, it automatically uses the internal network IP
listenIP: 0.0.0.0
# List of ports that the RPC service listens on; configuring multiple ports will launch multiple instances.
ports: [ 30300 ]

verifyCode:
validTime: 300
validCount: 5
uintTime: 86400
maxCount: 10
superCode: "666666"
len: 6
phone:
use: ""
ali:
endpoint: ""
accessKeyId: ""
accessKeySecret: ""
signName: ""
verificationCodeTemplateCode: ""
mail:
enable: false
title: ""
senderMail: ""
senderAuthorizationCode: ""
smtpAddr: ""
smtpPort:

liveKit:
url: "ws://127.0.0.1:7880" # LIVEKIT_URL, LiveKit server address and port
key: "APIGPW3gnFTzqHH"
secret: "23ztfSqsfQ8hKkHzHTl3Z4bvaxro0snjk5jwbp5p6Q3"

allowRegister: true
8 changes: 8 additions & 0 deletions deployments/deploy/mongo-secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: openim-mongo-secret
type: Opaque
data:
mongo_openim_username: b3BlbklN # base64 for "openIM", this user credentials need in authSource database.
mongo_openim_password: b3BlbklNMTIz # base64 for "openIM123"
46 changes: 46 additions & 0 deletions deployments/deploy/openim-admin-api-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: admin-api-server
spec:
replicas: 1
selector:
matchLabels:
app: admin-api-server
template:
metadata:
labels:
app: admin-api-server
spec:
containers:
- name: openim-admin-api-container
image: openim/openim-admin-api:v3.8.3
env:
- name: CONFIG_PATH
value: "/config"
- name: CHATENV_REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
key: redis-password
- name: IMENV_MONGODB_USERNAME
valueFrom:
secretKeyRef:
name: openim-mongo-secret
key: mongo_openim_username
- name: CHATENV_MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo_openim_password

volumeMounts:
- name: openim-chat-config
mountPath: "/config"
readOnly: true
ports:
- containerPort: 10009
volumes:
- name: openim-chat-config
configMap:
name: openim-chat-config
13 changes: 13 additions & 0 deletions deployments/deploy/openim-admin-api-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: admin-api-service
spec:
selector:
app: admin-api-server
ports:
- name: http-10009
protocol: TCP
port: 10009
targetPort: 10009
type: NodePort
Loading
Loading