-
Notifications
You must be signed in to change notification settings - Fork 82
Kubernetes部署方式
idoop edited this page Oct 19, 2018
·
1 revision
yaml配置:
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: apollo-dev
name: apollo-dev
namespace: default
spec:
# 根据client数量配置实例数
replicas: 5
revisionHistoryLimit: 3
selector:
matchLabels:
app: apollo-dev
template:
metadata:
labels:
app: apollo-dev
spec:
containers:
- name: apollo-dev
image: idoop/docker-apollo:latest
imagePullPolicy: IfNotPresent
ports:
- name: config-port
containerPort: 8080
readinessProbe:
httpGet:
path: /
port: config-port
# 启动较慢,可以适量改大,如果同时要开启admin,或者同时开启其他环境服务,比如uat或pro,则设置的预备时间值翻倍
initialDelaySeconds: 40
periodSeconds: 20
timeoutSeconds: 3
livenessProbe:
# 同预备时间相似,但如果要同时启动admin或启动多个环境的服务,则等待时长必须要大于全部服务启动完的时长
# 因为一旦没能启动完成,则健康检查失败将会陷入无限重启的状态
# 如果只有一个环境并设置了ONLY_CONFIG,则健康检查可以替换为httpGet方式.
initialDelaySeconds: 50
periodSeconds: 10
exec:
command:
- healthcheck
env:
# 如果想在容器中同时运行admin,则不要配置ONLY_CONFIG
- name: ONLY_CONFIG
value: "TRUE"
# 如果mysql也在k8s集群中,则地址可以直接配置MySQL服务名.
- name: DEV_DB
value: jdbc:mysql://mysql-in-k8s-svc:3306/ApolloConfigDBDev?characterEncoding=utf8
- name: DEV_DB_USER
value: root
- name: DEV_DB_PWD
value: Admin123
# 如果设置了ONLY_CONFIG,则可以不配置LB
# - name: DEV_LB
# value: apollo-dev
terminationGracePeriodSeconds: 5
---
kind: Service
apiVersion: v1
metadata:
labels:
app: apollo-dev
name: apollo-dev
namespace: default
spec:
ports:
- name: config-port
port: 8080
targetPort: 8080
selector:
app: apollo-dev
假设portal也部署在kubernetes中,则类似如下配置:
kind: Pod
apiVersion: v1
metadata:
labels:
app: apollo-portal
name: apollo-portal
namespace: default
spec:
containers:
- name: apollo-portal
image: idoop/docker-apollo:latest
imagePullPolicy: IfNotPresent
ports:
- name: portal-port
containerPort: 8070
# 如无必要,可以不暴露portal中的admin和config
#- name: config-port
# containerPort: 8080
#- name: admin-port
# containerPort: 8090
readinessProbe:
initialDelaySeconds: 200
periodSeconds: 20
exec:
command:
- healthcheck
livenessProbe:
initialDelaySeconds: 300
periodSeconds: 10
exec:
command:
- healthcheck
env:
- name: PORTAL_DB
value: jdbc:mysql://mysql-in-k8s-svc:3306/ApolloPortalDB?characterEncoding=utf8
- name: PORTAL_DB_USER
value: root
- name: PORTAL_DB_PWD
value: password
# 如果config服务部署中没配置启动admin,则config的数据库的ServerConfig表中eureka.service.url的地址建议配置为localhost
- name: DEV_DB
value: jdbc:mysql://mysql-in-k8s-svc:3306/ApolloConfigDBDev?characterEncoding=utf8
- name: DEV_DB_USER
value: root
- name: DEV_DB_PWD
value: Admin123
# 但如果config服务中启动了admin,则config数据库的ServerConfig表中eureka.service.url的地址应该是config的svc名称与对外的端口
# 以本次为例,svc为apollo-dev,端口为8080,portal则只需指定DEV_URL,类似下方.
#- name: DEV_URL
# value: http://apollo-dev:8080
---
kind: Service
apiVersion: v1
metadata:
labels:
app: apollo-portal
name: apollo-portal
namespace: default
spec:
ports:
- name: portal-port
port: 8070
targetPort: 8070
# 如无必要,可以不暴露portal中的admin和config
#- name: admin-port
#- name: config-port
selector:
app: apollo-portal