部署环境
1、mysql 10.10.10.26
账户 root 密码 123
apollo-config内部地址10.43.22.22
一、创建数据
Apollo服务端共需要两个数据库:ApolloPortalDB和ApolloConfigDB,我们把数据库、表的创建和样例数据都分别准备了sql文件,只需要导入数据库即可。
1.创建ApolloPortalDB
通过各种MySQL客户端导入apolloportaldb.sql即可。
2.创建ApolloConfigDB
通过各种MySQL客户端导入apolloconfigdb.sql即可。
二、创建Secrets
apollo-config环境变量(dev)
apiVersion: v1
kind: Secret
metadata:
name: apollo-config-secret
namespace: default
type: Opaque
data:
#SPRING_DATASOURCE_PASSWORD: 123
SPRING_DATASOURCE_PASSWORD: MTIz
#SPRING_DATASOURCE_URL: jdbc:mysql://10.10.10.26:30001/ApolloConfigDB?characterEncoding=utf8
SPRING_DATASOURCE_URL: >-
amRiYzpteXNxbDovLzEwLjEwLjEwLjI2OjMwMDAxL0Fwb2xsb0NvbmZpZ0RCP2NoYXJhY3RlckVuY29kaW5nPXV0Zjg=
#SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_USERNAME: cm9vdA==
apollo-portal环境变量(dev)
apiVersion: v1
kind: Secret
metadata:
name: apollo-portal-secret
namespace: default
type: Opaque
data:
#APOLLO_PORTAL_ENVS = dev
APOLLO_PORTAL_ENVS: ZGV2
#PRO_META = http://localhost:8080
PRO_META: aHR0cDovL2xvY2FsaG9zdDo4MDgw
#SPRING_DATASOURCE_PASSWORD = 123
SPRING_DATASOURCE_PASSWORD: MTIz
#SPRING_DATASOURCE_URL = jdbc:mysql://10.10.10.26:30001/ApolloPortalDB? characterEncoding=utf8
SPRING_DATASOURCE_URL: >-
amRiYzpteXNxbDovLzEwLjEwLjEwLjI2OjMwMDAxL0Fwb2xsb1BvcnRhbERCPyBjaGFyYWN0ZXJFbmNvZGluZz11dGY4
#SPRING_DATASOURCE_USERNAME = root
SPRING_DATASOURCE_USERNAME: cm9vdA==
三、创建配置文件ConfigMap
1.创建密文用于环境变量
apiVersion: v1
kind: ConfigMap
metadata:
labels:
name: apollo-portal-cfg-dev
name: apollo-portal-cfg
namespace: default
data:
key-apollo-env.properties: |-
local.meta=http://localhost:8080
dev.meta=http://10.43.22.22:8080
fat.meta=http://fill-in-fat-meta-server:8080
uat.meta=http://fill-in-uat-meta-server:8080
lpt.meta=${lpt_meta}
pro.meta=http://fill-in-pro-meta-server:8080
key-app.properties: |-
appId=100003173
jdkVersion=1.8
key-application-github.properties: |-
local.meta=http://localhost:8080
dev.meta=http://fill-in-dev-meta-server:8080
fat.meta=http://fill-in-fat-meta-server:8080
uat.meta=http://fill-in-uat-meta-server:8080
lpt.meta=${lpt_meta}
pro.meta=http://fill-in-pro-meta-server:8080
四、部署ApolloConfig
1、创建内部访问service
apiVersion: v1
kind: Service
metadata:
name: apollo-config-service-inner
namespace: default
spec:
selector:
name: apollo-config-dev
type: ClusterIP
clusterIP: 10.43.22.22 #将该值写入ApolloConfigDB数据库eureka.service.url
ports:
- name:
port: 8080
protocol: TCP
targetPort: 8080
sessionAffinity: None
2、部署服务
apiVersion: apps/v1
kind: Deployment
metadata:
name: apollo-config
namespace: default
spec:
selector:
matchLabels:
name: apollo-config-dev
template:
metadata:
labels:
name: apollo-config-dev
spec:
containers:
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-configservice:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-config-secret
ports:
- name: 8080tcp
expose: true
protocol: TCP
containerPort: 8080
name: apollo-config
五、部署ApolloAdmin
1、配置数据库
更改配置ApolloConfigDB>ServerConfig>eureka.service.url = http://10.43.22.22:8080/eureka/
2、部署服务
apiVersion: apps/v1
kind: Deployment
metadata:
name: apollo-admin
namespace: default
spec:
selector:
matchLabels:
name: apollo-admin-dev
template:
metadata:
labels:
name: apollo-admin-dev
spec:
containers:
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-adminservice:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-config-secret
ports:
- name: 8090tcp
expose: true
protocol: TCP
containerPort: 8090
name: apollo-admin
restartPolicy: Always
replicas: 1
六、部署ApolloPortal
1、部署服务
apiVersion: apps/v1
kind: Deployment
metadata:
name: apollo-portal
namespace: default
spec:
selector:
matchLabels:
name: apollo-portal-dev
template:
metadata:
labels:
name: apollo-portal-dev
spec:
containers:
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-portal:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-portal-secret
ports:
- name: 8070tcp
expose: true
protocol: TCP
containerPort: 8070
name: apollo-portal
volumeMounts:
- name: apollo-portal-cfg-volume
mountPath: /apollo-portal/config/
restartPolicy: Always
volumes:
- name: apollo-portal-cfg-volume
configMap:
name: apollo-portal-cfg
items:
- key: key-application-github.properties
path: application-github.properties
- key: key-apollo-env.properties
path: apollo-env.properties
- key: key-app.properties
path: app.properties
replicas: 1
2、暴露服务
apiVersion: v1
kind: Service
metadata:
name: apollo-portal-front
namespace: default
spec:
selector:
name: apollo-portal-dev
type: NodePort
ports:
- name: ''
port: 8070
protocol: TCP
targetPort: 8070
nodePort: 30004
sessionAffinity: None
apiVersion: apps/v1
kind: Deployment
metadata:
name: apollo-dev
namespace: default
spec:
selector:
matchLabels:
app: apollo-dev
template:
metadata:
labels:
app: apollo-dev
spec:
containers:
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-configservice:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-config-dev
ports:
- name: 8080tcp
expose: true
protocol: TCP
containerPort: 8080
name: apollo-config
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-adminservice:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-config-dev
ports:
- name: 8090tcp
expose: true
protocol: TCP
containerPort: 8090
name: apollo-admin
- imagePullPolicy: IfNotPresent
image: 'apolloconfig/apollo-portal:latest'
envFrom:
- prefix: ''
secretRef:
name: apollo-portal-dev
ports:
- name: 8070tcp
expose: true
protocol: TCP
containerPort: 8070
name: apollo-portal
volumeMounts:
- name: apollo-portal-cfg-volume
mountPath: /apollo-portal/config/
restartPolicy: Always
volumes:
- name: apollo-portal-cfg-volume
configMap:
name: apollo-cfg
items:
- key: key-application-github.properties
path: application-github.properties
- key: key-apollo-env.properties
path: apollo-env.properties
- key: key-app.properties
path: app.properties
replicas: 1
查看容器内状态:kubectl exec -it apollo-portal-dev-6779cb4fcf-g7r7r --container apollo-portal -- sh