helm部署多环境多k8s集群Apollo(阿里云资源)

规划

搭建信息

1.利用官方文档提供的helm方式部署
2.部署三个环境: pro dev test
3.各个环境需准备MySQL、Slb,因网络原因,dev和test环境的Slb需有公网ip,生产的vpc与内网连通故无需公网
4.apollo的组件包括apollo-config-server(其中包括apollo-meta-server)、apollo-admin-server和apollo-portal
4.每个环境(开发/测试/生产)都需要安装apollo-config-server和apollo-admin-server,计划将两者部署在对应环境的k8s集群中的ops命名空间下
5.开发、测试、生产三个环境只需要一个apollo-portal,计划将apollo-portal部署在生产k8s集群的ops命名空间下

环境数据库实例用户密码数据库数据库连接地址SLB ip
生产proddbapollomy_apollo_db_passwdProdApolloConfigDBrm-prod-rds-addresss.mysql.rds.aliyuncs.comprod_slb_address
测试testdbapollomy_apollo_db_passwdTestAlphaApolloConfigDBrm-test-rds-addresss.mysql.rds.aliyuncs.comtest_slb_address
开发devdbapollomy_apollo_db_passwdDevApolloConfigDBrm-dev-rds-addresss.mysql.rds.aliyuncs.comdev_slb_address

在这里插入图片描述

部署大致流程

1.使用helm将apollo的chart拉到本地
2.修改chart包中的values.yaml文件,对配置进行自定义
3.在各自集群上部署apollo-config-server和apollo-admin-server
4.在生产集群上部署apollo-portal

准备工作

按照分布式部署指南
1.创建数据库用户apollo
2.创建数据库并授读写权限给apollo用户
3.每个集群各自需一个数据库,apollo-portal单独需要一个数据库

部署

部署生产环境

$ helm version
version.BuildInfo{Version:"v3.5.1", GitCommit:"32c22239423b3b4ba6706d450bd044baffdcf9e6", GitTreeState:"clean", GoVersion:"go1.15.7"}

$ helm repo add apollo http://ctripcorp.github.io/apollo/charts


"apollo" has been added to your repositories

$ cd /tmp/apollo/

$ helm search repo apollo
NAME                 	CHART VERSION	APP VERSION	DESCRIPTION
apollo/apollo-portal 	0.1.2        	1.7.2      	A Helm chart for Apollo Portal
apollo/apollo-service	0.1.2        	1.7.2      	A Helm chart for Apollo Config Service and Apol...

$ helm pull apollo/apollo-service --untar

$ cd /tmp/apollo/apollo-service

修改values.yaml,以下是修改好的版本
若手动修改,注意修改数据库相关信息

configdb:
  name: apollo-configdb
  # apolloconfigdb host
  host: "rm-prod-rds-addresss.mysql.rds.aliyuncs.com"
  port: 3306
  dbName: ProdApolloConfigDB
  # apolloconfigdb user name
  userName: "apollo"
  # apolloconfigdb password
  password: "my_apollo_db_passwd"
  connectionStringProperties: characterEncoding=utf8
  service:
    # whether to create a Service for this host or not
    enabled: true
    fullNameOverride: ""
    port: 3306
    type: ExternalName

configService:
  name: apollo-configservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8080
  image:
    repository: apolloconfig/apollo-configservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8080
    targetPort: 8080
    type: ClusterIP
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
    # override apollo.config-service.url: config service url to be accessed by apollo-client
    configServiceUrlOverride: ""
    # override apollo.admin-service.url: admin service url to be accessed by apollo-portal
    adminServiceUrlOverride: ""
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

adminService:
  name: apollo-adminservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8090
  image:
    repository: apolloconfig/apollo-adminservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8090
    targetPort: 8090
    type: ClusterIP
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

helm 部署

$ helm install apollo-service -f values.yaml -n ops apollo/apollo-service

$ helm list -n ops
NAME          	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART               APP VERSION
apollo-service	ops      	1       	2021-02-03 14:17:18.883545338 +0800 CST	deployed	apollo-service-0.1.21.7.2

注:部署过程中镜像拉取速度可能较慢

部署apollo-portal

cd /tmp/apollo
helm pull apollo/apollo-portal --untar
cd apollo-portal

修改values.yaml
注意
1.portal的svc需要一个nodeport,主要是方便内网slb暴露服务
2.config.metaServers是各个环境的config-server访问ip:port,这里dev和test的ip和port是slb的
3.配置环境config.envs

name: apollo-portal
fullNameOverride: ""
replicaCount: 1
containerPort: 8070
image:
  repository: apolloconfig/apollo-portal
  pullPolicy: IfNotPresent
imagePullSecrets: []
service:
  fullNameOverride: ""
  port: 8070
  targetPort: 8070
  type: NodePort
  sessionAffinity: ClientIP
ingress:
  enabled: false
  annotations: {}
  hosts:
    - host: ""
      paths: []
  tls: []
liveness:
  initialDelaySeconds: 100
  periodSeconds: 10
readiness:
  initialDelaySeconds: 30
  periodSeconds: 5
# environment variables passed to the container, e.g. JAVA_OPTS
env: {}
strategy: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}

config:
  # spring profiles to activate
  profiles: "github,auth"
  # specify the env names, e.g. dev,pro
  envs: "pro,dev,test"
  # specify the meta servers, e.g.
  # dev: http://apollo-configservice-dev:8080
  # pro: http://apollo-configservice:8080
  # metaServers: {}
  metaServers:
    pro: http://apollo-service-apollo-configservice.ops:8080
    dev: http://dev_slb_address:30002
    test: http://test_slb_address:30004
  # specify the context path, e.g. /apollo
  contextPath: ""
  # extra config files for apollo-portal, e.g. application-ldap.yml
  files: {}

portaldb:
  name: apollo-portaldb
  # apolloportaldb host
  host: rm-prod-rds-addresss.mysql.rds.aliyuncs.com
  port: 3306
  dbName: ApolloPortalDB
  # apolloportaldb user name
  userName: apollo
  # apolloportaldb password
  password: my_apollo_db_passwd
  connectionStringProperties: characterEncoding=utf8
  service:
    # whether to create a Service for this host or not
    enabled: true
    fullNameOverride: ""
    port: 3306
    type: ExternalName

helm部署

$ helm install apollo-portal -f values.yaml -n  ops apollo/apollo-portal

注:values.yaml配置的svc的nodeport为随机端口,用命令获取

kubectl get svc -n ops | grep apollo-portal

获取nodeport后,在slb上配置监听,将slb的8080端口转发到这个nodeport上
这时访问http://prod_slb_address:8080,则可以看到apollo-portal的界面
账号apollo 密码admin 后期使用注意修改

部署开发环境

helm repo add apollo http://ctripcorp.github.io/apollo/charts
cd /tmp/apollo/
helm pull apollo/apollo-service --untar
cd /tmp/apollo/apollo-service

ops@dev-jump:/tmp/apollo/apollo-service$ helm install apollo-service -f values.yaml -n ops apollo/apollo-service

修改values.yaml
注意:
1.修改数据库相关信息
2.config-server和admin-server的svc各自需要一个nodeport,yaml文件中未指定,k8s将随机分配,这里分别是30002和30001
3.dev、test环境和portal所在的生产环境无法通过内网互通,故config-server和admin-server通过node暴露服务在公网,portal才能连通
4.因注意点3,故需修改configService.config.configServiceUrlOverride和configService.config.adminServiceUrlOverride,参数详情见分布式部署指南

configdb:
  name: apollo-configdb
  # apolloconfigdb host
  host: "rm-dev-rds-addresss.mysql.rds.aliyuncs.com"
  port: 3306
  dbName: DevApolloConfigDB
  # apolloconfigdb user name
  userName: "apollo"
  # apolloconfigdb password
  password: "my_apollo_db_passwd"
  connectionStringProperties: characterEncoding=utf8
  service:
    # whether to create a Service for this host or not
    enabled: true
    fullNameOverride: ""
    port: 3306
    type: ExternalName

configService:
  name: apollo-configservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8080
  image:
    repository: apolloconfig/apollo-configservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8080
    targetPort: 8080
    type: NodePort
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
    # override apollo.config-service.url: config service url to be accessed by apollo-client
    configServiceUrlOverride: "http://dev_slb_address:30002"
    # override apollo.admin-service.url: admin service url to be accessed by apollo-portal
    adminServiceUrlOverride: "http://dev_slb_address:30001"
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

adminService:
  name: apollo-adminservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8090
  image:
    repository: apolloconfig/apollo-adminservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8090
    targetPort: 8090
    type: NodePort
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

config-server和admin-server的svc被随机分配nodeport,使用以下命令查看,本例分别是30002和30001

kubectl get svc -n ops | grep apollo

在slb上配置监听,将config-server和admin-server暴露在公网,这里用的slb前端端口与svc的nodeport一致,注意加白名单访问控制

部署测试环境

helm repo add apollo http://ctripcorp.github.io/apollo/charts
cd /tmp/apollo/
helm pull apollo/apollo-service --untar
cd /tmp/apollo/apollo-service

类似开发环境,修改values.yaml,需要注意的点和开发环境一样

configdb:
  name: apollo-configdb
  # apolloconfigdb host
  host: "rm-test-rds-addresss.mysql.rds.aliyuncs.com"
  port: 3306
  dbName: TestBetaApolloConfigDB
  # apolloconfigdb user name
  userName: "apollo"
  # apolloconfigdb password
  password: "my_apollo_db_passwd"
  connectionStringProperties: characterEncoding=utf8
  service:
    # whether to create a Service for this host or not
    enabled: true
    fullNameOverride: ""
    port: 3306
    type: ExternalName

configService:
  name: apollo-configservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8080
  image:
    repository: apolloconfig/apollo-configservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8080
    targetPort: 8080
    type: NodePort
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
    # override apollo.config-service.url: config service url to be accessed by apollo-client
    configServiceUrlOverride: "http://test_slb_address:30004"
    # override apollo.admin-service.url: admin service url to be accessed by apollo-portal
    adminServiceUrlOverride: "http://test_slb_address:30003"
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

adminService:
  name: apollo-adminservice
  fullNameOverride: ""
  replicaCount: 1
  containerPort: 8090
  image:
    repository: apolloconfig/apollo-adminservice
    pullPolicy: IfNotPresent
  imagePullSecrets: []
  service:
    fullNameOverride: ""
    port: 8090
    targetPort: 8090
    type: NodePort
  liveness:
    initialDelaySeconds: 100
    periodSeconds: 10
  readiness:
    initialDelaySeconds: 30
    periodSeconds: 5
  config:
    # spring profiles to activate
    profiles: "github,kubernetes"
  # environment variables passed to the container, e.g. JAVA_OPTS
  env: {}
  strategy: {}
  resources: {}
  nodeSelector: {}
  tolerations: []
  affinity: {}

helm部署之后,也和开发环境一样配置slb监听

helm install apollo-service -f values.yaml -n ops apollo/apollo-service

确认部署

1.访问apollo页面,使用apollo用户登录
2.在界面右上角管理员工具中选择"系统信息"
3.在弹出的系统信息页面中,可以看到在部署portal时定义好的环境
4.分别点击各个环境中的config-server和admin-server的"check"按钮,无报错则部署成功

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值