forked from easzlab/kubeasz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
411 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# 3.3 K8S 应用部署模板 app.yaml | ||
|
||
以下示例配置仅做参考,描述一个简单 java spring boot项目的 k8s 部署文件模板;在实际部署前,CI/CD流程中会对变量做替换。详见 [gitlab-ci.yml文件](gitlab-ci.yml.md)。 | ||
|
||
``` bash | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: PROJECT_NS | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: harborkey1 | ||
namespace: PROJECT_NS | ||
data: | ||
#待替换的变量DOCKER_KEY,参考 docs/guide/harbor.md#k8s%E4%B8%AD%E4%BD%BF%E7%94%A8harbor | ||
.dockerconfigjson: DOCKER_KEY | ||
type: kubernetes.io/dockerconfigjson | ||
|
||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: APP_NAME | ||
namespace: PROJECT_NS | ||
spec: | ||
replicas: APP_REP | ||
template: | ||
metadata: | ||
labels: | ||
run: APP_NAME | ||
spec: | ||
containers: | ||
- name: APP_NAME | ||
image: ProjectImage | ||
imagePullPolicy: Always | ||
env: | ||
# 设置java的时区 | ||
- name: TZ | ||
value: "Asia/Shanghai" | ||
resources: | ||
limits: | ||
cpu: 500m | ||
memory: 1600Mi | ||
requests: | ||
cpu: 200m | ||
memory: 800Mi | ||
ports: | ||
- containerPort: 8080 | ||
imagePullSecrets: | ||
- name: harborkey1 | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
run: APP_NAME | ||
name: APP_NAME | ||
namespace: PROJECT_NS | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 8080 | ||
selector: | ||
run: APP_NAME | ||
sessionAffinity: None | ||
|
||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: APP_NAME-ingress | ||
namespace: PROJECT_NS | ||
spec: | ||
rules: | ||
- host: AppDomain | ||
http: | ||
paths: | ||
- path: /AppPath | ||
backend: | ||
serviceName: APP_NAME | ||
servicePort: 80 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 3.2环境配置替换 config.sh | ||
|
||
首先应用开发人员需要整理在不同环境(测试环境/生产环境)的配置参数,并在源代码中约定好替换的名称(如db_host, db_usr);然后用户必须在项目gitlab web界面(“Settings”>"CI/CD">"Variables")配置变量;最后根据gitlab-ci.yml文件定义CI/CD执行的需要,编写如下简单变量替换shell脚本;该shell脚本分别在测试环境打包阶段(beta-build)和生产环境打包阶段(prod-build)阶段运行。 | ||
|
||
以下脚本仅作示例,实际应根据项目需要增加/修改需替换变量名称与对应源代码中的配置文件 | ||
|
||
``` bash | ||
#!/bin/bash | ||
|
||
#set -o verbose | ||
#set -o xtrace | ||
|
||
beta_config() { | ||
sed -i \ | ||
-e "s/db_host/$BETA_DB_HOST/g" \ | ||
-e "s/db_usr/$BETA_DB_USR/g" \ | ||
-e "s/db_pwd/$BETA_DB_PWD/g" \ | ||
example-web/src/main/resources/config/datasource.properties # 项目源码的配置文件 | ||
sed -i \ | ||
-e "s/redis_host/$BETA_REDIS_HOST/g" \ | ||
-e "s/redis_port/$BETA_REDIS_PORT/g" \ | ||
-e "s/redis_pwd/$BETA_REDIS_PWD/g" \ | ||
example-web/src/main/resources/config/redis.properties # 项目源码的配置文件 | ||
} | ||
|
||
prod_config() { | ||
sed -i \ | ||
-e "s/db_host/$PROD_DB_HOST/g" \ | ||
-e "s/db_usr/$PROD_DB_USR/g" \ | ||
-e "s/db_pwd/$PROD_DB_PWD/g" \ | ||
example-web/src/main/resources/config/datasource.properties | ||
sed -i \ | ||
-e "s/redis_host/$PROD_REDIS_HOST/g" \ | ||
-e "s/redis_port/$PROD_REDIS_PORT/g" \ | ||
-e "s/redis_pwd/$PROD_REDIS_PWD/g" \ | ||
example-web/src/main/resources/config/redis.properties | ||
} | ||
|
||
if [[ "$CI_JOB_STAGE" == "beta-build" ]];then | ||
beta_config | ||
elif [[ "$CI_JOB_STAGE" == "prod-build" ]];then | ||
prod_config | ||
else | ||
echo "error: undefined CI_JOB_STAGE!" | ||
fi | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.