Skip to content

Commit

Permalink
use official docker images and use built-in default environment names (
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam authored Jul 25, 2021
1 parent b2d666f commit fa4386f
Show file tree
Hide file tree
Showing 35 changed files with 171 additions and 2,724 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Apollo 1.9.0
* [Reduce bootstrap time in the situation with large properties](https://github.com/ctripcorp/apollo/pull/3816)
* [docs: English catalog in sidebar](https://github.com/ctripcorp/apollo/pull/3831)
* [fix the issue that release messages might be missed in certain scenarios](https://github.com/ctripcorp/apollo/pull/3819)
* [use official docker images for manual kubernetes deployment](https://github.com/ctripcorp/apollo/pull/3840)
------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/6?closed=1)

111 changes: 38 additions & 73 deletions scripts/apollo-on-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,41 @@
# 使用方法

## 一、构建镜像
> Apollo 1.7.0版本增加了基于Kubernetes原生服务发现的[Helm Chart部署模式](https://www.apolloconfig.com/#/zh/deployment/distributed-deployment-guide?id=_241-%e5%9f%ba%e4%ba%8ekubernetes%e5%8e%9f%e7%94%9f%e6%9c%8d%e5%8a%a1%e5%8f%91%e7%8e%b0),由于不再使用内置的Eureka,所以在整体部署上有很大简化,如无特殊需求,建议使用该模式部署。
### 1.1 获取 apollo 压缩包
https://github.com/ctripcorp/apollo/releases 下载预先打好的 java 包 <br/>
例如你下载的是: <br/>
apollo-portal-1.0.0-github.zip <br/>
apollo-adminservice-1.0.0-github.zip <br/>
apollo-configservice-1.0.0-github.zip <br/>
## 1. 创建数据库
具体步骤请参考 [2.1 创建数据库](https://www.apolloconfig.com/#/zh/deployment/distributed-deployment-guide?id=_21-%e5%88%9b%e5%bb%ba%e6%95%b0%e6%8d%ae%e5%ba%93),需要注意的是 ApolloPortalDB 只需要在生产环境部署一个即可,而 ApolloConfigDB 需要在每个环境部署一套,示例假设你的 apollo 开启了 4 个环境, 即 dev、fat、uat、prod,那么就需要创建 4 个 ApolloConfigDB。

### 1.2 解压压缩包, 获取程序 jar 包
- 解压 apollo-portal-1.0.0-github.zip <br/>
获取 apollo-portal-1.0.0.jar, 重命名为 apollo-portal.jar, 放到 scripts/apollo-on-kubernetes/apollo-portal-server
- 解压 apollo-adminservice-1.0.0-github.zip <br/>
获取 apollo-adminservice-1.0.0.jar, 重命名为 apollo-adminservice.jar, 放到 scripts/apollo-on-kubernetes/apollo-admin-server
- 解压 apollo-configservice-1.0.0-github.zip <br/>
获取 apollo-configservice-1.0.0.jar, 重命名为 apollo-configservice.jar, 放到 scripts/apollo-on-kubernetes/apollo-config-server
## 2. 调整部署配置

### 1.3 build image
需要分别为alpine-bash-3.8-image,apollo-config-server,apollo-admin-server和apollo-portal-server构建镜像。
### 2.1 ApolloConfigDB 数据库连接信息

build apollo-config-server image 为例, 其他类似
dev 环境为例,需要修改:

```bash
scripts/apollo-on-kubernetes/apollo-config-server$ tree -L 2
.
├── apollo-configservice.conf
├── apollo-configservice.jar
├── config
│   ├── application-github.properties
│   └── app.properties
├── Dockerfile
├── entrypoint.sh
└── scripts
└── startup-kubernetes.sh
```
1. `apollo-env-dev/service-apollo-config-server-dev.yaml``apollo-env-dev/service-apollo-admin-server-dev.yaml``application-github.properties``spring.datasource.url``spring.datasource.username``spring.datasource.password`配置
2. `apollo-env-dev/service-mysql-for-apollo-dev-env.yaml`中 mysql endpoint 地址信息

build image
### 2.2 eureka.service.url

```bash
# 在 scripts/apollo-on-kubernetes/apollo-config-server 路径下
docker build -t apollo-config-server:v1.0.0 .
```
以 dev 环境为例,默认是以 replica 为 3 做的样例配置,如果 replica 数量改变了,那么也要对应修改`apollo-env-dev/service-apollo-config-server-dev.yaml``apollo-env-dev/service-apollo-admin-server-dev.yaml``application-github.properties``eureka.service.url`配置。

push image <br/>
将 image push 到你的 docker registry, 例如 vmware harbor
如果该配置希望以数据库中为准,那么在 yaml 中直接删除该配置项即可。

## 二、Deploy apollo on kubernetes
### 2.3 ApolloPortalDB 数据库连接信息

### 2.1 部署 MySQL 服务
你可以选用 MySQL-Galera-WSrep 来提高你的 MySQL 服务的可用性 <br/>
MySQL 部署步骤略
1. 修改`service-apollo-portal-server.yaml``application-github.properties``spring.datasource.url``spring.datasource.username``spring.datasource.password`配置
2. 修改`service-apollo-portal-server.yaml`中 mysql endpoint 地址信息

### 2.1 导入 MySQL DB 文件
由于上面部署了分布式的 MySQL, 所有 config-server、admin-server、portal-server 使用同一个 MySQL 服务的不同数据库
### 2.4 ApolloPortal 的环境信息

示例假设你的 apollo 开启了 4 个环境, 即 dev、test-alpha、test-beta、prod, 在你的 MySQL 中导入 scripts/apollo-on-kubernetes/db 下的文件即可
1. 修改`service-apollo-portal-server.yaml``application-github.properties``apollo.portal.envs`配置
* 如果该配置希望以数据库中为准,那么在 yaml 中直接删除该配置项即可。
2. 修改`service-apollo-portal-server.yaml``apollo-env.properties`的各环境 meta server 地址信息

如果有需要, 你可以更改 eureka.service.url 的地址, 格式为 http://config-server-pod-name-index.meta-server-service-name:8080/eureka/ , 例如 http://statefulset-apollo-config-server-dev-0.service-apollo-meta-server-dev:8080/eureka/
## 3. Deploy apollo on kubernetes

### 2.2 Deploy apollo on kubernetes
示例假设 apollo 开启了 4 个环境, 即 dev、fat、uat、pro

示例假设你有 4 台 kubernetes node 来部署 apollo, apollo 开启了 4 个环境, 即 dev、test-alpha、test-beta、prod

按照 scripts/apollo-on-kubernetes/kubernetes/kubectl-apply.sh 文件的内容部署 apollo 即可,注意需要按照实际情况修改对应配置文件中的数据库连接信息、eureka.service.url、replicas、nodeSelector、镜像信息等。
按照 scripts/apollo-on-kubernetes/kubernetes/kubectl-apply.sh 文件的内容部署 apollo 即可。

```bash
scripts/apollo-on-kubernetes/kubernetes$ cat kubectl-apply.sh
Expand All @@ -75,15 +47,15 @@ kubectl apply -f apollo-env-dev/service-mysql-for-apollo-dev-env.yaml --record &
kubectl apply -f apollo-env-dev/service-apollo-config-server-dev.yaml --record && \
kubectl apply -f apollo-env-dev/service-apollo-admin-server-dev.yaml --record

# fat-env(test-alpha-env)
kubectl apply -f apollo-env-test-alpha/service-mysql-for-apollo-test-alpha-env.yaml --record && \
kubectl apply -f apollo-env-test-alpha/service-apollo-config-server-test-alpha.yaml --record && \
kubectl apply -f apollo-env-test-alpha/service-apollo-admin-server-test-alpha.yaml --record
# fat-env
kubectl apply -f apollo-env-fat/service-mysql-for-apollo-fat-env.yaml --record && \
kubectl apply -f apollo-env-fat/service-apollo-config-server-fat.yaml --record && \
kubectl apply -f apollo-env-fat/service-apollo-admin-server-fat.yaml --record

# uat-env(test-beta-env)
kubectl apply -f apollo-env-test-beta/service-mysql-for-apollo-test-beta-env.yaml --record && \
kubectl apply -f apollo-env-test-beta/service-apollo-config-server-test-beta.yaml --record && \
kubectl apply -f apollo-env-test-beta/service-apollo-admin-server-test-beta.yaml --record
# uat-env
kubectl apply -f apollo-env-uat/service-mysql-for-apollo-uat-env.yaml --record && \
kubectl apply -f apollo-env-uat/service-apollo-config-server-uat.yaml --record && \
kubectl apply -f apollo-env-uat/service-apollo-admin-server-uat.yaml --record

# prod-env
kubectl apply -f apollo-env-prod/service-mysql-for-apollo-prod-env.yaml --record && \
Expand All @@ -94,10 +66,7 @@ kubectl apply -f apollo-env-prod/service-apollo-admin-server-prod.yaml --record
kubectl apply -f service-apollo-portal-server.yaml --record
```

~~你需要注意的是, 应当尽量让同一个 server 的不同 pod 在不同 node 上, 这个通过 kubernetes nodeSelector 实现~~
去掉nodeSelector 改为POD反亲和性[podAntiAffinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/)

### 2.3 验证所有 pod 处于 Running 并且 READY 状态
## 4. 验证所有 pod 处于 Running 并且 READY 状态

```bash
kubectl get pod -n sre -o wide
Expand All @@ -110,9 +79,9 @@ deployment-apollo-admin-server-dev-b7bbd657-xs4wt 1/1 Running
deployment-apollo-admin-server-prod-699bbd894f-j977p 1/1 Running 0 2d 10.247.4.83 k8s-apollo-node-2
deployment-apollo-admin-server-prod-699bbd894f-n9m54 1/1 Running 0 2d 10.247.8.11 k8s-apollo-node-3
deployment-apollo-admin-server-prod-699bbd894f-vs56w 1/1 Running 0 2d 10.247.1.27 k8s-apollo-node-1
deployment-apollo-admin-server-test-beta-7c855cd4f5-9br65 1/1 Running 0 2d 10.247.1.25 k8s-apollo-node-1
deployment-apollo-admin-server-test-beta-7c855cd4f5-cck5g 1/1 Running 0 2d 10.247.8.9 k8s-apollo-node-3
deployment-apollo-admin-server-test-beta-7c855cd4f5-x6gt4 1/1 Running 0 2d 10.247.4.81 k8s-apollo-node-2
deployment-apollo-admin-server-uat-7c855cd4f5-9br65 1/1 Running 0 2d 10.247.1.25 k8s-apollo-node-1
deployment-apollo-admin-server-uat-7c855cd4f5-cck5g 1/1 Running 0 2d 10.247.8.9 k8s-apollo-node-3
deployment-apollo-admin-server-uat-7c855cd4f5-x6gt4 1/1 Running 0 2d 10.247.4.81 k8s-apollo-node-2
deployment-apollo-portal-server-6d4bbc879c-bv7cn 1/1 Running 0 2d 10.247.8.12 k8s-apollo-node-3
deployment-apollo-portal-server-6d4bbc879c-c4zrb 1/1 Running 0 2d 10.247.1.28 k8s-apollo-node-1
deployment-apollo-portal-server-6d4bbc879c-qm4mn 1/1 Running 0 2d 10.247.4.84 k8s-apollo-node-2
Expand All @@ -122,9 +91,9 @@ statefulset-apollo-config-server-dev-2 1/1 Running
statefulset-apollo-config-server-prod-0 1/1 Running 0 2d 10.247.8.10 k8s-apollo-node-3
statefulset-apollo-config-server-prod-1 1/1 Running 0 2d 10.247.4.82 k8s-apollo-node-2
statefulset-apollo-config-server-prod-2 1/1 Running 0 2d 10.247.1.26 k8s-apollo-node-1
statefulset-apollo-config-server-test-beta-0 1/1 Running 0 2d 10.247.8.8 k8s-apollo-node-3
statefulset-apollo-config-server-test-beta-1 1/1 Running 0 2d 10.247.4.80 k8s-apollo-node-2
statefulset-apollo-config-server-test-beta-2 1/1 Running 0 2d 10.247.1.24 k8s-apollo-node-1
statefulset-apollo-config-server-uat-0 1/1 Running 0 2d 10.247.8.8 k8s-apollo-node-3
statefulset-apollo-config-server-uat-1 1/1 Running 0 2d 10.247.4.80 k8s-apollo-node-2
statefulset-apollo-config-server-uat-2 1/1 Running 0 2d 10.247.1.24 k8s-apollo-node-1
```

### 2.4 访问 apollo service
Expand All @@ -135,19 +104,15 @@ statefulset-apollo-config-server-test-beta-2 1/1 Running
- client 端, 在 client 端无需再实现负载均衡 <br/>
Dev<br/>
&nbsp;&nbsp;&nbsp;&nbsp;kubernetes-master-ip:30002 <br/>
Test-Alpha <br/>
Fat <br/>
&nbsp;&nbsp;&nbsp;&nbsp;kubernetes-master-ip:30003 <br/>
Test-Beta <br/>
Uat <br/>
&nbsp;&nbsp;&nbsp;&nbsp;kubernetes-master-ip:30004 <br/>
Prod <br/>
&nbsp;&nbsp;&nbsp;&nbsp;kubernetes-master-ip:30005 <br/>

# FAQ

## 关于修改的 Dockerfile
添加 ENV 和 entrypoint.sh, 启动 server 需要的配置, 在 kubernetes yaml 文件中可以通过 configmap 传入、也可以通过 ENV 传入
关于 Dockerfile、entrypoint.sh 具体内容, 你可以查看文件里的内容

## 关于 kubernetes yaml 文件
具体内容请查看 `scripts/apollo-on-kubernetes/kubernetes/service-apollo-portal-server.yaml` 注释 <br/>
其他类似。
Expand Down
29 changes: 0 additions & 29 deletions scripts/apollo-on-kubernetes/alpine-bash-3.8-image/Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/apollo-on-kubernetes/apollo-admin-server/.dockerignore

This file was deleted.

38 changes: 0 additions & 38 deletions scripts/apollo-on-kubernetes/apollo-admin-server/Dockerfile

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/apollo-on-kubernetes/apollo-config-server/.dockerignore

This file was deleted.

Loading

0 comments on commit fa4386f

Please sign in to comment.