docs: add k8s simple deploy tutorial document

pull/90/head
moonrailgun 2 years ago
parent 1856be3539
commit 6834d0477f

@ -1,3 +1,3 @@
Only have one tailchat instance version. Only have one tailchat instance version.
Not include **openapi** and **plugins** Not include **openapi** and **admin**

@ -0,0 +1,4 @@
{
"label": "Kubernetes",
"position": 50
}

@ -0,0 +1,117 @@
---
sidebar_position: 1
title: Simple Deployment
---
## Introduction
Kubernetes is an open-source container orchestration platform used for automating the deployment, scaling, and management of containerized applications. It provides a way to orchestrate containers, automating tasks such as deployment, scheduling, load balancing, and fault recovery, making containerized applications run efficiently in a distributed system.
Advantages of Kubernetes include:
- Automation: Kubernetes automates tasks such as deployment, scheduling, load balancing, and fault recovery, reducing the amount of manual work required.
- Scalability: Kubernetes can manage thousands of containerized applications in large-scale clusters, with good horizontal and vertical scalability.
- Flexibility: Kubernetes supports multiple container runtimes and multiple cloud platforms, allowing applications to be deployed and managed in different environments.
- Reliability: Kubernetes provides powerful fault recovery mechanisms and self-healing capabilities, ensuring high availability and reliability of applications.
- Community support: Kubernetes is an active open-source project with a large community support and ecosystem, allowing for quick updates and support.
## Quick Start
If you want to deploy the Tailchat project on Kubernetes, you can find the prepared simple Tailchat deployment configuration in the `docker/simple/k8s` subdirectory of the project directory. These configuration files include Kubernetes resource definitions for running Tailchat, such as StatefulSet, Service, and dependencies such as databases and persistent storage. These resource definitions allow you to quickly deploy a simple Tailchat project on Kubernetes without manually creating and configuring these resources.
:::info
Note that the deployed Tailchat in this tutorial does not include the complete Tailchat ecosystem, such as the **Open Platform** and **Admin Management Platform**.
:::
### Environment Dependencies
To start this chapter, we assume that you have a working Kubernetes environment ready. This section does not describe how to set up a k8s environment.
### Getting Started
First, we need to clone the project repository:
```bash
git clone git@github.com:msgbyte/tailchat.git
```
Change the working directory to the configuration file directory:
```bash
cd docker/simple/k8s
```
At this point, you can see many prepared configuration files, and we can start by running a single command:
```bash
kubectl apply -f namespace.yml -f pv.yml -f mongo.yml -f minio.yml -f redis.yml -f tailchat.yml
```
This command will create the `namespace`, create `pv` and `pvc`, create `mongodb`, `minio`, `redis`, and other necessary third-party middleware, and finally start a multi-instance `tailchat` service.
You can check the status of each service using the following command:
```bash
kubectl get svc -n tailchat
```
### Routing and Load Balancing
When all services are ready, our Tailchat service is now running in the cluster, but we cannot access it because it has not been exposed to the outside.
For local testing, we can use the `port forward` function to map the port of a pod to the local machine. In a production environment, however, we need to build routing and forwarding.
Taking `traefik` as an example:
> Traefik is an open-source reverse proxy and load balancer designed specifically for routing and load balancing traffic in containerized applications and microservices architectures. Traefik supports multiple backend services, including Docker, Kubernetes, Mesos, Swarm, Consul, Etcd, and more. It can automatically discover and configure backend services and route traffic to the corresponding service instances based on rules.
#### Installing Helm and Adding Repository Address
The installation of `helm` is not discussed here. We execute the following command to add `traefik` to the repository list:
```bash
helm repo add traefik https://helm.traefik.io/traefik
```
#### Installing Traefik in the Tailchat Namespace
```bash
helm install traefik traefik/traefik -n tailchat
```
#### Starting Ingress Resource Declaration
```bash
kubectl apply -f ingress.yml
```
If everything is ok, you can see the following output using the following command:
```bash
kubectl get services -n tailchat
```
![](/img/kubernetes/traefik-svc.png)
#### Setting up DNS Services
You can modify the domain address configuration in the `ingress.yml` mentioned above, which defaults to `http://tailchat.internal.com/`.
If you do not wish to modify or do not have a domain name, you can modify the `hosts` file to achieve this:
```bash
sudo vim /etc/hosts
```
Then add the following path:
```
127.0.0.1 tailchat.internal.com
```
Now you can open your browser and visit `http://tailchat.internal.com` to access the Tailchat service deployed on Kubernetes.
Of course, you can also check the availability of the service by visiting the following address:
```
http://tailchat.internal.com/health
```

@ -0,0 +1,116 @@
---
sidebar_position: 1
title: 简单部署
---
## 简介
Kubernetes 是一个开源的容器编排平台,用于自动化部署、扩展和管理容器化应用程序。它提供了一种容器编排的方法,可以自动化容器的部署、调度、负载均衡和故障恢复等任务,使得容器化应用程序可以在分布式系统中高效地运行。
Kubernetes 的优点包括:
- 自动化Kubernetes 可以自动化容器的部署、调度、负载均衡和故障恢复等任务,减少了人工干预的工作量。
- 可扩展性Kubernetes 可以在大规模集群中管理数千个容器化应用程序,具有良好的水平扩展性和垂直扩展性。
- 灵活性Kubernetes 支持多种容器运行时和多种云平台,可以在不同的环境中部署和管理应用程序。
- 可靠性Kubernetes 提供了强大的故障恢复机制和自我修复能力,可以确保应用程序的高可用性和可靠性。
- 社区支持Kubernetes 是一个活跃的开源项目,有庞大的社区支持和生态系统,可以快速获取更新和支持。
## 快速入门
如果您想要在 Kubernetes 上部署 Tailchat 项目,那么您可以在项目目录中的 `docker/simple/k8s` 子目录中找到已经准备好的简单 Tailchat 部署配置。这些配置文件包括了用于运行 Tailchat 的 Kubernetes 资源定义,例如 StatefulSet、Service 和 依赖的数据库、持久化存储 等等。这些资源定义可以让您快速地在 Kubernetes 上部署一个简单的 Tailchat 项目,而无需手动创建和配置这些资源。
:::info
需要注意的是,本教程部署的 Tailchat 不包含完整的 Tailchat 生态如**开放平台**与**Admin后台管理平台**
:::
### 环境依赖
为了开始本章的内容,我们假设你已经准备好了一个可用的 kubernetes 环境,关于如何搭建 k8s 环境本节不进行赘述。
### 开始
首先我们需要clone项目仓库:
```bash
git clone git@github.com:msgbyte/tailchat.git
```
将工作目录切到配置文件目录
```bash
cd docker/simple/k8s
```
此时我们可以看到有许多已经准备好了的配置文件,我们可以通过一条命令直接启动:
```bash
kubectl apply -f namespace.yml -f pv.yml -f mongo.yml -f minio.yml -f redis.yml -f tailchat.yml
```
这条命令会依次执行创建`namespace`、创建`pv`和`pvc`、创建`mongodb`、`minio`、`redis`等必须的第三方中间件,最后启动一个多实例的 `tailchat` 服务。
你可以通过以下命令检测各个服务的状态:
```bash
kubectl get svc -n tailchat
```
### 路由与负载均衡。
当所有的服务都就绪后我们的Tailchat服务目前已经在集群中运行起来了但是此时我们还无法访问因为还没有暴露在外部。
对于本地测试,我们可以用`port forward`功能将一个pod的端口映射到本地。而在生产环境我们则需要构建路由转发。
`traefik` 为例:
> Traefik 是一款开源的反向代理和负载均衡器专门用于处理容器化应用程序和微服务架构中的流量路由和负载均衡。Traefik 支持多种后端服务,包括 Docker、Kubernetes、Mesos、Swarm、Consul、Etcd 等等。它可以自动地发现和配置后端服务,并根据规则将流量路由到相应的服务实例。
#### 安装helm, 并增加仓库地址
`helm` 的安装不做赘述。我们执行以下命令将`traefik`添加到仓库列表
```bash
helm repo add traefik https://helm.traefik.io/traefik
```
#### 在 tailchat 命名空间中安装traefik
```bash
helm install traefik traefik/traefik -n tailchat
```
#### 启动 ingress 资源声明
```bash
kubectl apply -f ingress.yml
```
如果一切正常,则通过以下命令可以看到如下输出
```bash
kubectl get services -n tailchat
```
![](/img/kubernetes/traefik-svc.png)
#### 设置DNS服务
你可以在上述的`ingress.yml`中修改域名地址配置,默认是 `http://tailchat.internal.com/`
如果不期望修改或者没有域名则可以通过修改`hosts`文件来实现:
```bash
sudo vim /etc/hosts
```
然后增加如下路径:
```
127.0.0.1 tailchat.internal.com
```
现在你可以打开浏览器并打开`http://tailchat.internal.com`来访问部署在k8s中的tailchat服务
当然,你也可以访问如下地址检测服务可用性:
```
http://tailchat.internal.com/health
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Loading…
Cancel
Save