|
1 |
| -# OpenIM Application Containerization Deployment Guide |
| 1 | +# Kubernetes Deployment |
2 | 2 |
|
3 |
| -OpenIM supports a variety of cluster deployment methods, including but not limited to `helm`, `sealos`, `kustomize` |
| 3 | +## Resource Requests |
4 | 4 |
|
5 |
| -Various contributors, as well as previous official releases, have provided some referenceable solutions: |
| 5 | +- CPU: 2 cores |
| 6 | +- Memory: 4 GiB |
| 7 | +- Disk usage: 20 GiB (on Node) |
6 | 8 |
|
7 |
| -+ [k8s-jenkins Repository](https://github.com/OpenIMSDK/k8s-jenkins) |
8 |
| -+ [open-im-server-k8s-deploy Repository](https://github.com/openimsdk/open-im-server-k8s-deploy) |
9 |
| -+ [openim-charts Repository](https://github.com/OpenIMSDK/openim-charts) |
10 |
| -+ [deploy-openim Repository](https://github.com/showurl/deploy-openim) |
| 9 | +## Preconditions |
11 | 10 |
|
12 |
| -### Dependency Check |
| 11 | +ensure that you have already deployed the following components: |
13 | 12 |
|
14 |
| -```bash |
15 |
| -Kubernetes: >= 1.16.0-0 |
16 |
| -Helm: >= 3.0 |
17 |
| -``` |
| 13 | +- Redis |
| 14 | +- MongoDB |
| 15 | +- Kafka |
| 16 | +- MinIO |
18 | 17 |
|
19 |
| -### Minimum Configuration |
| 18 | +## Origin Deploy |
20 | 19 |
|
21 |
| -The recommended minimum configuration for a production environment is as follows: |
| 20 | +### Enter the target dir |
22 | 21 |
|
23 |
| -```yaml |
24 |
| -CPU: 4 |
25 |
| -Memory: 8G |
26 |
| -Disk: 100G |
27 |
| -``` |
| 22 | +`cd ./deployments/deploy/` |
28 | 23 |
|
29 |
| -## Configuration File Generation |
| 24 | +### Deploy configs and dependencies |
30 | 25 |
|
31 |
| -We have automated all the files, making the generation of configuration files optional for OpenIM. However, if you desire custom configurations, you can follow the steps below: |
| 26 | +Upate your configMap `openim-config.yml`. **You can check the official docs for more details.** |
32 | 27 |
|
33 |
| -```bash |
34 |
| -$ make init |
35 |
| -# Alternatively, use script: |
36 |
| -# ./scripts/init-config.sh |
37 |
| -``` |
| 28 | +In `openim-config.yml`, you need modify the following configurations: |
38 | 29 |
|
39 |
| -At this point, configuration files will be generated under `deployments/openim/config`, which you can modify as per your requirements. |
| 30 | +**discovery.yml** |
40 | 31 |
|
41 |
| -## Cluster Setup |
| 32 | +- `kubernetes.namespace`: default is `default`, you can change it to your namespace. |
42 | 33 |
|
43 |
| -If you already have a `kubernetes` cluster, or if you wish to build a `kubernetes` cluster from scratch, you can skip this step. |
| 34 | +**mongodb.yml** |
44 | 35 |
|
45 |
| -For a quick start, I used [sealos](https://github.com/labring/sealos) to rapidly set up the cluster, with sealos also being a wrapper for kubeadm at its core: |
| 36 | +- `address`: set to your already mongodb address or mongo Service name and port in your deployed. |
| 37 | +- `database`: set to your mongodb database name.(Need have a created database.) |
| 38 | +- `authSource`: set to your mongodb authSource. (authSource is specify the database name associated with the user's credentials, user need create in this database.) |
46 | 39 |
|
47 |
| -```bash |
48 |
| -$ SEALOS_VERSION=`curl -s https://api.github.com/repos/labring/sealos/releases/latest | grep -oE '"tag_name": "[^"]+"' | head -n1 | cut -d'"' -f4` && \ |
49 |
| - curl -sfL https://raw.githubusercontent.com/labring/sealos/${SEALOS_VERSION}/scripts/install.sh | |
50 |
| - sh -s ${SEALOS_VERSION} labring/sealos |
51 |
| -``` |
| 40 | +**kafka.yml** |
52 | 41 |
|
53 |
| -**Supported Versions:** |
| 42 | +- `address`: set to your already kafka address or kafka Service name and port in your deployed. |
54 | 43 |
|
55 |
| -+ docker: `labring/kubernetes-docker`:(v1.24.0~v1.27.0) |
56 |
| -+ containerd: `labring/kubernetes`:(v1.24.0~v1.27.0) |
| 44 | +**redis.yml** |
57 | 45 |
|
58 |
| -#### Cluster Installation: |
| 46 | +- `address`: set to your already redis address or redis Service name and port in your deployed. |
59 | 47 |
|
60 |
| -Cluster details are as follows: |
| 48 | +**minio.yml** |
61 | 49 |
|
62 |
| -| Hostname | IP Address | System Info | |
63 |
| -| -------- | ---------- | ------------------------------------------------------------ | |
64 |
| -| master01 | 10.0.0.9 | `Linux VM-0-9-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux` | |
65 |
| -| node01 | 10.0.0.4 | Similar to master01 | |
66 |
| -| node02 | 10.0.0.10 | Similar to master01 | |
| 50 | +- `internalAddress`: set to your minio Service name and port in your deployed. |
| 51 | +- `externalAddress`: set to your already expose minio external address. |
67 | 52 |
|
68 |
| -```bash |
69 |
| -$ export CLUSTER_USERNAME=ubuntu |
70 |
| -$ export CLUSTER_PASSWORD=123456 |
71 |
| -$ sudo sealos run labring/kubernetes:v1.25.0 labring/helm:v3.8.2 labring/calico:v3.24.1 \ |
72 |
| - --masters 10.0.0.9 \ |
73 |
| - --nodes 10.0.0.4,10.0.0.10 \ |
74 |
| - -u "$CLUSTER_USERNAME" \ |
75 |
| - -p "$CLUSTER_PASSWORD" |
76 |
| -``` |
| 53 | +### Set the secret |
77 | 54 |
|
78 |
| -> **Node** Uninstallation method: using `kubeadm` for uninstallation does not remove `etcd` and `cni` related configurations. Manual clearance or using `sealos` for uninstallation is needed. |
79 |
| -> |
80 |
| -> ```bash |
81 |
| -> $ sealos reset |
82 |
| -> ``` |
| 55 | +A Secret is an object that contains a small amount of sensitive data. Such as password and secret. Secret is similar to ConfigMaps. |
83 | 56 |
|
84 |
| -If you are local, you can also use Kind and Minikube to test, for example, using Kind: |
| 57 | +#### Redis: |
85 | 58 |
|
86 |
| -```bash |
87 |
| -$ GO111MODULE="on" go get sigs.k8s.io/[email protected] |
88 |
| -$ kind create cluster |
89 |
| -``` |
| 59 | +Update the `redis-password` value in `redis-secret.yml` to your Redis password encoded in base64. |
90 | 60 |
|
91 |
| -### Installing helm |
| 61 | +```yaml |
| 62 | +apiVersion: v1 |
| 63 | +kind: Secret |
| 64 | +metadata: |
| 65 | + name: openim-redis-secret |
| 66 | +type: Opaque |
| 67 | +data: |
| 68 | + redis-password: b3BlbklNMTIz # update to your redis password encoded in base64, if need empty, you can set to "" |
| 69 | +``` |
92 | 70 |
|
93 |
| -Helm simplifies the deployment and management of Kubernetes applications to a large extent by offering version control and release management through packaging. |
| 71 | +#### Mongo: |
94 | 72 |
|
95 |
| -**Using Script:** |
| 73 | +Update the `mongo_openim_username`, `mongo_openim_password` value in `mongo-secret.yml` to your Mongo username and password encoded in base64. |
96 | 74 |
|
97 |
| -```bash |
98 |
| -$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash |
| 75 | +```yaml |
| 76 | +apiVersion: v1 |
| 77 | +kind: Secret |
| 78 | +metadata: |
| 79 | + name: openim-mongo-secret |
| 80 | +type: Opaque |
| 81 | +data: |
| 82 | + 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). |
| 83 | + mongo_openim_password: b3BlbklNMTIz # update to your mongo password encoded in base64, if need empty, you can set to "" |
99 | 84 | ```
|
100 | 85 |
|
101 |
| -**Adding Repository:** |
| 86 | +#### Minio: |
102 | 87 |
|
103 |
| -```bash |
104 |
| -$ helm repo add brigade https://openimsdk.github.io/openim-charts |
| 88 | +Update the `minio-root-user` and `minio-root-password` value in `minio-secret.yml` to your MinIO accessKeyID and secretAccessKey encoded in base64. |
| 89 | + |
| 90 | +```yaml |
| 91 | +apiVersion: v1 |
| 92 | +kind: Secret |
| 93 | +metadata: |
| 94 | + name: openim-minio-secret |
| 95 | +type: Opaque |
| 96 | +data: |
| 97 | + minio-root-user: cm9vdA== # update to your minio accessKeyID encoded in base64, if need empty, you can set to "" |
| 98 | + minio-root-password: b3BlbklNMTIz # update to your minio secretAccessKey encoded in base64, if need empty, you can set to "" |
105 | 99 | ```
|
106 | 100 |
|
107 |
| -### OpenIM Image Strategy |
| 101 | +#### Kafka: |
108 | 102 |
|
109 |
| -Automated offerings include aliyun, ghcr, docker hub: [Image Documentation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) |
| 103 | +Update the `kafka-password` value in `kafka-secret.yml` to your Kafka password encoded in base64. |
110 | 104 |
|
111 |
| -**Local Test Build Method:** |
| 105 | +```yaml |
| 106 | +apiVersion: v1 |
| 107 | +kind: Secret |
| 108 | +metadata: |
| 109 | + name: openim-kafka-secret |
| 110 | +type: Opaque |
| 111 | +data: |
| 112 | + kafka-password: b3BlbklNMTIz # update to your kafka password encoded in base64, if need empty, you can set to "" |
| 113 | +``` |
112 | 114 |
|
113 |
| -```bash |
114 |
| -$ make image |
| 115 | +### Apply the secret. |
| 116 | + |
| 117 | +```shell |
| 118 | +kubectl apply -f redis-secret.yml -f minio-secret.yml -f mongo-secret.yml -f kafka-secret.yml |
115 | 119 | ```
|
116 | 120 |
|
117 |
| -> This command assists in quickly building the required images locally. For a detailed build strategy, refer to the [Build Documentation](https://github.com/openimsdk/open-im-server/blob/main/build/README.md). |
| 121 | +### Apply all config |
118 | 122 |
|
119 |
| -## Installation |
| 123 | +`kubectl apply -f ./openim-config.yml` |
120 | 124 |
|
121 |
| -Explore our Helm-Charts repository and read through: [Helm-Charts Repository](https://github.com/openimsdk/helm-charts) |
| 125 | +> Attation: If you use `default` namespace, you can excute `clusterRile.yml` to create a cluster role binding for default service account. |
| 126 | +> |
| 127 | +> Namespace is modify to `discovery.yml` in `openim-config.yml`, you can change `kubernetes.namespace` to your namespace. |
122 | 128 |
|
| 129 | +**Excute `clusterRole.yml`** |
123 | 130 |
|
124 |
| -Using the helm charts repository, you can ignore the following configuration, but if you want to just use the server and scale on top of it, you can go ahead: |
| 131 | +`kubectl apply -f ./clusterRole.yml` |
125 | 132 |
|
126 |
| -**Use the Helm template to generate the deployment yaml file: `openim-charts.yaml`** |
| 133 | +### run all deployments and services |
127 | 134 |
|
128 |
| -**Gen Image:** |
| 135 | +> Note: Ensure that infrastructure services like MinIO, Redis, and Kafka are running before deploying the main applications. |
129 | 136 |
|
130 | 137 | ```bash
|
131 |
| -../scripts/genconfig.sh ../scripts/install/environment.sh ./templates/helm-image.yaml > ./charts/generated-configs/helm-image.yaml |
| 138 | +kubectl apply \ |
| 139 | + -f openim-api-deployment.yml \ |
| 140 | + -f openim-api-service.yml \ |
| 141 | + -f openim-crontask-deployment.yml \ |
| 142 | + -f openim-rpc-user-deployment.yml \ |
| 143 | + -f openim-rpc-user-service.yml \ |
| 144 | + -f openim-msggateway-deployment.yml \ |
| 145 | + -f openim-msggateway-service.yml \ |
| 146 | + -f openim-push-deployment.yml \ |
| 147 | + -f openim-push-service.yml \ |
| 148 | + -f openim-msgtransfer-service.yml \ |
| 149 | + -f openim-msgtransfer-deployment.yml \ |
| 150 | + -f openim-rpc-conversation-deployment.yml \ |
| 151 | + -f openim-rpc-conversation-service.yml \ |
| 152 | + -f openim-rpc-auth-deployment.yml \ |
| 153 | + -f openim-rpc-auth-service.yml \ |
| 154 | + -f openim-rpc-group-deployment.yml \ |
| 155 | + -f openim-rpc-group-service.yml \ |
| 156 | + -f openim-rpc-friend-deployment.yml \ |
| 157 | + -f openim-rpc-friend-service.yml \ |
| 158 | + -f openim-rpc-msg-deployment.yml \ |
| 159 | + -f openim-rpc-msg-service.yml \ |
| 160 | + -f openim-rpc-third-deployment.yml \ |
| 161 | + -f openim-rpc-third-service.yml |
132 | 162 | ```
|
133 | 163 |
|
134 |
| -**Gen Charts:** |
| 164 | +### Verification |
| 165 | + |
| 166 | +After deploying the services, verify that everything is running smoothly: |
135 | 167 |
|
136 | 168 | ```bash
|
137 |
| -for chart in ./charts/*/; do |
138 |
| - if [[ "$chart" == *"generated-configs"* || "$chart" == *"helmfile.yaml"* ]]; then |
139 |
| - continue |
140 |
| - fi |
141 |
| - |
142 |
| - if [ -f "${chart}values.yaml" ]; then |
143 |
| - helm template "$chart" -f "./charts/generated-configs/helm-image.yaml" -f "./charts/generated-configs/config.yaml" -f "./charts/generated-configs/notification.yaml" >> openim-charts.yaml |
144 |
| - else |
145 |
| - helm template "$chart" >> openim-charts.yaml |
146 |
| - fi |
147 |
| -done |
148 |
| -``` |
| 169 | +# Check the status of all pods |
| 170 | +kubectl get pods |
149 | 171 |
|
150 |
| -**Use Helmfile:** |
| 172 | +# Check the status of services |
| 173 | +kubectl get svc |
151 | 174 |
|
152 |
| -```bash |
153 |
| -GO111MODULE=on go get github.com/roboll/helmfile@latest |
154 |
| -``` |
| 175 | +# Check the status of deployments |
| 176 | +kubectl get deployments |
155 | 177 |
|
156 |
| -```bash |
157 |
| -export MONGO_ADDRESS=im-mongo |
158 |
| -export MONGO_PORT=27017 |
159 |
| -export REDIS_ADDRESS=im-redis-master |
160 |
| -export REDIS_PORT=6379 |
161 |
| -export KAFKA_ADDRESS=im-kafka |
162 |
| -export KAFKA_PORT=9092 |
163 |
| -export OBJECT_APIURL="https://openim.server.com/api" |
164 |
| -export MINIO_ENDPOINT="http://im-minio:9000" |
165 |
| -export MINIO_SIGN_ENDPOINT="https://openim.server.com/im-minio-api" |
166 |
| - |
167 |
| -mkdir ./charts/generated-configs |
168 |
| -../scripts/genconfig.sh ../scripts/install/environment.sh ./templates/config.yaml > ./charts/generated-configs/config.yaml |
169 |
| -cp ../config/notification.yaml ./charts/generated-configs/notification.yaml |
170 |
| -../scripts/genconfig.sh ../scripts/install/environment.sh ./templates/helm-image.yaml > ./charts/generated-configs/helm-image.yaml |
| 178 | +# View all resources |
| 179 | +kubectl get all |
171 | 180 | ```
|
172 | 181 |
|
173 |
| -```bash |
174 |
| -helmfile apply |
175 |
| -``` |
| 182 | +### clean all |
| 183 | + |
| 184 | +`kubectl delete -f ./` |
| 185 | + |
| 186 | +### Notes: |
| 187 | + |
| 188 | +- If you use a specific namespace for your deployment, be sure to append the -n <namespace> flag to your kubectl commands. |
0 commit comments