- 2.4.1 基于Kubernetes原生服务发现
- 2.4.1.1 环境要求
- 2.4.1.2 添加Apollo Helm Chart仓库
- 2.4.1.3 部署apollo-configservice和apollo-adminservice
- 2.4.1.3.1 安装apollo-configservice和apollo-adminservice
- 2.4.1.3.2 卸载apollo-configservice和apollo-adminservice
- 2.4.1.3.3 配置项说明
- 2.4.1.3.4 配置样例
- 2.4.1.3.4.1 ConfigDB的host是k8s集群外的IP
- 2.4.1.3.4.2 ConfigDB的host是k8s集群外的域名
- 2.4.1.3.4.3 ConfigDB的host是k8s集群内的一个服务
- 2.4.1.3.4.4 指定Meta Server返回的apollo-configservice地址
- 2.4.1.3.4.5 指定Meta Server返回的apollo-adminservice地址
- 2.4.1.3.4.6 以Ingress配置自定义路径
/config
形式暴露apollo-configservice服务 - 2.4.1.3.4.7 以Ingress配置自定义路径
/admin
形式暴露apollo-adminservice服务
- 2.4.1.4 部署apollo-portal
2.4.1 基于Kubernetes原生服务发现
Apollo 1.7.0版本增加了基于Kubernetes原生服务发现的部署模式,由于不再使用内置的Eureka,所以在整体部署上有很大简化,同时也提供了Helm Charts,便于部署。
更多设计说明可以参考#3054。
2.4.1.1 环境要求
- Kubernetes 1.10+
- Helm 3
2.4.1.2 添加Apollo Helm Chart仓库
$ helm repo add apollo http://ctripcorp.github.io/apollo/charts
$ helm search repo apollo
2.4.1.3 部署apollo-configservice和apollo-adminservice
2.4.1.3.1 安装apollo-configservice和apollo-adminservice
需要在每个环境中安装apollo-configservice和apollo-adminservice,所以建议在release名称中加入环境信息,例如:apollo-service-dev
$ helm install apollo-service-dev \
--set configdb.host=1.2.3.4 \
--set configdb.userName=apollo \
--set configdb.password=apollo \
--set configdb.service.enabled=true \
--set configService.replicaCount=1 \
--set adminService.replicaCount=1 \
-n your-namespace \
apollo/apollo-service
一般部署建议通过 values.yaml 来配置:
$ helm install apollo-service-dev -f values.yaml -n your-namespace apollo/apollo-service
安装完成后会提示对应环境的Meta Server地址,需要记录下来,apollo-portal安装时需要用到:
Get meta service url for current release by running these commands:
echo http://apollo-service-dev-apollo-configservice:8080
更多配置项说明可以参考2.4.1.3.3 配置项说明
2.4.1.3.2 卸载apollo-configservice和apollo-adminservice
例如要卸载apollo-service-dev
的部署:
$ helm uninstall -n your-namespace apollo-service-dev
2.4.1.3.3 配置项说明
下表列出了apollo-service chart的可配置参数及其默认值:
Parameter | Description | Default |
---|---|---|
configdb.host | The host for apollo config db | nil |
configdb.port | The port for apollo config db | 3306 |
configdb.dbName | The database name for apollo config db | ApolloConfigDB |
configdb.userName | The user name for apollo config db | nil |
configdb.password | The password for apollo config db | nil |
configdb.connectionStringProperties | The connection string properties for apollo config db | characterEncoding=utf8 |
configdb.service.enabled | Whether to create a Kubernetes Service for configdb.host or not. Set it to true if configdb.host is an endpoint outside of the kubernetes cluster | false |
configdb.service.fullNameOverride | Override the service name for apollo config db | nil |
configdb.service.port | The port for the service of apollo config db | 3306 |
configdb.service.type | The service type of apollo config db: ClusterIP or ExternalName . If the host is a DNS name, please specify ExternalName as the service type, e.g. xxx.mysql.rds.aliyuncs.com | ClusterIP |
configService.fullNameOverride | Override the deployment name for apollo-configservice | nil |
configService.replicaCount | Replica count of apollo-configservice | 2 |
configService.containerPort | Container port of apollo-configservice | 8080 |
configService.image.repository | Image repository of apollo-configservice | apolloconfig/apollo-configservice |
configService.image.tag | Image tag of apollo-configservice, e.g. 1.8.0 , leave it to nil to use the default version. (chart version >= 0.2.0) | nil |
configService.image.pullPolicy | Image pull policy of apollo-configservice | IfNotPresent |
configService.imagePullSecrets | Image pull secrets of apollo-configservice | [] |
configService.service.fullNameOverride | Override the service name for apollo-configservice | nil |
configService.service.port | The port for the service of apollo-configservice | 8080 |
configService.service.targetPort | The target port for the service of apollo-configservice | 8080 |
configService.service.type | The service type of apollo-configservice | ClusterIP |
configService.ingress.enabled | Whether to enable the ingress for config-service or not. (chart version >= 0.2.0) | false |
configService.ingress.annotations | The annotations of the ingress for config-service. (chart version >= 0.2.0) | {} |
configService.ingress.hosts.host | The host of the ingress for config-service. (chart version >= 0.2.0) | nil |
configService.ingress.hosts.paths | The paths of the ingress for config-service. (chart version >= 0.2.0) | [] |
configService.ingress.tls | The tls definition of the ingress for config-service. (chart version >= 0.2.0) | [] |
configService.liveness.initialDelaySeconds | The initial delay seconds of liveness probe | 100 |
configService.liveness.periodSeconds | The period seconds of liveness probe | 10 |
configService.readiness.initialDelaySeconds | The initial delay seconds of readiness probe | 30 |
configService.readiness.periodSeconds | The period seconds of readiness probe | 5 |
configService.config.profiles | specify the spring profiles to activate | github,kubernetes |
configService.config.configServiceUrlOverride | Override apollo.config-service.url : config service url to be accessed by apollo-client | nil |
configService.config.adminServiceUrlOverride | Override apollo.admin-service.url : admin service url to be accessed by apollo-portal | nil |
configService.config.contextPath | specify the context path, e.g. /apollo , then users could access config service via http://{config_service_address}/apollo . (chart version >= 0.2.0) | nil |
configService.env | Environment variables passed to the container, e.g.JAVA_OPTS: -Xss256k | {} |
configService.strategy | The deployment strategy of apollo-configservice | {} |
configService.resources | The resources definition of apollo-configservice | {} |
configService.nodeSelector | The node selector definition of apollo-configservice | {} |
configService.tolerations | The tolerations definition of apollo-configservice | [] |
configService.affinity | The affinity definition of apollo-configservice | {} |
adminService.fullNameOverride | Override the deployment name for apollo-adminservice | nil |
adminService.replicaCount | Replica count of apollo-adminservice | 2 |
adminService.containerPort | Container port of apollo-adminservice | 8090 |
adminService.image.repository | Image repository of apollo-adminservice | apolloconfig/apollo-adminservice |
adminService.image.tag | Image tag of apollo-adminservice, e.g. 1.8.0 , leave it to nil to use the default version. (chart version >= 0.2.0) | nil |
adminService.image.pullPolicy | Image pull policy of apollo-adminservice | IfNotPresent |
adminService.imagePullSecrets | Image pull secrets of apollo-adminservice | [] |
adminService.service.fullNameOverride | Override the service name for apollo-adminservice | nil |
adminService.service.port | The port for the service of apollo-adminservice | 8090 |
adminService.service.targetPort | The target port for the service of apollo-adminservice | 8090 |
adminService.service.type | The service type of apollo-adminservice | ClusterIP |
adminService.ingress.enabled | Whether to enable the ingress for admin-service or not. (chart version >= 0.2.0) | false |
adminService.ingress.annotations | The annotations of the ingress for admin-service. (chart version >= 0.2.0) | {} |
adminService.ingress.hosts.host | The host of the ingress for admin-service. (chart version >= 0.2.0) | nil |
adminService.ingress.hosts.paths | The paths of the ingress for admin-service. (chart version >= 0.2.0) | [] |
adminService.ingress.tls | The tls definition of the ingress for admin-service. (chart version >= 0.2.0) | [] |
adminService.liveness.initialDelaySeconds | The initial delay seconds of liveness probe | 100 |
adminService.liveness.periodSeconds | The period seconds of liveness probe | 10 |
adminService.readiness.initialDelaySeconds | The initial delay seconds of readiness probe | 30 |
adminService.readiness.periodSeconds | The period seconds of readiness probe | 5 |
adminService.config.profiles | specify the spring profiles to activate | github,kubernetes |
adminService.config.contextPath | specify the context path, e.g. /apollo , then users could access admin service via http://{admin_service_address}/apollo . (chart version >= 0.2.0) | nil |
adminService.env | Environment variables passed to the container, e.g.JAVA_OPTS: -Xss256k | {} |
adminService.strategy | The deployment strategy of apollo-adminservice | {} |
adminService.resources | The resources definition of apollo-adminservice | {} |
adminService.nodeSelector | The node selector definition of apollo-adminservice | {} |
adminService.tolerations | The tolerations definition of apollo-adminservice | [] |
adminService.affinity | The affinity definition of apollo-adminservice | {} |
2.4.1.3.4 配置样例
2.4.1.3.4.1 ConfigDB的host是k8s集群外的IP
configdb:
host: 1.2.3.4
dbName: ApolloConfigDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
service:
enabled: true
2.4.1.3.4.2 ConfigDB的host是k8s集群外的域名
configdb:
host: xxx.mysql.rds.aliyuncs.com
dbName: ApolloConfigDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
service:
enabled: true
type: ExternalName
2.4.1.3.4.3 ConfigDB的host是k8s集群内的一个服务
configdb:
host: apollodb-mysql.mysql
dbName: ApolloConfigDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
2.4.1.3.4.4 指定Meta Server返回的apollo-configservice地址
如果apollo-client无法直接访问apollo-configservice的Service(比如不在同一个k8s集群),那么可以参照下面的示例指定Meta Server返回给apollo-client的地址(比如可以通过nodeport访问)
configService:
config:
configServiceUrlOverride: http://1.2.3.4:12345
2.4.1.3.4.5 指定Meta Server返回的apollo-adminservice地址
如果apollo-portal无法直接访问apollo-adminservice的Service(比如不在同一个k8s集群),那么可以参照下面的示例指定Meta Server返回给apollo-portal的地址(比如可以通过nodeport访问)
configService:
config:
adminServiceUrlOverride: http://1.2.3.4:23456
2.4.1.3.4.6 以Ingress配置自定义路径/config
形式暴露apollo-configservice服务
# use /config as root, should specify configService.config.contextPath as /config
configService:
config:
contextPath: /config
ingress:
enabled: true
hosts:
- paths:
- /config
2.4.1.3.4.7 以Ingress配置自定义路径/admin
形式暴露apollo-adminservice服务
# use /admin as root, should specify adminService.config.contextPath as /admin
adminService:
config:
contextPath: /admin
ingress:
enabled: true
hosts:
- paths:
- /admin
2.4.1.4 部署apollo-portal
2.4.1.4.1 安装apollo-portal
假设有dev, pro两个环境,且meta server地址分别为http://apollo-service-dev-apollo-configservice:8080
和http://apollo-service-pro-apollo-configservice:8080
:
$ helm install apollo-portal \
--set portaldb.host=1.2.3.4 \
--set portaldb.userName=apollo \
--set portaldb.password=apollo \
--set portaldb.service.enabled=true \
--set config.envs="dev\,pro" \
--set config.metaServers.dev=http://apollo-service-dev-apollo-configservice:8080 \
--set config.metaServers.pro=http://apollo-service-pro-apollo-configservice:8080 \
--set replicaCount=1 \
-n your-namespace \
apollo/apollo-portal
一般部署建议通过 values.yaml 来配置:
$ helm install apollo-portal -f values.yaml -n your-namespace apollo/apollo-portal
更多配置项说明可以参考2.4.1.4.3 配置项说明
2.4.1.4.2 卸载apollo-portal
例如要卸载apollo-portal
的部署:
$ helm uninstall -n your-namespace apollo-portal
2.4.1.4.3 配置项说明
下表列出了apollo-portal chart的可配置参数及其默认值:
Parameter | Description | Default |
---|---|---|
fullNameOverride | Override the deployment name for apollo-portal | nil |
replicaCount | Replica count of apollo-portal | 2 |
containerPort | Container port of apollo-portal | 8070 |
image.repository | Image repository of apollo-portal | apolloconfig/apollo-portal |
image.tag | Image tag of apollo-portal, e.g. 1.8.0 , leave it to nil to use the default version. (chart version >= 0.2.0) | nil |
image.pullPolicy | Image pull policy of apollo-portal | IfNotPresent |
imagePullSecrets | Image pull secrets of apollo-portal | [] |
service.fullNameOverride | Override the service name for apollo-portal | nil |
service.port | The port for the service of apollo-portal | 8070 |
service.targetPort | The target port for the service of apollo-portal | 8070 |
service.type | The service type of apollo-portal | ClusterIP |
service.sessionAffinity | The session affinity for the service of apollo-portal | ClientIP |
ingress.enabled | Whether to enable the ingress or not | false |
ingress.annotations | The annotations of the ingress | {} |
ingress.hosts.host | The host of the ingress | nil |
ingress.hosts.paths | The paths of the ingress | [] |
ingress.tls | The tls definition of the ingress | [] |
liveness.initialDelaySeconds | The initial delay seconds of liveness probe | 100 |
liveness.periodSeconds | The period seconds of liveness probe | 10 |
readiness.initialDelaySeconds | The initial delay seconds of readiness probe | 30 |
readiness.periodSeconds | The period seconds of readiness probe | 5 |
env | Environment variables passed to the container, e.g.JAVA_OPTS: -Xss256k | {} |
strategy | The deployment strategy of apollo-portal | {} |
resources | The resources definition of apollo-portal | {} |
nodeSelector | The node selector definition of apollo-portal | {} |
tolerations | The tolerations definition of apollo-portal | [] |
affinity | The affinity definition of apollo-portal | {} |
config.profiles | specify the spring profiles to activate | github,auth |
config.envs | specify the env names, e.g. dev,pro | nil |
config.contextPath | specify the context path, e.g. /apollo , then users could access portal via http://{portal_address}/apollo | nil |
config.metaServers | specify the meta servers, e.g.dev: http://apollo-configservice-dev:8080 pro: http://apollo-configservice-pro:8080 | {} |
config.files | specify the extra config files for apollo-portal, e.g. application-ldap.yml | {} |
portaldb.host | The host for apollo portal db | nil |
portaldb.port | The port for apollo portal db | 3306 |
portaldb.dbName | The database name for apollo portal db | ApolloPortalDB |
portaldb.userName | The user name for apollo portal db | nil |
portaldb.password | The password for apollo portal db | nil |
portaldb.connectionStringProperties | The connection string properties for apollo portal db | characterEncoding=utf8 |
portaldb.service.enabled | Whether to create a Kubernetes Service for portaldb.host or not. Set it to true if portaldb.host is an endpoint outside of the kubernetes cluster | false |
portaldb.service.fullNameOverride | Override the service name for apollo portal db | nil |
portaldb.service.port | The port for the service of apollo portal db | 3306 |
portaldb.service.type | The service type of apollo portal db: ClusterIP or ExternalName . If the host is a DNS name, please specify ExternalName as the service type, e.g. xxx.mysql.rds.aliyuncs.com | ClusterIP |
2.4.1.4.4 配置样例
2.4.1.4.4.1 PortalDB的host是k8s集群外的IP
portaldb:
host: 1.2.3.4
dbName: ApolloPortalDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
service:
enabled: true
2.4.1.4.4.2 PortalDB的host是k8s集群外的域名
portaldb:
host: xxx.mysql.rds.aliyuncs.com
dbName: ApolloPortalDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
service:
enabled: true
type: ExternalName
2.4.1.4.4.3 PortalDB的host是k8s集群内的一个服务
portaldb:
host: apollodb-mysql.mysql
dbName: ApolloPortalDBName
userName: someUserName
password: somePassword
connectionStringProperties: characterEncoding=utf8&useSSL=false
2.4.1.4.4.4 配置环境信息
config:
envs: dev,pro
metaServers:
dev: http://apollo-service-dev-apollo-configservice:8080
pro: http://apollo-service-pro-apollo-configservice:8080
2.4.1.4.4.5 以Load Balancer形式暴露服务
service:
type: LoadBalancer
2.4.1.4.4.6 以Ingress形式暴露服务
ingress:
enabled: true
hosts:
- paths:
- /
2.4.1.4.4.7 以Ingress配置自定义路径/apollo
形式暴露服务
# use /apollo as root, should specify config.contextPath as /apollo
ingress:
enabled: true
hosts:
- paths:
- /apollo
config:
...
contextPath: /apollo
...
2.4.1.4.4.8 以Ingress配置session affinity形式暴露服务
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/affinity-mode: "persistent"
nginx.ingress.kubernetes.io/session-cookie-conditional-samesite-none: "true"
nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
hosts:
- host: xxx.somedomain.com # host is required to make session affinity work
paths:
- /
2.4.1.4.4.9 启用 LDAP 支持
config:
...
profiles: github,ldap
...
files:
application-ldap.yml: |
spring:
ldap:
base: "dc=example,dc=org"
username: "cn=admin,dc=example,dc=org"
password: "password"
searchFilter: "(uid={0})"
urls:
- "ldap://xxx.somedomain.com:389"
ldap:
mapping:
objectClass: "inetOrgPerson"
loginId: "uid"
userDisplayName: "cn"
email: "mail"